defience 0 Newbie Poster

When my bot joins a room it will respond to certain words that are typed. An example would be that if someone typed "hello" the bot would reply "Hello <user>! How are you doing?" My problem is that I can't seem to get the bot to reply to NOTICE or PRIVMSG from a user. I'm not sure what I'm overlooking. I can get the bot to reply with a NOTICE or PRIVMSG to a user but only if the received message is from the channel and NOT a NOTICE or PRIVMSG from a user.
User types "hello"
(I get "Received message from <userinfo> NOTICE #bottest:hello
bot replies NOTICE user "Hello <user>! How are you doing?"
How can I get the bot to respond to a NOTICE from a user instead of a NOTICE from the channel?

I've tried changing the def main() portion to def messageFromUser but that didn't do it. Now before,
I had self.sendmessageToChannel(channel, "blah blah") but had to change 'channel' to 'user' because it would send the reply by NOTICE or PRIVMSG to everyone in the channel instead of to just the user.
I hope I'm making sense.... http://python-forum.org/py/images/smiles/icon_confused.gif

I've included the portions of code that I think the problem is in, it's not the complete code:


[/B]
 
[B]#debug set to 'True' so I can read the output
#starts with the usual of host, port, nick, etc.....
#then the ping & pong........[/B]
[B]               
# Callbacks you may implement instead of delving into the raw data passed to  IRCBot.act
    def messageFromChannel(self, channel, user, message):
        """ Callback called when a message is received from a channel the bot is residing [/B]
[B]in."""
        dbg("Received message from '" + str(user) + "' in channel '" + "':\n" + message)
        
    def sendMessageToChannel(self, channel, message):
        """ Sends a message to a channel. """
        self.send("NOTICE " + channel + " :" + message)
        
    def messageFromUser(self, user, message, msgtype=None):
        """ Callback called when a message is received from a user."""
        dbg("Received message from '" + user + "':\n" + message)
    
    def sendMessageToUser(self, user, message):
        """ Sends a message to a user. """
        self.send("NOTICE " + user + " :" + message)
      
    
    def userEntered(self, user, channel):
        #""" Callback called when a new user enters a channel you are in. """
        dbg(user + " entered channel " + channel)
    def act(self, data):
        """ Callback which is passed raw data from the IRC server received from the [/B]
[B]socket."""
        pass
    
    def reply(self, data, message):
        """ Sends a message to either a channel or an individual, based on the text [/B]
[B]passed."""
        # call getChannel passing True as the username param.
        self.sendMessageToChannel(self.getChannel(data), message, True)    
        
    def getSenderName(self, data):
        """ Get the name of the person who sent a message, given the raw IRC message."""
        try:
            regSenderName = re.compile(":[\w\s]*")
            return re.sub("^:", "", regSenderName.findall(data)[0])
        except IndexError:
            return None
    
    def getChannel(self, data, username=True):
        """ Gets the channel a message was sent from."""
        # make self.reply handle the checking of user/channel.
        if not data.count("#") and username:
            return self.getSenderName(data)
        else:
            try:
                channel = data[data.index("#"):]
                return channel[:channel.index(" ")]
            except ValueError:
                return None
    
    def recv(self, amount):
        """ Receives text from the IRC server."""
        return self.sock.recv(amount)
    
    def send(self, text):
        """ Send a raw IRC command to the server."""
        self.sock.send(text + "\n\r")
        dbg("bot -> " + text)
        
    # <code removed for sake of space......connection code
       
def baseAct(self, data):
        """ Parses the received data and responds accordingly. It parses the data and calls
            the necessary callbacks."""
        # Call the callbacks.
        channel = self.getChannel(data, False)
        sender = self.getSenderName(data)
        # messageFromChannel
        if channel:
            # Get senders name when message received from channel
            if not sender:
                sender = None
            self.messageFromChannel(channel, sender, data[data.find(" :") + 2:])
        # userEntered
        elif sender and data[data.find(" ") + 1:].startswith("JOIN :"):
            self.userEntered(sender, data[data.find("JOIN :") + 6:])
        elif sender:
            # Make sure this is a message (NOTICE or PRIVMSG).
            ok = False
            if data[data.find(" ") + 1:].startswith("NOTICE %s :" % self.nick):
                ok = True
            elif data[data.find(" ") + 1:].startswith("PRIVMSG %s :" % self.nick):
                ok = True
            # messageFromUser
            if ok:
                self.messageFromUser(sender, data[data.find(":") + 2:])
            # Pass the data to self.act
        self.act(data)
        
def main():
    """ Called when this module is ran directly. """
    class MrXbot(IRCBot):
        def messageFromChannel(self, channel, user, message):
            if message.startswith("hello"):
                self.sendMessageToChannel(user, "Hello %s! How are you doing?" % user)
            elif message.startswith("wtf"):
                self.sendMessageToChannel(user, "That's not very nice behavior " + user )[/B][B]
                     
             # < I have a longer list of replies and comments but you get the idea......
        
bot.close()[/B]
 
[B]