3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-01-11 20:52:42 +01:00

Move handle_mode into IRCS2SProtocol

TODO: clean up protocols/unreal to use more of this code as well
This commit is contained in:
James Lu 2017-07-06 17:10:03 -07:00
parent faa5b729d9
commit 45dad63d5b
5 changed files with 39 additions and 51 deletions

View File

@ -615,17 +615,6 @@ class InspIRCdProtocol(TS6BaseProtocol):
return {'target': channel, 'modes': changedmodes, 'ts': ts,
'channeldata': oldobj}
def handle_mode(self, numeric, command, args):
"""Handles incoming user mode changes."""
# In InspIRCd, MODE is used for setting user modes and
# FMODE is used for channel modes:
# <- :70MAAAAAA MODE 70MAAAAAA -i+xc
target = args[0]
modestrings = args[1:]
changedmodes = self.parse_modes(target, modestrings)
self.apply_modes(target, changedmodes)
return {'target': target, 'modes': changedmodes}
def handle_idle(self, numeric, command, args):
"""
Handles the IDLE command, sent between servers in remote WHOIS queries.

View File

@ -548,6 +548,40 @@ class IRCS2SProtocol(IRCCommonProtocol):
return {'target': killed, 'text': killmsg, 'userdata': data}
def _check_cloak_change(self, uid):
return
def handle_mode(self, source, command, args):
"""Handles mode changes."""
# InspIRCd:
# <- :70MAAAAAA MODE 70MAAAAAA -i+xc
# P10:
# <- ABAAA M GL -w
# <- ABAAA M #test +v ABAAB 1460747615
# <- ABAAA OM #test +h ABAAA
target = self._get_UID(args[0])
if utils.isChannel(target):
target = self.to_lower(target)
channeldata = self.channels[target].deepcopy()
else:
channeldata = None
modestrings = args[1:]
changedmodes = self.parse_modes(target, modestrings)
self.apply_modes(target, changedmodes)
# Call the CLIENT_OPERED hook if +o is being set.
# TODO: handle umodes for admin, servprotect, etc. and set the oper type accordingly.
if ('+o', None) in changedmodes and target in self.users:
self.call_hooks([target, 'CLIENT_OPERED', {'text': 'IRC Operator'}])
if target in self.users:
# Target was a user. Check for any cloak changes.
self._check_cloak_change(target)
return {'target': target, 'modes': changedmodes, 'channeldata': channeldata}
def handle_part(self, source, command, args):
"""Handles incoming PART commands."""
channels = self.to_lower(args[0]).split(',')

View File

@ -164,6 +164,9 @@ class P10Protocol(IRCS2SProtocol):
self.protocol_caps |= {'slash-in-hosts', 'underscore-in-hosts'}
# OPMODE is like SAMODE on other IRCds, and it follows the same modesetting syntax.
self.handle_opmode = self.handle_mode
def _send_with_prefix(self, source, text, **kwargs):
self.send("%s %s" % (source, text), **kwargs)
@ -1111,31 +1114,6 @@ class P10Protocol(IRCS2SProtocol):
self._send_with_prefix(self.sid, 'EA')
return {}
def handle_mode(self, source, command, args):
"""Handles mode changes."""
# <- ABAAA M GL -w
# <- ABAAA M #test +v ABAAB 1460747615
# <- ABAAA OM #test +h ABAAA
target = self._get_UID(args[0])
if utils.isChannel(target):
target = self.to_lower(target)
modestrings = args[1:]
changedmodes = self.parse_modes(target, modestrings)
self.apply_modes(target, changedmodes)
# Call the CLIENT_OPERED hook if +o is being set.
if ('+o', None) in changedmodes and target in self.users:
self.call_hooks([target, 'CLIENT_OPERED', {'text': 'IRC Operator'}])
if target in self.users:
# Target was a user. Check for any cloak changes.
self._check_cloak_change(target)
return {'target': target, 'modes': changedmodes}
# OPMODE is like SAMODE on other IRCds, and it follows the same modesetting syntax.
handle_opmode = handle_mode
def handle_kick(self, source, command, args):
"""Handles incoming KICKs."""
# <- ABAAA K #TEST AyAAA :PyLink-devel

View File

@ -585,19 +585,6 @@ class TS6Protocol(TS6BaseProtocol):
return {'target': channel, 'modes': changedmodes, 'ts': ts,
'channeldata': oldobj}
def handle_mode(self, numeric, command, args):
"""Handles incoming user mode changes."""
# <- :70MAAAAAA MODE 70MAAAAAA -i+xc
target = args[0]
modestrings = args[1:]
changedmodes = self.parse_modes(target, modestrings)
self.apply_modes(target, changedmodes)
# Call the OPERED UP hook if +o is being set.
if ('+o', None) in changedmodes:
otype = 'Server Administrator' if ('a', None) in self.users[target].modes else 'IRC Operator'
self.call_hooks([target, 'CLIENT_OPERED', {'text': otype}])
return {'target': target, 'modes': changedmodes}
def handle_tb(self, numeric, command, args):
"""Handles incoming topic burst (TB) commands."""
# <- :42X TB #chat 1467427448 GL!~gl@127.0.0.1 :test

View File

@ -703,8 +703,8 @@ class UnrealProtocol(TS6BaseProtocol):
self.updateTS(numeric, channel, their_ts)
return {'target': channel, 'modes': parsedmodes, 'channeldata': oldobj}
else:
# User mode change: pass those on to handle_umode2()
self.handle_umode2(numeric, 'MODE', args[1:])
# User mode change: pass those on to IRCS2SProtocol's handle_mode()
super().handle_mode(numeric, 'MODE', args)
def _check_cloak_change(self, uid, parsedmodes):
"""