3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-01-12 05:02:33 +01:00

protocols: handle usermode-based away (i.e. ngircd +a)

This commit is contained in:
James Lu 2017-07-06 20:19:52 -07:00
parent b2b50371ab
commit 085b4cacbe
2 changed files with 33 additions and 1 deletions

View File

@ -551,6 +551,19 @@ class IRCS2SProtocol(IRCCommonProtocol):
def _check_cloak_change(self, uid):
return
def _check_umode_away_change(self, uid):
# Handle away status changes based on umode +a
awaymode = self.umodes.get('away')
if uid in self.users and awaymode:
u = self.users[uid]
old_away_status = u.away
# Check whether the user is marked away, and send a hook update only if the status has changed.
away_status = (awaymode, None) in u.modes
if away_status != old_away_status:
# This sets a dummy away reason of "Away" because no actual text is provided.
self.call_hooks([uid, 'AWAY', {'text': 'Away'}])
def handle_mode(self, source, command, args):
"""Handles mode changes."""
# InspIRCd:
@ -577,8 +590,9 @@ class IRCS2SProtocol(IRCCommonProtocol):
self.call_hooks([target, 'CLIENT_OPERED', {'text': 'IRC Operator'}])
if target in self.users:
# Target was a user. Check for any cloak changes.
# Target was a user. Check for any cloak and away status changes.
self._check_cloak_change(target)
self._check_umode_away_change(target)
return {'target': target, 'modes': changedmodes, 'channeldata': channeldata}

View File

@ -128,6 +128,21 @@ class NgIRCdProtocol(IRCS2SProtocol):
self.servers[sid] = Server(uplink, name, internal=True, desc=desc)
return sid
def away(self, source, text):
"""Sends an AWAY message from a PyLink client. If the text is empty, away status is unset."""
if not self.is_internal_client(source):
raise LookupError('No such PyLink client exists.')
# Away status is denoted on ngIRCd with umode +a.
modes = self.users[source].modes
if text and (('a', None) not in modes):
# Set umode +a if it isn't already set
self.mode(source, source, [('+a', None)])
elif ('a', None) in modes:
# Ditto, only unset the mode if it *was* set.
self.mode(source, source, [('-a', None)])
self.users[source].away = text
def join(self, client, channel):
channel = self.to_lower(channel)
@ -325,6 +340,9 @@ class NgIRCdProtocol(IRCS2SProtocol):
# Add the nick to the list of users on its server; this is used for SQUIT tracking
self.servers[source].users.add(uid)
# Check away status changes (TODO: implement cloak handling too)
self._check_umode_away_change(uid)
return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': host, 'host': host, 'ident': ident,
'parse_as': 'UID', 'ip': '0.0.0.0'}
else: