make !silence effect min_args and unknown-command

closes #160
This commit is contained in:
jesopo 2019-09-26 11:56:14 +01:00
parent 1b79a74741
commit 4bb20c49dd
2 changed files with 51 additions and 49 deletions

View file

@ -194,57 +194,41 @@ class Module(ModuleManager.BaseModule):
if hook.get_kwarg("remove_empty", True):
args_split = list(filter(None, args_split))
min_args = hook.get_kwarg("min_args")
if min_args and len(args_split) < min_args:
command_prefix = ""
if is_channel:
command_prefix = self._command_prefix(server, target)
usage = self._get_usage(hook, command, command_prefix)
if usage:
stderr.write("Not enough arguments, usage: %s" %
usage).send(command_method)
else:
stderr.write("Not enough arguments (minimum: %d)" %
min_args).send(command_method)
else:
event_kwargs = {"hook": hook, "user": user, "server": server,
"target": target, "is_channel": is_channel, "tags": tags,
"args_split": args_split, "command": command,
"args": " ".join(args_split), "stdout": stdout,
"stderr": stderr}
event_kwargs.update(kwargs)
event_kwargs = {"hook": hook, "user": user, "server": server,
"target": target, "is_channel": is_channel, "tags": tags,
"args_split": args_split, "command": command,
"args": " ".join(args_split), "stdout": stdout,
"stderr": stderr}
event_kwargs.update(kwargs)
check_assert = lambda check: self._check_assert(event_kwargs, check)
event_kwargs["check_assert"] = check_assert
check_assert = lambda check: self._check_assert(event_kwargs, check)
event_kwargs["check_assert"] = check_assert
check_success, check_message = self._check("preprocess",
event_kwargs)
if not check_success:
if check_message:
stderr.write(check_message).send(command_method)
return True
check_success, check_message = self._check("preprocess", event_kwargs)
if not check_success:
if check_message:
stderr.write(check_message).send(command_method)
return True
new_event = self.events.on(hook.event_name).make_event(
**event_kwargs)
new_event = self.events.on(hook.event_name).make_event(**event_kwargs)
self.log.trace("calling command '%s': %s",
[command, new_event.kwargs])
self.log.trace("calling command '%s': %s", [command, new_event.kwargs])
try:
hook.call(new_event)
except utils.EventError as e:
stderr.write(str(e)).send(command_method)
return True
try:
hook.call(new_event)
except utils.EventError as e:
stderr.write(str(e)).send(command_method)
return True
if not hook.get_kwarg("skip_out", False):
has_out = stdout.has_text() or stderr.has_text()
if has_out:
command_method = self._command_method(target, server)
stdout.send(command_method)
stderr.send(command_method)
target.last_stdout = stdout
target.last_stderr = stderr
ret = new_event.eaten
if not hook.get_kwarg("skip_out", False):
has_out = stdout.has_text() or stderr.has_text()
if has_out:
command_method = self._command_method(target, server)
stdout.send(command_method)
stderr.send(command_method)
target.last_stdout = stdout
target.last_stderr = stderr
ret = new_event.eaten
if expect_output and message_tags and not has_out:
server.send(utils.irc.protocol.tagmsg(target_str,
@ -252,6 +236,17 @@ class Module(ModuleManager.BaseModule):
return ret
@utils.hook("preprocess.command")
def _check_min_args(self, event):
min_args = event["hook"].get_kwarg("min_args")
if min_args and len(event["args_split"]) < min_args:
usage = self._get_usage(event["hook"], event["command"],
event["command_prefix"])
if usage:
return "Not enough arguments, usage: %s" % usage
else:
return "Not enough arguments (minimum: %d)" % min_args
def _command_prefix(self, server, channel):
return channel.get_setting("command-prefix",
server.get_setting("command-prefix", "!"))

View file

@ -12,8 +12,11 @@ class Module(ModuleManager.BaseModule):
def _is_silenced(self, target):
silence_until = target.get_setting("silence-until", None)
if silence_until and time.time()<silence_until:
return True
if not silence_until == None:
if time.time()<silence_until:
return True
else:
target.del_setting("silence-until")
return False
@utils.hook("received.command.silence", channel_only=True)
@ -55,5 +58,9 @@ class Module(ModuleManager.BaseModule):
if silence_until:
if self._is_silenced(event["target"]):
return utils.consts.PERMISSION_HARD_FAIL
else:
event["target"].del_setting("silence-until")
@utils.hook("unknown.command")
@utils.kwarg("priority", EventManager.PRIORITY_HIGH)
def unknown_command(self, event):
if event["is_channel"] and self._is_silenced(event["target"]):
event.eat()