Beispiel #1
0
 def on_ctcp(self, connection, event): # this is for /me actions
     ctcp_cmd = event.arguments[0]
     if ctcp_cmd == "ACTION":
         msg = event.arguments[1]
         nick = event.source.nick
         channel = event.target
         plugins.myprint("%s: *%s %s" % (channel, nick, msg))
Beispiel #2
0
    def join_channels(self, connection):
        for ch in connection.params[6]:
            connection.locks[ch] = threading.Lock()

        mchans = ",".join(connection.params[6])
        plugins.myprint("%s: joining %s" % (connection.params[0], mchans))
        connection.send_raw("JOIN %s" % mchans)
Beispiel #3
0
    def on_nick(self, connection, event):
        oldnick = event.source.nick
        newnick = event.target
        plugins.myprint("%s: %s is now known as %s" % (connection.params[0], oldnick, newnick))

        # reconquer our nick!
        if oldnick == settings.bot_name:
            connection.nick(settings.bot_name)
Beispiel #4
0
    def on_action(self, connection, event):
        msg = event.arguments[0]
        nick = event.source.nick

        if irc.client.is_channel(event.target):
            target = event.target
        else:
            target = nick

        plugins.myprint("%s: *%s %s" % (target, nick, msg))
Beispiel #5
0
    def on_privmsg(self, connection, event):
        nick = event.source.nick
        chat = nick
        msg = event.arguments[0]
        plugins.myprint("%s: %s: %s" % (chat, nick, msg))

        # possible command
        if msg and msg[0] == settings.cmd_prefix:
            self.react_to_command(connection, event, msg[1:])
        elif msg:
            tmp = msg.split(" ", 1)
            tonick = tmp[0]
            args = tmp[1] if len(tmp) == 2 else None
            if (tonick == settings.bot_name or tonick[:-1] == settings.bot_name) and args:
                self.react_to_command(connection, event, args)
Beispiel #6
0
    def on_disconnect(self, connection, event):
        if self.tehbot.core.quit_called:
            return

        delay = 120
        plugins.myprint("%s: lost connection" % (connection.params[0]))
        plugins.myprint("%s: reconnecting in %d seconds" % (connection.params[0], delay))

        with self.tehbot.core.reactor.mutex:
            for cmd in self.tehbot.core.reactor.delayed_commands[:]:
                if cmd.function.func.args == ('keep-alive',) and cmd.function.func.func.__self__ == connection:
                    print "removing cmd", cmd
                    self.tehbot.core.reactor.delayed_commands.remove(cmd)

        self.tehbot.core.reactor.execute_delayed(delay, self.tehbot.reconnect, (connection,))
Beispiel #7
0
    def on_pubmsg(self, connection, event):
        nick = event.source.nick
        channel = event.target
        msg = event.arguments[0]
        plugins.myprint("%s: %s: %s" % (channel, nick, msg))

        # possible command
        if msg and msg[0] == settings.cmd_prefix:
            self.react_to_command(connection, event, msg[1:])
        elif msg:
            tmp = msg.split(" ", 1)
            tonick = tmp[0]
            args = tmp[1] if len(tmp) == 2 else None
            if (tonick == settings.bot_name or tonick[:-1] == settings.bot_name) and args:
                self.react_to_command(connection, event, args)
            for h in self.tehbot.channel_handlers:
                self.tehbot.core.queue.put((h, (connection, channel, nick, msg)))
Beispiel #8
0
    def on_quit(self, connection, event):
        plugins.myprint("%s: %s has quit (%s)" % (connection.name, event.source.nick, event.arguments[0]))
        botname = self.tehbot.settings.value("botname", connection)
        nick = event.source.nick

        for channel in connection.tehbot_users.keys():
            try:
                connection.tehbot_users[channel].remove(nick)
            except ValueError as e:
                pass

        print "part", channel, connection.tehbot_users[channel]

        # reconquer our nick!
        if nick == botname:
            connection.nick(botname)

        try:
            self.tehbot.privusers[connection].remove(nick)
        except:
            pass
Beispiel #9
0
    def on_join(self, connection, event):
        plugins.myprint("%s: %s: %s joined" % (connection.name, event.target, event.source.nick))
        nick = event.source.nick
        channel = event.target
        botname = self.tehbot.settings.value("botname", connection)

        connection.tehbot_users[channel].append(nick)
        print "join", channel, connection.tehbot_users[channel]

        if nick == botname:
            connection.channels.add(channel.lower())

            params = self.tehbot.settings.connection_params(connection)
            channels = set(params.get("channels", []))

            if channel.lower() not in channels:
                connection.part(channel)

            return

        for h in self.tehbot.channel_join_handlers:
            self.tehbot.queue.put((h, (connection, event, {})))
Beispiel #10
0
    def join_channels(self, connection):
        params = self.tehbot.settings.connection_params(connection)
        channels = set(params.get("channels", []))

        channels_to_join = channels.difference(connection.channels)
        channels_to_part = connection.channels.difference(channels)

        for ch in channels_to_join:
            connection.locks[ch] = threading.Lock()

        for ch in channels_to_part:
            del connection.locks[ch]

        if channels_to_join:
            mchans = ",".join(channels_to_join)
            plugins.myprint("%s: joining %s" % (connection.name, mchans))
            connection.send_raw("JOIN %s" % mchans)

        if channels_to_part:
            mchans = ",".join(channels_to_part)
            plugins.myprint("%s: parting %s" % (connection.name, mchans))
            connection.part(channels_to_part)
Beispiel #11
0
 def on_privmsg(self, connection, event):
     nick = event.source.nick
     channel = event.target
     msg = event.arguments[0]
     plugins.myprint("%s: %s: %s" % (channel, nick, msg))
Beispiel #12
0
    def on_quit(self, connection, event):
        plugins.myprint("%s: %s has quit (%s)" % (connection.params[0], event.source.nick, event.arguments[0]))

        # reconquer our nick!
        if event.source.nick == settings.bot_name:
            connection.nick(settings.bot_name)
Beispiel #13
0
 def on_part(self, connection, event):
     plugins.myprint("%s: %s left" % (event.target, event.source.nick))
Beispiel #14
0
 def on_join(self, connection, event):
     plugins.myprint("%s: %s joined" % (event.target, event.source.nick))
Beispiel #15
0
 def on_welcome(self, connection, event):
     plugins.myprint("%s: connected to %s" % (connection.params[0], connection.server))
     for ch in connection.params[6]:
         plugins.myprint("%s: joining %s" % (connection.params[0], ch))
         connection.locks[ch] = threading.Lock()
         connection.join(ch)
Beispiel #16
0
 def on_welcome(self, connection, event):
     plugins.myprint("%s: connected to %s" % (connection.params[0], connection.server))
     self.tehbot.core.reactor.execute_delayed(10, self.join_channels, (connection,))
Beispiel #17
0
 def on_welcome(self, connection, event):
     plugins.myprint("%s: connected to %s" % (connection.name, connection.server))
     self.tehbot.core.reactor.scheduler.execute_after(2, functools.partial(self.join_channels, connection))