diff --git a/src/irclib.py b/src/irclib.py index 1b12d1c1a..1d358a3d0 100644 --- a/src/irclib.py +++ b/src/irclib.py @@ -931,20 +931,7 @@ class Irc(IrcCommandDispatcher): return - caps = ['account-notify', 'extended-join'] - - if self.sasl_password: - if not self.sasl_username: - log.warning('%s: SASL username is not set, unable to ' - 'identify.', self.network) - else: - caps.append('sasl') - - log.debug('%s: Requesting capabilities: %s', - self.network, ' '.join(caps)) - - for cap in caps: - self.queueMsg(ircmsgs.IrcMsg(command='CAP', args=('REQ', cap))) + self.queueMsg(ircmsgs.IrcMsg(command='CAP', args=('LS',))) if self.password: log.info('%s: Queuing PASS command, not logging the password.', @@ -975,16 +962,28 @@ class Irc(IrcCommandDispatcher): self.queueMsg(ircmsgs.IrcMsg(command='AUTHENTICATE', args=(authstring,))) def doCap(self, msg): + caps = ['account-notify', 'extended-join'] + + if self.sasl_password: + if self.sasl_username: + caps.append('sasl') + else: + log.warning('%s: SASL username is not set, unable to ' + 'identify.', self.network) + for cap in msg.args[2].split(' '): - if msg.args[1] == 'ACK': - log.info('%s: Server acknowledged %r capability', + if msg.args[1] == 'LS' and cap in caps: + log.debug('%s: Requesting capability %r', cap) + self.queueMsg(ircmsgs.IrcMsg(command='CAP', args=('REQ', cap))) + elif msg.args[1] == 'ACK': + log.info('%s: Server acknowledged capability %r', self.network, cap) if cap == 'sasl': self.queueMsg(ircmsgs.IrcMsg(command='AUTHENTICATE', args=('PLAIN',))) elif msg.args[1] == 'NAK': - log.warning('%s: Server refused %r capability', + log.warning('%s: Server refused capability %r', self.network, cap) if cap == 'sasl': diff --git a/test/test_irclib.py b/test/test_irclib.py index 190a46557..ebb9fd896 100644 --- a/test/test_irclib.py +++ b/test/test_irclib.py @@ -382,6 +382,8 @@ class IrcTestCase(SupyTestCase): m = self.irc.takeMsg() self.failUnless(m.command == 'NICK', 'Expected NICK, got %r.' % m) m = self.irc.takeMsg() + self.failUnless(m.command == 'CAP', 'Expected NICK, got %r.' % m) + m = self.irc.takeMsg() self.failUnless(m.command == 'USER', 'Expected USER, got %r.' % m) def testPingResponse(self): @@ -478,7 +480,9 @@ class IrcCallbackTestCase(SupyTestCase): conf.supybot.nick.setValue(nick) user = 'user any user' conf.supybot.user.setValue(user) - expected = [ircmsgs.nick(nick), ircmsgs.user('limnoria', user)] + expected = [ircmsgs.nick(nick), + ircmsgs.IrcMsg(command='CAP', args=('LS',)), + ircmsgs.user('limnoria', user)] irc = irclib.Irc('test') msgs = [irc.takeMsg()] while msgs[-1] != None: