parent
1b79a74741
commit
4bb20c49dd
2 changed files with 51 additions and 49 deletions
|
@ -194,57 +194,41 @@ class Module(ModuleManager.BaseModule):
|
||||||
if hook.get_kwarg("remove_empty", True):
|
if hook.get_kwarg("remove_empty", True):
|
||||||
args_split = list(filter(None, args_split))
|
args_split = list(filter(None, args_split))
|
||||||
|
|
||||||
min_args = hook.get_kwarg("min_args")
|
event_kwargs = {"hook": hook, "user": user, "server": server,
|
||||||
if min_args and len(args_split) < min_args:
|
"target": target, "is_channel": is_channel, "tags": tags,
|
||||||
command_prefix = ""
|
"args_split": args_split, "command": command,
|
||||||
if is_channel:
|
"args": " ".join(args_split), "stdout": stdout,
|
||||||
command_prefix = self._command_prefix(server, target)
|
"stderr": stderr}
|
||||||
usage = self._get_usage(hook, command, command_prefix)
|
event_kwargs.update(kwargs)
|
||||||
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)
|
|
||||||
|
|
||||||
check_assert = lambda check: self._check_assert(event_kwargs, check)
|
check_assert = lambda check: self._check_assert(event_kwargs, check)
|
||||||
event_kwargs["check_assert"] = check_assert
|
event_kwargs["check_assert"] = check_assert
|
||||||
|
|
||||||
check_success, check_message = self._check("preprocess",
|
check_success, check_message = self._check("preprocess", event_kwargs)
|
||||||
event_kwargs)
|
if not check_success:
|
||||||
if not check_success:
|
if check_message:
|
||||||
if check_message:
|
stderr.write(check_message).send(command_method)
|
||||||
stderr.write(check_message).send(command_method)
|
return True
|
||||||
return True
|
|
||||||
|
|
||||||
new_event = self.events.on(hook.event_name).make_event(
|
new_event = self.events.on(hook.event_name).make_event(**event_kwargs)
|
||||||
**event_kwargs)
|
|
||||||
|
|
||||||
self.log.trace("calling command '%s': %s",
|
self.log.trace("calling command '%s': %s", [command, new_event.kwargs])
|
||||||
[command, new_event.kwargs])
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
hook.call(new_event)
|
hook.call(new_event)
|
||||||
except utils.EventError as e:
|
except utils.EventError as e:
|
||||||
stderr.write(str(e)).send(command_method)
|
stderr.write(str(e)).send(command_method)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if not hook.get_kwarg("skip_out", False):
|
if not hook.get_kwarg("skip_out", False):
|
||||||
has_out = stdout.has_text() or stderr.has_text()
|
has_out = stdout.has_text() or stderr.has_text()
|
||||||
if has_out:
|
if has_out:
|
||||||
command_method = self._command_method(target, server)
|
command_method = self._command_method(target, server)
|
||||||
stdout.send(command_method)
|
stdout.send(command_method)
|
||||||
stderr.send(command_method)
|
stderr.send(command_method)
|
||||||
target.last_stdout = stdout
|
target.last_stdout = stdout
|
||||||
target.last_stderr = stderr
|
target.last_stderr = stderr
|
||||||
ret = new_event.eaten
|
ret = new_event.eaten
|
||||||
|
|
||||||
if expect_output and message_tags and not has_out:
|
if expect_output and message_tags and not has_out:
|
||||||
server.send(utils.irc.protocol.tagmsg(target_str,
|
server.send(utils.irc.protocol.tagmsg(target_str,
|
||||||
|
@ -252,6 +236,17 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
return ret
|
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):
|
def _command_prefix(self, server, channel):
|
||||||
return channel.get_setting("command-prefix",
|
return channel.get_setting("command-prefix",
|
||||||
server.get_setting("command-prefix", "!"))
|
server.get_setting("command-prefix", "!"))
|
||||||
|
|
|
@ -12,8 +12,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
def _is_silenced(self, target):
|
def _is_silenced(self, target):
|
||||||
silence_until = target.get_setting("silence-until", None)
|
silence_until = target.get_setting("silence-until", None)
|
||||||
if silence_until and time.time()<silence_until:
|
if not silence_until == None:
|
||||||
return True
|
if time.time()<silence_until:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
target.del_setting("silence-until")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@utils.hook("received.command.silence", channel_only=True)
|
@utils.hook("received.command.silence", channel_only=True)
|
||||||
|
@ -55,5 +58,9 @@ class Module(ModuleManager.BaseModule):
|
||||||
if silence_until:
|
if silence_until:
|
||||||
if self._is_silenced(event["target"]):
|
if self._is_silenced(event["target"]):
|
||||||
return utils.consts.PERMISSION_HARD_FAIL
|
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()
|
||||||
|
|
Loading…
Reference in a new issue