add !lsearch to show what !clear would remove
This commit is contained in:
parent
32f047c10e
commit
ecfab16fc4
1 changed files with 55 additions and 34 deletions
|
@ -403,12 +403,46 @@ class Module(ModuleManager.BaseModule):
|
||||||
def _cunmute(self, channel):
|
def _cunmute(self, channel):
|
||||||
channel.send_mode("-m")
|
channel.send_mode("-m")
|
||||||
|
|
||||||
def _filter_mask(self, mask, list):
|
def _filter_mask(self, mask, mode_list):
|
||||||
parsed_mask = utils.irc.hostmask_parse(mask)
|
parsed_mask = utils.irc.hostmask_parse(mask)
|
||||||
return list(utils.irc.hostmask_match_many(list, parsed_mask))
|
return list(utils.irc.hostmask_match_many(mode_list, parsed_mask))
|
||||||
def _filter_prefix(self, prefix, list):
|
def _filter_prefix(self, prefix, list):
|
||||||
return [l for l in list if prefix in l]
|
return [l for l in list if prefix in l]
|
||||||
|
|
||||||
|
def _type_to_mode(self, server, channel, type):
|
||||||
|
if type[0] == "+":
|
||||||
|
if type[1:]:
|
||||||
|
if type[1] in channel.mode_lists:
|
||||||
|
return type[1], None
|
||||||
|
else:
|
||||||
|
raise utils.EventError("Unknown list mode")
|
||||||
|
else:
|
||||||
|
raise utils.EventError("Please provide a list mode")
|
||||||
|
elif type in ["quiets", "mutes"]:
|
||||||
|
quiet_method = self._quiet_method(server)
|
||||||
|
if quiet_method:
|
||||||
|
return quiet_method[0], quiet_method[1]
|
||||||
|
else:
|
||||||
|
raise utils.EventError(NO_QUIETS)
|
||||||
|
else:
|
||||||
|
raise utils.EventError("Unknown type '%s'" % type)
|
||||||
|
|
||||||
|
def _list_query_event(self, server, channel, args):
|
||||||
|
list_type = args[0]
|
||||||
|
list_mode, list_prefix = self._type_to_mode(server, channel, list_type)
|
||||||
|
|
||||||
|
list_mask = None
|
||||||
|
if len(args) > 1:
|
||||||
|
list_mask = args[1]
|
||||||
|
|
||||||
|
mode_list = list(channel.mode_lists[list_mode])
|
||||||
|
if list_prefix:
|
||||||
|
mode_list = self._filter_prefix(list_prefix, mode_list)
|
||||||
|
if list_mask:
|
||||||
|
mode_list = self._filter_mask(list_mask, mode_list)
|
||||||
|
|
||||||
|
return list_mode, mode_list
|
||||||
|
|
||||||
@utils.hook("received.command.clear")
|
@utils.hook("received.command.clear")
|
||||||
@utils.kwarg("channel_only", True)
|
@utils.kwarg("channel_only", True)
|
||||||
@utils.kwarg("require_mode", "o")
|
@utils.kwarg("require_mode", "o")
|
||||||
|
@ -417,39 +451,26 @@ class Module(ModuleManager.BaseModule):
|
||||||
@utils.kwarg("usage", "<type> [mask]")
|
@utils.kwarg("usage", "<type> [mask]")
|
||||||
@utils.kwarg("usage", "+<mode> [mask]")
|
@utils.kwarg("usage", "+<mode> [mask]")
|
||||||
def clear(self, event):
|
def clear(self, event):
|
||||||
list_type = event["args_split"][0]
|
mode, mode_list = self._list_query_event(
|
||||||
list_mode = None
|
event["server"], event["target"], event["args_split"])
|
||||||
list_filter = lambda l: list(l)
|
|
||||||
|
|
||||||
if list_type[0] == "+":
|
chunks = self._chunk(event["server"], mode_list)
|
||||||
if list_type[1:]:
|
for chunk in chunks:
|
||||||
list_mode = list_type[1]
|
event["target"].send_mode("-%s" % mode*len(chunk), chunk)
|
||||||
else:
|
|
||||||
raise utils.EventError("Please provide a list mode")
|
|
||||||
|
|
||||||
elif list_type in ["quiets", "mutes"]:
|
@utils.hook("received.command.lsearch")
|
||||||
quiet_method = self._quiet_method(event["server"])
|
@utils.kwarg("channel_only", True)
|
||||||
if quiet_method:
|
@utils.kwarg("require_mode", "o")
|
||||||
list_mode = quiet_method[0]
|
@utils.kwarg("require_access", "lsearch")
|
||||||
if quiet_method[1]:
|
@utils.kwarg("help", "Search a given channel list mode (e.g. +b)")
|
||||||
list_filter = lambda list: self._filter_prefix(
|
@utils.kwarg("usage", "<type> [mask]")
|
||||||
quiet_method[1], list)
|
@utils.kwarg("usage", "+<mode> [mask]")
|
||||||
else:
|
def lsearch(self, event):
|
||||||
raise utils.EventError(NO_QUIETS)
|
mode, mode_list = self._list_query_event(
|
||||||
|
event["server"], event["target"], event["args_split"])
|
||||||
|
|
||||||
|
if mode_list:
|
||||||
|
event["stdout"].write("%s: %s" %
|
||||||
|
(event["user"].nickname, " ".join(mode_list)))
|
||||||
else:
|
else:
|
||||||
raise utils.EventError("Unknown type '%s'" % type)
|
event["stderr"].write("%s: no matches" % event["user"].nickname)
|
||||||
|
|
||||||
if list_mode in event["target"].mode_lists:
|
|
||||||
if len(event["args_split"]) > 1:
|
|
||||||
old_filter = list_filter
|
|
||||||
list_filter = lambda list: self._filter_mask(
|
|
||||||
event["args_split"][1], old_filter(list))
|
|
||||||
|
|
||||||
mode_list = list_filter(event["target"].mode_lists[list_mode])
|
|
||||||
|
|
||||||
chunks = self._chunk(event["server"], mode_list)
|
|
||||||
for chunk in chunks:
|
|
||||||
event["target"].send_mode("-%s" % list_mode*len(chunk), chunk)
|
|
||||||
else:
|
|
||||||
raise utils.EventError("Unknown list mode")
|
|
||||||
|
|
Loading…
Reference in a new issue