Esempio n. 1
0
    def __init__(self):
        self.se = SEChatWrapper(SE_HOST)
        self.se.login(SE_OPENID_USER, SE_OPENID_PASSWORD)
        self.se.joinRoom(SE_ROOM_ID)
        self.se.watchRoom(SE_ROOM_ID, self.on_se_message, 5)

        irc.bot.SingleServerIRCBot.__init__(
            self, [(IRC_SERVER, IRC_PORT)], IRC_NICK, IRC_NICK)
Esempio n. 2
0
class Bot(irc.bot.SingleServerIRCBot):
    def __init__(self):
        self.se = SEChatWrapper(SE_HOST)
        self.se.login(SE_OPENID_USER, SE_OPENID_PASSWORD)
        self.se.joinRoom(SE_ROOM_ID)
        self.se.watchRoom(SE_ROOM_ID, self.on_se_message, 5)

        irc.bot.SingleServerIRCBot.__init__(
            self, [(IRC_SERVER, IRC_PORT)], IRC_NICK, IRC_NICK)

    def on_se_message(self, message, chat):
        if IRC_SILENT:
            return

        if message['user_id'] != SE_USER_ID:
            message_remaining = h.unescape(message['content'])

            # we split long messages so the IRC server doesn't complin
            self.connection.privmsg(IRC_CHANNEL,
                "%s: %s" % (
                    message['user_name'], message_remaining[:256]
                )
            )

            message_remaining = message_remaining[256:]

            while message_remaining:
                self.connection.privmsg(IRC_CHANNEL,
                    "%s [ctn'd]: %s" % (
                        message['user_name'], message_remaining
                    )
                )
                
                message_remaining = message_remaining[256:]

    def on_welcome(self, c, event):
        c.join(IRC_CHANNEL)
        self.se.sendMessage(SE_ROOM_ID, 
            "***[Connected to IRC Server and Joined Channel: %s:%s/%s]***" % (
                IRC_SERVER, IRC_PORT, IRC_CHANNEL))

    def _on_disconnect(self, *a, **kw):
        self.se.sendMessage(SE_ROOM_ID, 
            "***[Disconnected from IRC Server]***")
        return super(Bot, self)._on_disconnect(*a, **kw)

    def _on_kick(self, *a, **kw):
        self.se.sendMessage(SE_ROOM_ID, 
            "***[Kicked from IRC Channel]***")
        return super(Bot, self)._on_kick(*a, **kw)

    def on_pubmsg(self, connection, event):
        if IRC_NICK not in event.source.nick:
            body = event.arguments[0]
            self.se.sendMessage(SE_ROOM_ID, 
                "**[%s]** %s" % (event.source.nick, body,))