Example #1
0
    def _process_message(self, line):
        """Process a single message from IRC."""
        if line[1] == "JOIN":
            data = Data(self.bot, self.nick, line, msgtype="JOIN")
            self.bot.commands.call("join", data)

        elif line[1] == "PRIVMSG":
            data = Data(self.bot, self.nick, line, msgtype="PRIVMSG")
            if data.is_private:
                self.bot.commands.call("msg_private", data)
            else:
                self.bot.commands.call("msg_public", data)
            self.bot.commands.call("msg", data)

        elif line[1] == "376":  # On successful connection to the server
            # If we're supposed to auth to NickServ, do that:
            try:
                username = self.bot.config.irc["frontend"]["nickservUsername"]
                password = self.bot.config.irc["frontend"]["nickservPassword"]
            except KeyError:
                pass
            else:
                msg = "IDENTIFY {0} {1}".format(username, password)
                self.say("NickServ", msg, hidelog=True)

            # Join all of our startup channels:
            for chan in self.bot.config.irc["frontend"]["channels"]:
                self.join(chan)
Example #2
0
    def _process_message(self, line):
        """Process a single message from IRC."""
        if line[1] == "JOIN":
            data = Data(self.nick, line, msgtype="JOIN")
            self.bot.commands.call("join", data)

        elif line[1] == "PART":
            data = Data(self.nick, line, msgtype="PART")
            self.bot.commands.call("part", data)

        elif line[1] == "PRIVMSG":
            data = Data(self.nick, line, msgtype="PRIVMSG")
            if data.is_private:
                self.bot.commands.call("msg_private", data)
            else:
                self.bot.commands.call("msg_public", data)
            self.bot.commands.call("msg", data)

        elif line[1] == "NOTICE":
            data = Data(self.nick, line, msgtype="NOTICE")
            if self._auth_wait and data.nick == self.NICK_SERVICES:
                if data.msg.startswith("This nickname is registered."):
                    return
                self._auth_wait = False
                sleep(2)  # Wait for hostname change to propagate
                self._join_channels()

        elif line[1] == "376":  # On successful connection to the server
            # If we're supposed to auth to NickServ, do that:
            try:
                username = self.bot.config.irc["frontend"]["nickservUsername"]
                password = self.bot.config.irc["frontend"]["nickservPassword"]
            except KeyError:
                self._join_channels()
            else:
                self.logger.debug("Identifying with services")
                msg = "IDENTIFY {0} {1}".format(username, password)
                self.say(self.NICK_SERVICES, msg, hidelog=True)
                self._auth_wait = True

        elif line[1] == "401":  # No such nickname
            if self._auth_wait and line[3] == self.NICK_SERVICES:
                # Services is down, or something...?
                self._auth_wait = False
                self._join_channels()
Example #3
0
 def maker(self, line, chan, msg=None):
     data = Data(line)
     data.nick, data.ident, data.host = self.re_sender.findall(line[0])[0]
     if msg is not None:
         data.msg = msg
     data.chan = chan
     data.parse_args()
     return data
Example #4
0
 def maker(self, line, chan, msg=None):
     data = Data(line)
     data.nick, data.ident, data.host = self.re_sender.findall(line[0])[0]
     if msg is not None:
         data.msg = msg
     data.chan = chan
     data.parse_args()
     return data
Example #5
0
    def _load_reminders(self):
        """Load previously made reminders from the database."""
        with self._db() as permdb:
            try:
                database = permdb.get_attr("command:remind", "data")
            except KeyError:
                return
            permdb.set_attr("command:remind", "data", "[]")

        for item in ast.literal_eval(database):
            rid, user, wait, end, message, data = item
            if end < time.time():
                continue
            data = Data.unserialize(data)
            reminder = _Reminder(rid, user, wait, end, message, data, self)
            self._start_reminder(reminder, user)
Example #6
0
    def _load_reminders(self):
        """Load previously made reminders from the database."""
        with self._db() as permdb:
            try:
                database = permdb.get_attr("command:remind", "data")
            except KeyError:
                return
            permdb.set_attr("command:remind", "data", "[]")

        for item in ast.literal_eval(database):
            rid, user, wait, end, message, data = item
            if end < time.time():
                continue
            data = Data.unserialize(data)
            reminder = _Reminder(rid, user, wait, end, message, data, self)
            self._start_reminder(reminder, user)
Example #7
0
    def _load_reminders(self):
        """Load previously made reminders from the database."""
        permdb = self.config.irc["permissions"]
        try:
            database = permdb.get_attr("command:remind", "data")
        except KeyError:
            return
        permdb.set_attr("command:remind", "data", "[]")

        connect_wait = 30
        for item in ast.literal_eval(database):
            rid, user, wait, end, message, data = item
            if end < time.time() + connect_wait:
                # Make reminders that have expired while the bot was offline
                # trigger shortly after startup
                end = time.time() + connect_wait
            data = Data.unserialize(data)
            reminder = _Reminder(rid, user, wait, message, data, self, end)
            self._start_reminder(reminder, user)