add an optional mask pattern arg to !clear

This commit is contained in:
jesopo 2020-01-22 15:00:59 +00:00
parent 463ce89fba
commit ade5cbb1f3
2 changed files with 10 additions and 5 deletions

View file

@ -454,14 +454,19 @@ class Module(ModuleManager.BaseModule):
@utils.kwarg("require_mode", "o")
@utils.kwarg("require_access", "clear")
@utils.kwarg("help", "Clear a given channel list mode (e.g. +b)")
@utils.kwarg("usage", "+<mode>")
@utils.kwarg("usage", "+<mode> [mask]")
def clear(self, event):
type = event["args_split"][0]
if type[0] == "+" and type[1:]:
mode = type[1]
if mode in event["target"].mode_lists:
chunks = self._chunk(
event["server"], list(event["target"].mode_lists[mode]))
mode_list = event["target"].mode_lists[mode]
if len(event["args_split"]) > 1:
hostmask = utils.irc.hostmask_parse(event["args_split"][1])
mode_list = list(utils.irc.hostmask_match_many(
mode_list, hostmask))
chunks = self._chunk(event["server"], list(mode_list))
for chunk in chunks:
event["target"].send_mode("-%s" % mode*len(chunk), chunk)
else:

View file

@ -287,8 +287,8 @@ def hostmask_match_many(hostmasks: typing.List[str], pattern: HostmaskPattern,
) -> typing.Optional[str]:
for hostmask in hostmasks:
if pattern.match(hostmask):
return hostmask
yield hostmask
return None
def hostmask_match(hostmask: str, pattern: HostmaskPattern) -> bool:
return not hostmask_match_many([hostmask], pattern) == None
return any(hostmask_match_many([hostmask], pattern))