From 5a0e1f597fe25d2b2144d8a6f821f5ac98c43f02 Mon Sep 17 00:00:00 2001 From: Terence Simpson Date: Wed, 11 Nov 2009 14:53:30 +0000 Subject: [PATCH] Modify IRCLogin to support bot CAPAB and CAP commands --- IRCLogin/plugin.py | 82 +++++++++++++++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 22 deletions(-) diff --git a/IRCLogin/plugin.py b/IRCLogin/plugin.py index 41e956d..2bedbac 100644 --- a/IRCLogin/plugin.py +++ b/IRCLogin/plugin.py @@ -203,23 +203,40 @@ launchpad""" self.log.info("Calling login for %s" % msg.prefix) self._callCommand(["login"], irc, msg, []) + def do290(self, irc, msg): + """hyperiron CAPAB reply""" + realIrc = irc.getRealIrc() + realIrc._Freenode_capabed_notices = False + if msg.args[1].lower() == "identify-msg": + realIrc._Freenode_capabed = True + else: + realIrc._Freenode_capabed = Dalse + def doCap(self, irc, msg): - self.log.info("Got CAP message %r" % msg) - if msg.args[1].lower() == "ack": - if "identify-msg" in msg.args[2].lower(): - irc.getRealIrc()._Freenode_capabed = True + """ircd-seven CAP reply""" + cmd = msg.args[1].lower() + args = msg.args[2].lower() + realIrc = irc.getRealIrc() + if cmd == "ls": # Got capability listing + if "identify-msg" in args: # identify-msg is a capability on this server + irc.queueMsg(ircmsgs.IrcMsg('CAP REQ IDENTIFY-MSG')) # Request identify-msg - if msg.args[1].lower() == 'nak': - if "identify-msg" in msg.args[2].lower(): - irc.getRealIrc()._Freenode_capabed = False + if cmd == "ack": # Acknowledge reply + if "identify-msg" in args: # identify-msg is set + realIrc._Freenode_capabed = True + realIrc._Freenode_capabed_notices = True - def do376(self, irc, msg): - irc.queueMsg(ircmsgs.IrcMsg('CAP REQ IDENTIFY-MSG')) + if cmd == 'nak': # Failure reply + if "identify-msg" in args: # identify-msg is not set + realIrc._Freenode_capabed = False + realIrc._Freenode_capabed_notices = False - def do422(self, irc, msg): # MOTD missing - irc.queueMsg(ircmsgs.IrcMsg('CAP REQ IDENTIFY-MSG')) + def do421(self, irc, msg): + """Invalid command""" + if msg.args[1].lower() == "cap": + irc.queueMsg(ircmsgs.IrcMsg("CAPAB IDENTIFY MSG")) - def inFilter(self, irc, msg): + def do376(self, irc, msg, force=False): # End of /MOTD command. """ The new freenode ircd-seven requires using the 'CAP' command to set capabilities, rather than hyperirons 'CAPAB' command. @@ -228,18 +245,39 @@ launchpad""" "CAP NAK :identify-msg" to indicate failure. Other than that, it's the same. """ - if not msg.command == "PRIVMSG": + if not hasattr(irc.getRealIrc(), "_Freenode_capabed") and not force: # Do this only once + realIrc = irc.getRealIrc() + realIrc._Freenode_capabed = False + realIrc._Freenode_capabed_notices = False + # Try the CAP command first + irc.ququeMsg(ircmsgs.IrcMsg("CAP LS")) + + do422 = do376 + + def inFilter(self, irc, msg): + """ + Strip the leading '+' or '-' from each message + """ + + if msg.command not in ("PRIVMSG", "NOTICE"): return msg - if getattr(irc,'_Freenode_capabed',None) and msg.command == 'PRIVMSG': - if msg.tagged('identified') == None: - first = msg.args[1][0] - rest = msg.args[1][1:] - msg.tag('identified', first == '+') - if first in ('+', '-'): - msg = ircmsgs.privmsg(msg.args[0], rest, msg=msg) - assert msg.receivedAt and msg.receivedOn and msg.receivedBy + + if not getattr(irc, '_Freenode_capabed', False): + return msg + + if msg.command == "NOTICE" and not getattr(irc, '_Freenode_capabed_notices', False): + return msg + + if msg.tagged('identified') == None: + first = msg.args[1][0] + rest = msg.args[1][1:] + msg.tag('identified', first == '+') + if first in ('+', '-'): + msg = ircmsgs.privmsg(msg.args[0], rest, msg=msg) + assert msg.receivedAt and msg.receivedOn and msg.receivedBy + if len(msg.args) >= 2 and msg.args[1] and msg.args[1][0] in ('+', '-'): - self.do376(irc, msg) + self.do376(irc, msg, True) return msg Class = IRCLogin