3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-24 03:29:28 +01:00

clientbot: move services account setting bits into a shared function

This commit is contained in:
James Lu 2017-08-23 19:16:20 -07:00
parent c2fc9080cc
commit c9f10796ee

View File

@ -390,6 +390,18 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
return results
return {}
def _set_account_name(self, uid, account):
"""
Updates the user's account metadata.
"""
if account is None: # Ignore when account=None
return
elif account == '*': # This indicates logout
account = ''
if account != self.users[uid].services_account:
self.call_hooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': account}])
def handle_events(self, data):
"""Event handler for the RFC1459/2812 (clientbot) protocol."""
data = data.split(" ")
@ -432,9 +444,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
if idsource in self.users:
# Handle IRCv3.2 account-tag.
account_tag = tags.get('account')
if account_tag is not None and account_tag != self.users[idsource].services_account:
self.call_hooks([idsource, 'CLIENT_SERVICES_LOGIN', {'text': account_tag}])
self._set_account_name(idsource, tags.get('account'))
try:
func = getattr(self, 'handle_'+command.lower())
@ -744,10 +754,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
account = args[7]
log.debug('(%s) handle_354: got account %r for %s', self.name, account, uid)
if account == '*': # Indicates no account
account = ''
if account != self.users[uid].services_account:
self.call_hooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': account}])
self._set_account_name(uid, account)
if self.serverdata.get('track_oper_statuses'):
if '*' in status: # Track IRCop status
@ -815,12 +822,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
# <- :nick!user@host ACCOUNT accountname
# <- :nick!user@host ACCOUNT *
account = args[0]
if account == '*': # Logout
account = ''
if account != self.users[source].services_account:
return {'text': account}
self._set_account_name(source, args[0])
def handle_join(self, source, command, args):
"""