예제 #1
0
 def _handleNOTICE(self, nick, ident, host, params):
     user = None
     if params[0][0] in self.connection.supportHelper.chanTypes:
         if params[0] in self.connection.channels:
             source = self.connection.channels[params[0]]
         else:
             # We got a notice for an unknown channel. Create a temporary IRCChannel object for it.
             source = IRCChannel(params[0], self)
         if nick in self.connection.users:
             user = self.connection.users[nick]
         else:
             user = IRCUser(nick, ident, host)
     elif nick in self.connection.users:
         source = self.connection.users[nick]
     else:
         # We got a notice from an unknown user. Create a temporary IRCUser object for them.
         source = IRCUser(nick, ident, host)
     if isinstance(source, IRCChannel):
         self.moduleHandler.runGenericAction("notice-channel",
                                             self.connection.name, source,
                                             user, params[1])
     else:
         self.moduleHandler.runGenericAction("notice-user",
                                             self.connection.name, source,
                                             params[1])
예제 #2
0
 def _handlePRIVMSG(self, nick, ident, host, params):
     user = None
     if params[0][0] in self.connection.supportHelper.chanTypes:
         if params[0] in self.connection.channels:
             source = self.connection.channels[params[0]]
         else:
             # We got a message for an unknown channel. Create a temporary IRCChannel object for it.
             source = IRCChannel(params[0], self.connection)
         if nick in self.connection.users:
             user = self.connection.users[nick]
         else:
             user = IRCUser(nick, ident, host)
     elif nick in self.connection.users:
         source = self.connection.users[nick]
         user = source
     else:
         # We got a message from an unknown user. Create a temporary IRCUser object for them.
         source = IRCUser(nick, ident, host)
     if params[1][0] == "\x01":
         message = params[1][1:len(params[1]) - 1]
         self.moduleHandler.runGenericAction("ctcp-message",
                                             self.connection.name, source,
                                             user, message)
     elif isinstance(source, IRCChannel):
         self.moduleHandler.runGenericAction("message-channel",
                                             self.connection.name, source,
                                             user, params[1])
     else:
         self.moduleHandler.runGenericAction("message-user",
                                             self.connection.name, source,
                                             params[1])
예제 #3
0
    def _handleINVITE(self, nick, ident, host, params):
        if nick in self.bot.users:
            inviter = self.bot.users[nick]
        else:
            inviter = IRCUser(nick, ident, host)

        invitee = None
        if 'invite-notify' in self.bot.capabilities['finished'] and len(
                params) > 1:
            if params[0] not in self.bot.users:
                invitee = IRCUser(params[0])
            else:
                invitee = self.bot.users[nick]
            chanName = params[1]
        else:
            chanName = params[0]

        if chanName not in self.bot.channels:
            channel = IRCChannel(params[0], self.bot)
        else:
            channel = self.bot.channels[chanName]
        if not invitee or invitee.nick == self.bot.nick:
            self.bot.output.cmdJOIN(chanName)
        message = IRCMessage('INVITE', inviter, channel, '', self.bot,
                             {'invitee': invitee})
        self.handleMessage(message)
예제 #4
0
 def _handleJOIN(self, nick, ident, host, params):
     if nick not in self.connection.users:
         user = IRCUser(nick, ident, host)
         self.connection.users[nick] = user
     else:
         user = self.connection.users[nick]
     if params[0] not in self.connection.channels:
         channel = IRCChannel(params[0], self.connection)
         self.connection.outputHandler.cmdWHO(params[0])
         self.connection.outputHandler.cmdMODE(params[0])
         self.connection.channels[params[0]] = channel
     else:
         channel = self.connection.channels[params[0]]
     channel.users[nick] = user
     channel.ranks[nick] = ""
     self.moduleHandler.runGenericAction("channeljoin",
                                         self.connection.name, channel,
                                         user)
예제 #5
0
 def logBotMessage(self, server, source, body):
     if source[0] not in self.bot.servers[server].supportHelper.chanTypes:
         return
     if source not in self.bot.servers[server].channels:
         source = IRCChannel(source, self.bot.servers[server])
     else:
         source = self.bot.servers[server].channels[source]
     if self.bot.servers[server].nick not in self.bot.servers[server].users:
         user = IRCUser(self.bot.servers[server].nick, None, None)
     else:
         user = self.bot.servers[server].users[
             self.bot.servers[server].nick]
     if body.startswith(":\x01ACTION"):
         message = "* {} {}".format(user.nick, body[9:len(body) - 1])
     else:
         message = "<{}{}> {}".format(source.getHighestStatusOfUser(user),
                                      user.nick, body[1:])
     self._writeLog(server, source.name, message)
