correctly support INVEX and EXCEPTS lists

This commit is contained in:
jesopo 2020-01-22 17:58:12 +00:00
parent 811b85d0f9
commit 2a33b25930

View file

@ -4,28 +4,55 @@ class Module(ModuleManager.BaseModule):
# RPL_BANLIST # RPL_BANLIST
@utils.hook("received.367") @utils.hook("received.367")
def on_367(self, event): def on_367(self, event):
self._mode_list_mask(event["server"], event["line"].args[1], "b", self._mode_list_mask(event, "b", event["line"].args[2])
event["line"].args[2])
@utils.hook("received.368") @utils.hook("received.368")
def on_368(self, event): def on_368(self, event):
self._mode_list_end(event["server"], event["line"].args[1], "b") self._mode_list_end(event, "b")
# RPL_QUIETLIST # RPL_QUIETLIST
@utils.hook("received.728") @utils.hook("received.728")
def on_728(self, event): def on_728(self, event):
self._mode_list_mask(event["server"], event["line"].args[1], "q", self._mode_list_mask(event, "q", event["line"].args[3])
event["line"].args[3])
@utils.hook("received.729") @utils.hook("received.729")
def on_729(self, event): def on_729(self, event):
self._mode_list_end(event["server"], event["line"].args[1], "q") self._mode_list_end(event, "q")
def _mode_list_mask(self, server, target, mode, mask):
if target in server.channels: def _excepts(self, server):
channel = server.channels.get(target) return server.isupport.get("EXCEPTS", None) or "e"
self._mask_add(channel, "~%s " % mode, mask) # RPL_EXCEPTLIST
def _mode_list_end(self, server, target, mode): @utils.hook("received.348")
if target in server.channels: def on_348(self, event):
channel = server.channels.get(target) mode = self._excepts(event["server"])
self._mode_list_mask(event, mode, event["line"].args[3])
@utils.hook("received.349")
def on_349(self, event):
self._mode_list_end(event, self._excepts(event["server"]))
def _invex(self, server):
return server.isupport.get("INVEX", None) or "I"
# RPL_INVITELIST
@utils.hook("received.346")
def on_346(self, event):
mode = self._invex(event["server"])
self._mode_list_mask(event, mode, event["line"].args[3])
@utils.hook("received.347")
def on_347(self, event):
self._mode_list_end(event, self._invex(event["server"]))
def _channel(self, event):
target = event["line"].args[1]
if target in event["server"].channels:
return event["server"].channels.get(target)
return None
def _mode_list_mask(self, event, mode, mask):
channel = self._channel(event)
if channel:
self._mask_add(channel, "~%s" % mode, mask)
def _mode_list_end(self, event, mode):
channel = self._channel(event)
if channel:
temp_key = "~%s" % mode temp_key = "~%s" % mode
if temp_key in channel.mode_lists: if temp_key in channel.mode_lists:
channel.mode_lists[mode] = channel.mode_lists.pop(temp_key) channel.mode_lists[mode] = channel.mode_lists.pop(temp_key)