NickAuth: Add support for account-tag (not tested).

This commit is contained in:
Valentin Lorentz 2015-05-15 20:46:18 +02:00
parent 259457ae2f
commit b405f998a5
3 changed files with 24 additions and 26 deletions

View File

@ -147,6 +147,13 @@ class NickAuth(callbacks.Plugin):
irc.queueMsg(ircmsgs.whois(nick, nick)) irc.queueMsg(ircmsgs.whois(nick, nick))
auth = wrap(auth, []) auth = wrap(auth, [])
def inFilter(self, irc, msg):
"""If the messages has a server tag with account name, tries to
authenticate it."""
if msg.server_tags and 'account' in msg.server_tags:
self._auth(irc, msg.prefix, msg.server_tags['account'])
return msg
def do330(self, irc, msg): def do330(self, irc, msg):
mynick, theirnick, theiraccount, garbage = msg.args mynick, theirnick, theiraccount, garbage = msg.args
# I would like to use a dict comprehension, but we have to support # I would like to use a dict comprehension, but we have to support
@ -176,18 +183,8 @@ class NickAuth(callbacks.Plugin):
account = msg.args[0] account = msg.args[0]
user = ircdb.users.getUserFromNick(irc.network, account) user = ircdb.users.getUserFromNick(irc.network, account)
if not user: if account != '*':
try: self._auth(irc, msg.prefix, account)
user = ircdb.users.getUser(msg.prefix)
except KeyError:
user = None
if user:
if account == '*':
user.clearAuth()
else:
user.addAuth(msg.prefix)
ircdb.users.setUser(user, flush=False)
def doJoin(self, irc, msg): def doJoin(self, irc, msg):
@ -196,18 +193,8 @@ class NickAuth(callbacks.Plugin):
return return
account = msg.args[1] account = msg.args[1]
user = ircdb.users.getUserFromNick(irc.network, account)
if not user:
try:
user = ircdb.users.getUser(msg.prefix)
except KeyError:
user = None
if user:
if account != '*': if account != '*':
user.addAuth(msg.prefix) self._auth(irc, msg.prefix, account)
ircdb.users.setUser(user, flush=False)
def do354(self, irc, msg): def do354(self, irc, msg):
if len(msg.args) != 6 or msg.args[1] != '1': if len(msg.args) != 6 or msg.args[1] != '1':
@ -217,6 +204,12 @@ class NickAuth(callbacks.Plugin):
prefix = '%s!%s@%s' % (nick, ident, host) prefix = '%s!%s@%s' % (nick, ident, host)
user = ircdb.users.getUserFromNick(irc.network, account) user = ircdb.users.getUserFromNick(irc.network, account)
if account != '0':
self._auth(irc, prefix, account)
def _auth(self, irc, prefix, account):
user = ircdb.users.getUserFromNick(irc.network, account)
if not user: if not user:
try: try:
user = ircdb.users.getUser(prefix) user = ircdb.users.getUser(prefix)
@ -224,7 +217,6 @@ class NickAuth(callbacks.Plugin):
user = None user = None
if user: if user:
if account != '0':
user.addAuth(prefix) user.addAuth(prefix)
ircdb.users.setUser(user, flush=False) ircdb.users.setUser(user, flush=False)

View File

@ -967,7 +967,7 @@ class Irc(IrcCommandDispatcher):
self.sasl = 'plain' self.sasl = 'plain'
for cap in ('account-notify', 'extended-join', 'multi-prefix', for cap in ('account-notify', 'extended-join', 'multi-prefix',
'metadata-notify'): 'metadata-notify', 'account-tag'):
self.queueMsg(ircmsgs.IrcMsg(command='CAP', args=('REQ', cap))) self.queueMsg(ircmsgs.IrcMsg(command='CAP', args=('REQ', cap)))
if self.sasl: if self.sasl:

View File

@ -391,6 +391,10 @@ class IrcTestCase(SupyTestCase):
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'CAP', 'Expected CAP, got %r.' % m) self.failUnless(m.command == 'CAP', 'Expected CAP, got %r.' % m)
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'CAP', 'Expected CAP, got %r.' % m)
m = self.irc.takeMsg()
self.failUnless(m.command == 'CAP', 'Expected CAP, got %r.' % m)
m = self.irc.takeMsg()
self.failUnless(m.command == 'USER', 'Expected USER, got %r.' % m) self.failUnless(m.command == 'USER', 'Expected USER, got %r.' % m)
def testPingResponse(self): def testPingResponse(self):
@ -492,6 +496,8 @@ class IrcCallbackTestCase(SupyTestCase):
ircmsgs.IrcMsg(command='CAP', args=('REQ', 'account-notify')), ircmsgs.IrcMsg(command='CAP', args=('REQ', 'account-notify')),
ircmsgs.IrcMsg(command='CAP', args=('REQ', 'extended-join')), ircmsgs.IrcMsg(command='CAP', args=('REQ', 'extended-join')),
ircmsgs.IrcMsg(command='CAP', args=('REQ', 'multi-prefix')), ircmsgs.IrcMsg(command='CAP', args=('REQ', 'multi-prefix')),
ircmsgs.IrcMsg(command='CAP', args=('REQ', 'metadata-notify')),
ircmsgs.IrcMsg(command='CAP', args=('REQ', 'account-tag')),
ircmsgs.IrcMsg(command='CAP', args=('END',)), ircmsgs.IrcMsg(command='CAP', args=('END',)),
ircmsgs.user('limnoria', user) ircmsgs.user('limnoria', user)
] ]