예제 #6
0
    def activate(self):
        commandStr = '{}{} {}'.format(self.bot.commandChar, self.command,
                                      ' '.join(self.params))
        self.logger.info("Activated {!r}".format(commandStr))
        message = IRCMessage('PRIVMSG', IRCUser(self.user),
                             IRCChannel(self.channel, self.bot), commandStr,
                             self.bot)

        trigger = self.bot.moduleHandler.mappedTriggers[self.command].execute

        return trigger(message)
예제 #7
0
    def _handleJOIN(self, nick, ident, host, params):
        if nick not in self.bot.users:
            user = IRCUser(nick, ident, host)
            if 'extended-join' in self.bot.capabilities['finished'] and len(params) > 1:
                if params[1] != '*':
                    user.account = params[1]
                user.gecos = params[2]
            self.bot.users[nick] = user
        else:
            user = self.bot.users[nick]

        if params[0] not in self.bot.channels:
            channel = IRCChannel(params[0], self.bot)
            self.bot.output.cmdWHO(params[0])
            self.bot.output.cmdMODE(params[0])
            self.bot.channels[params[0]] = channel
        else:
            channel = self.bot.channels[params[0]]
        channel.users[nick] = user
        channel.ranks[nick] = ''
        message = IRCMessage('JOIN', user, channel, '', self.bot)
        self.handleMessage(message)
예제 #8
0
    def _handleJOIN(self, nick, ident, host, params):
        if nick not in self.bot.users:
            user = IRCUser(nick, ident, host)
            if 'extended-join' in self.bot.capabilities['finished'] and len(
                    params) > 1:
                if params[1] != '*':
                    user.account = params[1]
                user.gecos = params[2]
            self.bot.users[nick] = user
        else:
            user = self.bot.users[nick]

        if params[0] not in self.bot.channels:
            channel = IRCChannel(params[0], self.bot)
            self.bot.output.cmdWHO(params[0])
            self.bot.output.cmdMODE(params[0])
            self.bot.channels[params[0]] = channel
        else:
            channel = self.bot.channels[params[0]]
        channel.users[nick] = user
        channel.ranks[nick] = ''
        message = IRCMessage('JOIN', user, channel, '', self.bot)
        self.handleMessage(message)
예제 #9
0
 def _handleNOTICE(self, nick, ident, host, params):
     user = None
     if params[0][0] in self.bot.supportHelper.chanTypes:
         if params[0] in self.bot.channels:
             source = self.bot.channels[params[0]]
         else:
             # We got a notice for an unknown channel. Create a temporary IRCChannel object for it.
             source = IRCChannel(params[0], self.bot)
         if nick in self.bot.users:
             user = self.bot.users[nick]
         else:
             user = IRCUser(nick, ident, host)
     elif nick in self.bot.users:
         source = self.bot.users[nick]
     else:
         # We got a notice from an unknown user. Create a temporary IRCUser object for them.
         source = IRCUser(nick, ident, host)
     if isinstance(source, IRCChannel):
         message = IRCMessage('NOTICE', user, source, params[1], self.bot)
     else:
         message = IRCMessage('NOTICE', source, None, params[1], self.bot)
     self.handleMessage(message)
예제 #10
0
 def _handlePRIVMSG(self, nick, ident, host, params):
     user = None
     if params[0][0] in self.bot.supportHelper.chanTypes:
         if params[0] in self.bot.channels:
             source = self.bot.channels[params[0]]
         else:
             # We got a message for an unknown channel. Create a temporary IRCChannel object for it.
             source = IRCChannel(params[0], self.bot)
         if nick in self.bot.users:
             user = self.bot.users[nick]
         else:
             user = IRCUser(nick, ident, host)
     elif nick in self.bot.users:
         source = self.bot.users[nick]
         user = source
     else:
         # We got a message from an unknown user. Create a temporary IRCUser object for them.
         source = IRCUser(nick, ident, host)
     if len(params) == 1:
         self.bot.logger.warning('Received a blank PRIVMSG')
         params.append('')
     if params[1] and params[1][0] == '\x01':
         msgType = 'CTCP'
         msgStr = params[1][1:len(params[1]) - 1]
         if msgStr.upper().startswith('ACTION'):
             msgType = 'ACTION'
             msgStr = msgStr[7:]
         if isinstance(source, IRCChannel):
             message = IRCMessage(msgType, user, source, msgStr, self.bot)
         else:
             message = IRCMessage(msgType, source, None, msgStr, self.bot)
     elif isinstance(source, IRCChannel):
         message = IRCMessage('PRIVMSG', user, source, params[1], self.bot)
     else:
         message = IRCMessage('PRIVMSG', source, None, params[1], self.bot)
     self.handleMessage(message)