Thread: Works only part of the time?

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    1

    Question Works only part of the time?

    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

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078

    Re: Works only part of the time?

    Originally posted by scr0llwheel

    Code:
    strGamesnet = strUsername.substr(strUsername.find_first_of('.') + 6);
    There probably can be periods prior to the ".user." Check for the LAST period and just add 1 instead of finding the first period and adding 6.

    strGamesnet = strUsername.substr(strUsername.find_last_of('.') + 1);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with time
    By Gong in forum C++ Programming
    Replies: 7
    Last Post: 01-11-2007, 02:43 PM
  2. need help in time zone
    By Gong in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2007, 04:44 AM
  3. Help with assignment!
    By RVDFan85 in forum C++ Programming
    Replies: 12
    Last Post: 12-03-2006, 12:46 AM
  4. Sending an email in C program
    By Moony in forum C Programming
    Replies: 28
    Last Post: 10-19-2006, 10:42 AM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM