Exemplo n.º 1
0
    def on_ctcp(self, c, e):
        """Default handler for ctcp events.

        Replies to VERSION and PING requests and relays DCC requests
        to the on_dccchat method.
        """
        if e.arguments()[0] == "VERSION":
            c.ctcp_reply(nm_to_n(e.source()), "VERSION " + self.get_version())
        elif e.arguments()[0] == "PING":
            if len(e.arguments()) > 1:
                c.ctcp_reply(nm_to_n(e.source()), "PING " + e.arguments()[1])
        elif e.arguments()[0] == "DCC" and e.arguments()[1].split(
                " ", 1)[0] == "CHAT":
            self.on_dccchat(c, e)
Exemplo n.º 2
0
 def _on_nick(self, c, e):
     """[Internal]"""
     before = nm_to_n(e.source())
     after = e.target()
     for ch in self.channels.values():
         if ch.has_user(before):
             ch.change_nick(before, after)
Exemplo n.º 3
0
 def _on_join(self, c, e):
     """[Internal]"""
     ch = e.target()
     nick = nm_to_n(e.source())
     if nick == c.get_nickname():
         self.channels[ch] = Channel()
     self.channels[ch].add_user(nick)
Exemplo n.º 4
0
    def on_pubmsg(self, connection, event):
        nick = irclib.nm_to_n(event.source())
        request = event.arguments()[0]

        if not irclib.irc_lower(request).startswith(
                irclib.irc_lower(connection.get_nickname())):
            return

        if len(request) <= len(connection.get_nickname()):
            return

        # Some IRC clients, like xchat-gnome, default to using a comma
        # when addressing someone.
        vocative_separator = request[len(connection.get_nickname())]
        if vocative_separator == ':':
            request = request.split(':', 1)
        elif vocative_separator == ',':
            request = request.split(',', 1)
        else:
            return

        if len(request) > 1:
            response = self._delegate.irc_message_received(nick, request[1])
            if response:
                connection.privmsg(self._channel, response)
Exemplo n.º 5
0
    def _on_part(self, c, e):
        """[Internal]"""
        nick = nm_to_n(e.source())
        channel = e.target()

        if nick == c.get_nickname():
            del self.channels[channel]
        else:
            self.channels[channel].remove_user(nick)
Exemplo n.º 6
0
    def on_pubmsg(self, connection, event):
        nick = irclib.nm_to_n(event.source())
        request = event.arguments()[0]

        if not irclib.irc_lower(request).startswith(irclib.irc_lower(connection.get_nickname())):
            return

        if len(request) <= len(connection.get_nickname()):
            return

        # Some IRC clients, like xchat-gnome, default to using a comma
        # when addressing someone.
        vocative_separator = request[len(connection.get_nickname())]
        if vocative_separator == ':':
            request = request.split(':', 1)
        elif vocative_separator == ',':
            request = request.split(',', 1)
        else:
            return

        if len(request) > 1:
            response = self._delegate.irc_message_received(nick, request[1])
            if response:
                connection.privmsg(self._channel, response)
Exemplo n.º 7
0
 def _on_quit(self, c, e):
     """[Internal]"""
     nick = nm_to_n(e.source())
     for ch in self.channels.values():
         if ch.has_user(nick):
             ch.remove_user(nick)