示例#1
0
文件: core.py 项目: Dritz/pyGBot
    def privmsg(self, user, channel, msg):
        """ Called when the bot receives a message (from channel or user). """
        user = user.split('!', 1)[0]
        userIn = format.decodeIn(user)
        channelIn = format.decodeIn(channel)
        msgIn = format.decodeIn(msg)

        # Private message to me
        if channel.upper() == self.nickname.upper():
            # If auth msg has password, censor it for logging
            if msgIn.startswith('auth'):
                msgNoPwd = msgIn.split(' ')
                if len(msgNoPwd) > 2:
                    msgNoPwd[2] = '*' * 8
                msgNoPwd = ' '.join(msgNoPwd)
                log.chatlog.info('[PRV<-]<%s> %s' % (user, msgNoPwd))
            else:
                log.chatlog.info('[PRV<-]<%s> %s' % (user, msg))
            # Call Event Handler
            self.events.msg_private(userIn, msgIn)

        # Public message
        else:
            log.chatlog.info('[PUB<-]<%s> %s' % (user, msg))
            # Call Event Handler
            self.events.msg_channel(channelIn, userIn, msgIn)
示例#2
0
文件: core.py 项目: Dritz/pyGBot
 def userRenamed(self, oldname, newname):
     """Called when the bot sees a user change their nickname from oldname to
     newname. """
     oldnameIn = format.decodeIn(oldname)
     newnameIn = format.decodeIn(newname)
     log.chatlog.info('%s is now known as %s' % (oldname, newname))
     # Call Event Handler
     self.events.user_nickchange(oldnameIn, newnameIn)
示例#3
0
文件: core.py 项目: Dritz/pyGBot
 def kickedFrom(self, channel, kicker, message):
     """ Called when the bot is kicked from a channel. """
     channelIn = format.decodeIn(channel)
     kickerIn = format.decodeIn(kicker)
     messageIn = format.decodeIn(message)
     if channelIn in self.channels:
         self.channels.remove(channelIn)
     self.events.bot_kicked(channelIn, kickerIn, messageIn)
示例#4
0
文件: core.py 项目: Dritz/pyGBot
    def userLeft(self, user, channel):
        """Called when the bot sees a user leaving a channel. """
        user = user.split('!', 1)[0]
        userIn = format.decodeIn(user)
        channelIn = format.decodeIn(channel)
        log.chatlog.info('%s has left %s' % (user, channel))

        # Call Event Handler
        self.events.user_part(channelIn, userIn)
示例#5
0
文件: core.py 项目: Dritz/pyGBot
    def userJoined(self, user, channel):
        """Called when the bot sees a user joining a channel. """
        user = user.split('!', 1)[0]
        userIn = format.decodeIn(user)
        channelIn = format.decodeIn(channel)
        log.chatlog.info('%s joined %s' % (user, channel))

        # Call Event Handler
        self.events.user_join(channelIn, userIn)
示例#6
0
文件: core.py 项目: Dritz/pyGBot
 def userQuit(self, user, quitMessage):
     """ Called when the bot sees a user disconnect from the network. """
     user = user.split('!', 1)[0]
     userIn = format.decodeIn(user)
     quitMsgIn = format.decodeIn(quitMessage)
     
     log.chatlog.info("%s has quit [%s]" % (user, quitMessage))
     
     # Call Event Handler
     self.events.user_quit(userIn, quitMsgIn)
示例#7
0
文件: core.py 项目: Dritz/pyGBot
    def topicUpdated(self, user, channel, newTopic):
        """ Called when the bot sees the channel topic change. """
        user = user.split('!', 1)[0]
        userIn = format.decodeIn(user)
        channelIn = format.decodeIn(channel)
        newTopicIn = format.decodeIn(newTopic)
        log.chatlog.info('Topic for %s set by %s: %s' % (channel, user, newTopic))

        # Call Event Handler
        self.events.channel_topic(channelIn, userIn, newTopicIn)
示例#8
0
文件: core.py 项目: Dritz/pyGBot
    def action(self, user, channel, msg):
        """ Called when the bot sees someone do an action (/me). """
        user = user.split('!', 1)[0]
        userIn = format.decodeIn(user)
        channelIn = format.decodeIn(channel)
        msgIn = format.decodeIn(msg)
        log.chatlog.info('* %s %s' % (user, msg))

        # Call Event Handler
        self.events.msg_action(channelIn, userIn, msgIn)
示例#9
0
文件: core.py 项目: Dritz/pyGBot
    def noticed(self, user, channel, msg):
        """ Called when the bot receives a NOTICE. """
        user = user.split('!', 1)[0]
        userIn = format.decodeIn(user)
        channelIn = format.decodeIn(channel)
        msgIn = format.decodeIn(msg)
        log.chatlog.info('[NTE<-]<%s> %s' % (user, msg))

        # Call Event Handler
        self.events.msg_notice(userIn, msgIn)
示例#10
0
文件: core.py 项目: Dritz/pyGBot
    def userKicked(self, user, channel, kicker, message):
        """ Called when the bot sees a user get kicked. """
        user = user.split('!', 1)[0]
        userIn = format.decodeIn(user)
        channelIn = format.decodeIn(channel)
        kickerIn = format.decodeIn(kicker)
        messageIn = format.decodeIn(message)
        
        log.chatlog.info('%s was kicked from %s by %s (reason: %s)' % (user, channel, kicker, message))

        self.events.user_kicked(channelIn, userIn, kickerIn, messageIn)
示例#11
0
文件: core.py 项目: Dritz/pyGBot
    def joined(self, channel):
        """ Called when the bot joins a channel. """
        log.logger.info('[I have joined %s]' % (channel,))

        # Set modes
        if hasattr(self, 'plusmodes'):
            self.mode(channel, True, self.plusmodes)
        if hasattr(self, 'minusmodes'):
            self.mode(channel, False, self.minusmodes)
        
        # Call Event Handler
        channelIn = format.decodeIn(channel)
        self.channels.append(channelIn)
        self.events.bot_join(channelIn)
示例#12
0
文件: core.py 项目: Dritz/pyGBot
def decodeIn(msg):
    """ DEPRECATED. Maintained for backwards compatibility. Use
    pyGBot.format.decodeIn(). """
    log.logger.warning("DEPRECATED: pyGBot.core.decodeIn() is deprecated. " +\
    "Use format.decodeIn().")
    return format.decodeIn(msg)
示例#13
0
文件: core.py 项目: Dritz/pyGBot
 def left(self, channel):
     """ Called when the bot leaves a channel. """
     channelIn = format.decodeIn(channel)
     if channelIn in self.channels:
         self.channels.remove(channelIn)
示例#14
0
文件: core.py 项目: Dritz/pyGBot
        connector.connect()

def run():
    """ Run GBot. Called from the pyGBot bootstrap script. """
    try:
        conf = ConfigObj('pyGBot.ini')
    except IOError, msg:
        print "Cannot open config file: ", msg
        sys.exit(1)

    if conf.has_key('IRC') == False:
        print "Config file does not contain IRC connection information."
        sys.exit(1)

    try:
        channels = format.decodeIn(conf['IRC']['channel']).split()
        host = conf['IRC']['host']
        port = int(conf['IRC']['port'])
    except ConfigObjError:
        print "Required IRC connection info missing or invalid."
        sys.exit(1)

    localport = None
    localaddr = None

    if conf['IRC'].has_key('localport'):
        localport = int(conf['IRC']['localport'])
    if conf['IRC'].has_key('localaddr'):
        localaddr = conf['IRC']['localaddr']

    print "Initialising Factory..."