I am trying to code an IRC bot and am having a few problems. The bot will record chatter in a channel and log it along with the user's nickname and handle. A user's "handle" is how they are recognized on GamesNET with SrvX (completely unrelated to my bot). I want to try to capture their handle and record it every time a user joins a channel. There are two ways of doing this:
a) the user has set mode +x on themselves. This means their hostmask is something like [email protected]. I can then, obviously, pull their handle from that.
b) another way which isn't important to this post.
Anyway, the necessary information is that when a user joins a channel, the bot gets their whole hostmask. The hostmask is displayed in the form of (for example):
[email protected]
I want to get the 2nd "scr0llwheel" from that string (scr0llwheel!scr0ll@scr0llwheel.user.gamesnet)
Right now, I have...
Code:
void CBot::OnJoin(string strUsername, string strChannel)
{
string strHandle, strHandle2, strGamesnet;
strGamesnet = strUsername.substr(strUsername.find_first_of('.') + 6);
if (strGamesnet == "gamesnet ") {
strHandle = strUsername.substr(strUsername.find_first_of('@') + 1);
strHandle2 = strHandle.substr(0,strHandle.find_first_of('.'));
PrivMsg(strChannel, "handle: " + strHandle2);
}
}
The problem is: it works, but only some of the time?! I *think* it might have something to do with IRC, not my code but I wanted to post the code here in hopes of someone pointing out a problem, how to improve it, etc.
As you can probably tell, I'm new to programming C/C++ so any help would be greatly appreciated.
Thanks,
scr0llwheel