From 72145e09b8e812c997730d33d5ddca0701ebee34 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 19 Aug 2017 22:04:24 -0700 Subject: [PATCH] clientbot: implement away-notify support (#290) --- protocols/clientbot.py | 4 +++- protocols/ircs2s_common.py | 30 +++++++++++++++++------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/protocols/clientbot.py b/protocols/clientbot.py index cd8e9eb..771005b 100644 --- a/protocols/clientbot.py +++ b/protocols/clientbot.py @@ -15,7 +15,9 @@ from pylinkirc.protocols.ircs2s_common import * from pylinkirc.classes import * FALLBACK_REALNAME = 'PyLink Relay Mirror Client' -IRCV3_CAPABILITIES = {'multi-prefix', 'sasl'} + +# IRCv3 capabilities to request when available +IRCV3_CAPABILITIES = {'multi-prefix', 'sasl', 'away-notify'} class ClientbotWrapperProtocol(IRCCommonProtocol): def __init__(self, *args, **kwargs): diff --git a/protocols/ircs2s_common.py b/protocols/ircs2s_common.py index 86a434e..277d8bb 100644 --- a/protocols/ircs2s_common.py +++ b/protocols/ircs2s_common.py @@ -176,6 +176,23 @@ class IRCCommonProtocol(IRCNetwork): prefixsearch = re.search(r'\(([A-Za-z]+)\)(.*)', args) return dict(zip(prefixsearch.group(1), prefixsearch.group(2))) + def handle_away(self, source, command, args): + """Handles incoming AWAY messages.""" + # TS6: + # <- :6ELAAAAAB AWAY :Auto-away + # <- :6ELAAAAAB AWAY + # P10: + # <- ABAAA A :blah + # <- ABAAA A + if source not in self.users: + return + + try: + self.users[source].away = text = args[0] + except IndexError: # User is unsetting away status + self.users[source].away = text = '' + return {'text': text} + def handle_error(self, numeric, command, args): """Handles ERROR messages - these mean that our uplink has disconnected us!""" raise ProtocolError('Received an ERROR, disconnecting!') @@ -455,19 +472,6 @@ class IRCS2SProtocol(IRCCommonProtocol): self.channels[target].topicset = True topic_burst = topic - def handle_away(self, numeric, command, args): - """Handles incoming AWAY messages.""" - # TS6: - # <- :6ELAAAAAB AWAY :Auto-away - # P10: - # <- ABAAA A :blah - # <- ABAAA A - try: - self.users[numeric].away = text = args[0] - except IndexError: # User is unsetting away status - self.users[numeric].away = text = '' - return {'text': text} - def handle_invite(self, numeric, command, args): """Handles incoming INVITEs.""" # TS6: