Example #1
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])
Example #2
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])
Example #3
0
 def _handleTOPIC(self, nick, ident, host, params):
     if params[0] not in self.connection.channels:
         self._logWarning("Received TOPIC message for unknown channel {}.".format(params[0]))
         return
     channel = self.connection.channels[params[0]]
     if nick not in self.connection.users:
         # A user that's not in the channel can change the topic so let's make a temporary user.
         user = IRCUser(nick, ident, host)
     else:
         user = self.connection.users[nick]
     oldTopic = channel.topic
     channel.topic = params[1]
     channel.topicSetter = user.fullUserPrefix()
     channel.topicTimestamp = timeutils.timestamp(timeutils.now())
     self.moduleHandler.runGenericAction("changetopic", self.connection.name, channel, user, oldTopic, params[1])
Example #4
0
 def _handleKICK(self, nick, ident, host, params):
     if params[0] not in self.connection.channels:
         self._logWarning(
             "Received KICK message for unknown channel {}.".format(
                 params[0]))
         return
     channel = self.connection.channels[params[0]]
     if params[1] not in channel.users:
         self._logWarning(
             "Received KICK message for unknown user {} in channel {}.".
             format(nick, params[0]))
         return
     if nick not in self.connection.users:
         # Technically opers could KICK a user despite not being in the channel themselves
         kicker = IRCUser(nick, ident, host)
     else:
         kicker = self.connection.users[nick]
     kicked = self.connection.users[params[1]]
     reason = ""
     if len(params) > 2:
         reason = params[2]
     # We need to run the action before we actually get rid of the user
     self.moduleHandler.runGenericAction("channelkick",
                                         self.connection.name, channel,
                                         kicker, kicked, reason)
     if kicked.nick == self.connection.nick:
         del self.connection.channels[params[0]]
     else:
         del channel.users[kicked.nick]
         del channel.ranks[kicked.nick]
Example #5
0
 def _handleINVITE(self, nick, ident, host, params):
     if nick in self.connection.users:
         inviter = self.connection.users[nick]
     else:
         inviter = IRCUser(nick, ident, host)
     self.moduleHandler.runGenericAction("channelinvite",
                                         self.connection.name, params[1],
                                         inviter)
     self.connection.outputHandler.cmdJOIN(params[1])
Example #6
0
 def _handleTOPIC(self, nick, ident, host, params):
     if params[0] not in self.connection.channels:
         self._logWarning(
             "Received TOPIC message for unknown channel {}.".format(
                 params[0]))
         return
     channel = self.connection.channels[params[0]]
     if nick not in self.connection.users:
         # A user that's not in the channel can change the topic so let's make a temporary user.
         user = IRCUser(nick, ident, host)
     else:
         user = self.connection.users[nick]
     oldTopic = channel.topic
     channel.topic = params[1]
     channel.topicSetter = user.fullUserPrefix()
     channel.topicTimestamp = timeutils.timestamp(timeutils.now())
     self.moduleHandler.runGenericAction("changetopic",
                                         self.connection.name, channel,
                                         user, oldTopic, params[1])
Example #7
0
    def handleExtendedJoin(self, server, nick, ident, host, params):
        if not self.bot.moduleHandler.runActionUntilTrue("has-cap-enabled", server,self.capName):
            return False

        if nick not in self.bot.servers[server].users:
            user = IRCUser(nick, ident, host)
            if params[1] != "*":
                user.account = params[1]
            user.gecos = params[2]
            self.bot.servers[server].users[nick] = user
        else:
            user = self.bot.servers[server].users[nick]
        if params[0] not in self.bot.servers[server].channels:
            channel = IRCChannel(params[0], self.bot.servers[server])
            self.bot.servers[server].outputHandler.cmdWHO(params[0])
            self.bot.servers[server].outputHandler.cmdMODE(params[0])
            self.bot.servers[server].channels[params[0]] = channel
        else:
            channel = self.bot.servers[server].channels[params[0]]
        channel.users[nick] = user
        channel.ranks[nick] = ""
        self.bot.moduleHandler.runGenericAction("channeljoin", self.bot.servers[server].name, channel, user)
        return True  # Override the core JOIN handler
Example #8
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)
Example #9
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[8:len(body) - 1])
     else:
         message = "<{}{}> {}".format(source.getHighestStatusOfUser(user),
                                      user.nick, body)
     self._writeLog(server, source.name, message)
Example #10
0
 def _handleMODE(self, nick, ident, host, params):
     if nick in self.connection.users:
         user = self.connection.users[nick]
     else:
         user = IRCUser(nick, ident, host)
     if len(params) > 2:
         modeParams = params[2:]
     else:
         modeParams = []
     if params[0][0] in self.connection.supportHelper.chanTypes:
         if params[0] not in self.connection.channels:
             self._logWarning(
                 "Received MODE message for unknown channel {}.".format(
                     params[0]))
             return
         channel = self.connection.channels[params[0]]
         modes = channel.setModes(params[1], modeParams)
         if not modes:
             return
         if len(modes["added"]) > 0:
             self.moduleHandler.runGenericAction("modeschanged-channel",
                                                 self.connection.name, user,
                                                 channel, modes["added"],
                                                 modes["addedParams"], True)
         if len(modes["removed"]) > 0:
             self.moduleHandler.runGenericAction("modeschanged-channel",
                                                 self.connection.name, user,
                                                 channel, modes["removed"],
                                                 modes["removedParams"],
                                                 False)
     elif params[0] == self.connection.nick:
         modes = self.connection.setUserModes(params[1])
         if not modes:
             return
         if len(modes["added"]) > 0:
             self.moduleHandler.runGenericAction("modeschanged-user",
                                                 self.connection.name,
                                                 modes["added"], True)
         if len(modes["removed"]) > 0:
             self.moduleHandler.runGenericAction("modeschanged-user",
                                                 self.connection.name,
                                                 modes["removed"], False)
Example #11
0
 def _handleNumeric353(self, prefix, params):
     # 353: RPL_NAMREPLY
     channel = self.connection.channels[params[2]]
     if channel.userlistComplete:
         channel.userlistComplete = False
         channel.users.clear()
         channel.ranks.clear()
     for userPrefix in params[3].split():
         parsedPrefix = parseUserPrefix(userPrefix)
         nick = parsedPrefix[0]
         ranks = ""
         while nick[0] in self.connection.supportHelper.statusSymbols:
             ranks += self.connection.supportHelper.statusSymbols[nick[0]]
             nick = nick[1:]
         if nick in self.connection.users:
             user = self.connection.users[nick]
             user.ident = parsedPrefix[1]
             user.host = parsedPrefix[2]
         else:
             user = IRCUser(nick, parsedPrefix[1], parsedPrefix[2])
             self.connection.users[nick] = user
         channel.users[nick] = user
         channel.ranks[nick] = ranks