2017-10-27 12:15:33 +00:00
|
|
|
import re
|
2018-10-03 12:22:37 +00:00
|
|
|
from src import EventManager, ModuleManager, utils
|
2016-03-30 18:31:23 +00:00
|
|
|
|
2018-11-13 16:02:26 +00:00
|
|
|
STR_MORE = "%s (more...)" % utils.consts.RESET
|
2016-03-29 11:56:58 +00:00
|
|
|
STR_CONTINUED = "(...continued) "
|
|
|
|
|
2018-10-02 20:40:34 +00:00
|
|
|
COMMAND_METHOD = "command-method"
|
|
|
|
COMMAND_METHODS = ["PRIVMSG", "NOTICE"]
|
|
|
|
|
2016-03-29 11:56:58 +00:00
|
|
|
OUT_CUTOFF = 400
|
|
|
|
|
2018-12-22 00:49:00 +00:00
|
|
|
REGEX_CUTOFF = re.compile(r"^.{1,%d}(?:\s|$)" % OUT_CUTOFF)
|
2018-12-22 01:00:38 +00:00
|
|
|
REGEX_ARG_NUMBER = re.compile(r"\$(\d+)")
|
2017-10-27 12:15:33 +00:00
|
|
|
|
2016-03-29 15:22:22 +00:00
|
|
|
class Out(object):
|
2018-10-02 20:40:34 +00:00
|
|
|
def __init__(self, server, module_name, target, msgid):
|
|
|
|
self.server = server
|
2016-03-29 11:56:58 +00:00
|
|
|
self.module_name = module_name
|
2018-11-07 11:27:10 +00:00
|
|
|
self._hide_prefix = False
|
2016-03-29 15:22:22 +00:00
|
|
|
self.target = target
|
2016-03-29 11:56:58 +00:00
|
|
|
self._text = ""
|
|
|
|
self.written = False
|
2018-10-01 16:52:04 +00:00
|
|
|
self._msgid = msgid
|
2018-10-01 16:26:31 +00:00
|
|
|
|
2016-03-29 11:56:58 +00:00
|
|
|
def write(self, text):
|
|
|
|
self._text += text
|
|
|
|
self.written = True
|
|
|
|
return self
|
2018-10-01 16:26:31 +00:00
|
|
|
|
2019-01-23 20:35:28 +00:00
|
|
|
def send(self, method):
|
2016-03-29 11:56:58 +00:00
|
|
|
if self.has_text():
|
2018-07-14 08:50:12 +00:00
|
|
|
text = self._text
|
2016-03-29 11:56:58 +00:00
|
|
|
text_encoded = text.encode("utf8")
|
|
|
|
if len(text_encoded) > OUT_CUTOFF:
|
|
|
|
text = "%s%s" % (text_encoded[:OUT_CUTOFF].decode("utf8"
|
|
|
|
).rstrip(), STR_MORE)
|
|
|
|
self._text = "%s%s" % (STR_CONTINUED, text_encoded[OUT_CUTOFF:
|
|
|
|
].decode("utf8").lstrip())
|
2018-08-05 19:43:52 +00:00
|
|
|
else:
|
|
|
|
self._text = ""
|
2018-10-01 16:26:31 +00:00
|
|
|
|
|
|
|
tags = {}
|
|
|
|
if self._msgid:
|
2018-10-01 16:28:45 +00:00
|
|
|
tags["+draft/reply"] = self._msgid
|
2018-10-01 16:26:31 +00:00
|
|
|
|
2018-11-07 11:27:10 +00:00
|
|
|
prefix = ""
|
|
|
|
if not self._hide_prefix:
|
2018-11-13 16:02:26 +00:00
|
|
|
prefix = utils.consts.RESET + "[%s] " % self.prefix()
|
2018-11-07 11:27:10 +00:00
|
|
|
|
2018-10-02 20:40:34 +00:00
|
|
|
if method == "PRIVMSG":
|
|
|
|
self.target.send_message(text, prefix=prefix, tags=tags)
|
|
|
|
elif method == "NOTICE":
|
|
|
|
self.target.send_notice(text, prefix=prefix, tags=tags)
|
|
|
|
|
2016-03-29 11:56:58 +00:00
|
|
|
def set_prefix(self, prefix):
|
|
|
|
self.module_name = prefix
|
2018-11-07 11:27:10 +00:00
|
|
|
def hide_prefix(self):
|
|
|
|
self._hide_prefix = True
|
2018-10-01 16:26:31 +00:00
|
|
|
|
2016-03-29 11:56:58 +00:00
|
|
|
def has_text(self):
|
|
|
|
return bool(self._text)
|
|
|
|
|
2016-03-29 15:22:22 +00:00
|
|
|
class StdOut(Out):
|
2016-03-29 11:56:58 +00:00
|
|
|
def prefix(self):
|
2019-01-17 21:10:12 +00:00
|
|
|
return utils.irc.color(self.module_name, utils.consts.GREEN)
|
2016-03-29 15:22:22 +00:00
|
|
|
class StdErr(Out):
|
2016-03-29 11:56:58 +00:00
|
|
|
def prefix(self):
|
2019-01-11 20:57:52 +00:00
|
|
|
return utils.irc.color("!"+self.module_name, utils.consts.RED)
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2018-10-02 20:40:34 +00:00
|
|
|
def _command_method_validate(s):
|
|
|
|
if s.upper() in COMMAND_METHODS:
|
|
|
|
return s.upper()
|
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.export("channelset", {"setting": "command-prefix",
|
2018-09-27 11:08:07 +00:00
|
|
|
"help": "Set the command prefix used in this channel"})
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.export("serverset", {"setting": "command-prefix",
|
2018-09-27 11:08:07 +00:00
|
|
|
"help": "Set the command prefix used on this server"})
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.export("serverset", {"setting": "command-method",
|
2018-10-02 20:40:34 +00:00
|
|
|
"help": "Set the method used to respond to commands",
|
|
|
|
"validate": _command_method_validate})
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.export("channelset", {"setting": "command-method",
|
2018-10-02 20:40:34 +00:00
|
|
|
"help": "Set the method used to respond to commands",
|
|
|
|
"validate": _command_method_validate})
|
2018-11-07 11:27:10 +00:00
|
|
|
@utils.export("channelset", {"setting": "hide-prefix",
|
|
|
|
"help": "Disable/enable hiding prefix in command reponses",
|
|
|
|
"validate": utils.bool_or_none})
|
2018-11-12 22:55:40 +00:00
|
|
|
@utils.export("channelset", {"setting": "commands",
|
|
|
|
"help": "Disable/enable responding to commands in-channel",
|
|
|
|
"validate": utils.bool_or_none})
|
2018-11-12 23:00:51 +00:00
|
|
|
@utils.export("channelset", {"setting": "prefixed-commands",
|
|
|
|
"help": "Disable/enable responding to prefixed commands in-channel",
|
|
|
|
"validate": utils.bool_or_none})
|
2018-09-27 11:08:07 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("new.user|channel")
|
2016-03-29 11:56:58 +00:00
|
|
|
def new(self, event):
|
|
|
|
if "user" in event:
|
|
|
|
target = event["user"]
|
|
|
|
else:
|
|
|
|
target = event["channel"]
|
|
|
|
target.last_stdout = None
|
|
|
|
target.last_stderr = None
|
|
|
|
|
|
|
|
def has_command(self, command):
|
2018-08-31 11:55:52 +00:00
|
|
|
return command.lower() in self.events.on("received").on(
|
2016-03-29 11:56:58 +00:00
|
|
|
"command").get_children()
|
|
|
|
def get_hook(self, command):
|
2018-09-19 12:25:12 +00:00
|
|
|
return self.events.on("received.command").on(command
|
2016-03-29 11:56:58 +00:00
|
|
|
).get_hooks()[0]
|
|
|
|
|
2016-03-30 11:49:46 +00:00
|
|
|
def is_highlight(self, server, s):
|
2018-09-18 23:44:04 +00:00
|
|
|
if s and s[-1] in [":", ","]:
|
2018-09-17 10:31:29 +00:00
|
|
|
s = s[:-1]
|
|
|
|
return server.is_own_nickname(s)
|
2016-03-30 11:49:46 +00:00
|
|
|
|
2018-12-22 01:00:38 +00:00
|
|
|
def _get_aliases(self, server):
|
|
|
|
return server.get_setting("command-aliases", {})
|
|
|
|
def _set_aliases(self, server, aliases):
|
|
|
|
server.set_setting("command-aliases", aliases)
|
|
|
|
|
2019-01-23 20:35:28 +00:00
|
|
|
def _command_method(self, target, server):
|
|
|
|
return target.get_setting(COMMAND_METHOD,
|
|
|
|
server.get_setting(COMMAND_METHOD, "PRIVMSG")).upper()
|
|
|
|
|
2016-03-30 11:49:46 +00:00
|
|
|
def message(self, event, command, args_index=1):
|
2018-12-22 01:00:38 +00:00
|
|
|
args_split = event["message_split"][args_index:]
|
|
|
|
if not self.has_command(command):
|
|
|
|
aliases = self._get_aliases(event["server"])
|
|
|
|
if command.lower() in aliases:
|
2018-12-22 01:01:25 +00:00
|
|
|
command, _, new_args = aliases[command.lower()].partition(" ")
|
2018-12-22 01:00:38 +00:00
|
|
|
for match in REGEX_ARG_NUMBER.finditer(new_args):
|
|
|
|
index = int(match.group(1))
|
|
|
|
if index >= len(args_split):
|
|
|
|
return
|
|
|
|
new_args = new_args.replace(match.group(0),
|
|
|
|
args_split[index])
|
2018-12-22 01:02:55 +00:00
|
|
|
args_split = new_args.split(" ")
|
2018-12-22 01:00:38 +00:00
|
|
|
|
2016-03-29 15:22:22 +00:00
|
|
|
if self.has_command(command):
|
2018-09-06 15:05:14 +00:00
|
|
|
ignore = event["user"].get_setting("ignore", False)
|
|
|
|
if ignore:
|
|
|
|
return
|
|
|
|
|
2016-03-29 15:22:22 +00:00
|
|
|
hook = self.get_hook(command)
|
2018-10-10 09:42:41 +00:00
|
|
|
alias_of = self._get_alias_of(hook)
|
|
|
|
if alias_of:
|
|
|
|
if self.has_command(alias_of):
|
|
|
|
hook = self.get_hook(alias_of)
|
|
|
|
else:
|
|
|
|
raise ValueError("'%s' is an alias of unknown command '%s'"
|
|
|
|
% (command.lower(), alias_of.lower()))
|
2016-03-29 15:22:22 +00:00
|
|
|
|
2018-12-22 01:00:38 +00:00
|
|
|
is_channel = False
|
2016-03-29 15:22:22 +00:00
|
|
|
if "channel" in event:
|
|
|
|
target = event["channel"]
|
|
|
|
is_channel = True
|
|
|
|
else:
|
|
|
|
target = event["user"]
|
|
|
|
if not is_channel and hook.kwargs.get("channel_only"):
|
|
|
|
return
|
2016-04-04 22:20:55 +00:00
|
|
|
if is_channel and hook.kwargs.get("private_only"):
|
2016-04-04 17:41:07 +00:00
|
|
|
return
|
2016-03-29 15:22:22 +00:00
|
|
|
|
2018-10-04 10:04:24 +00:00
|
|
|
module_name = self._get_prefix(hook) or ""
|
|
|
|
if not module_name and hasattr(hook.function, "__self__"):
|
2018-09-29 08:44:13 +00:00
|
|
|
module_name = hook.function.__self__._name
|
2018-10-01 16:26:31 +00:00
|
|
|
|
2018-10-01 16:52:04 +00:00
|
|
|
msgid = event["tags"].get("draft/msgid", None)
|
2018-10-02 20:40:34 +00:00
|
|
|
stdout = StdOut(event["server"], module_name, target, msgid)
|
|
|
|
stderr = StdErr(event["server"], module_name, target, msgid)
|
2019-01-23 20:35:28 +00:00
|
|
|
command_method = self._command_method(target, event["server"])
|
2016-03-29 15:22:22 +00:00
|
|
|
|
2018-10-01 15:32:24 +00:00
|
|
|
returns = self.events.on("preprocess.command").call_unsafe(
|
2018-10-01 15:04:06 +00:00
|
|
|
hook=hook, user=event["user"], server=event["server"],
|
2018-09-03 20:48:14 +00:00
|
|
|
target=target, is_channel=is_channel, tags=event["tags"])
|
2019-01-28 23:29:52 +00:00
|
|
|
|
2019-01-29 08:06:59 +00:00
|
|
|
hard_fail = False
|
2019-01-28 23:52:30 +00:00
|
|
|
force_success = False
|
2019-01-29 08:06:59 +00:00
|
|
|
error = None
|
2016-03-29 15:22:22 +00:00
|
|
|
for returned in returns:
|
2019-01-28 23:29:52 +00:00
|
|
|
if returned == utils.consts.PERMISSION_HARD_FAIL:
|
2019-01-29 08:06:59 +00:00
|
|
|
hard_fail = True
|
2019-01-28 23:29:52 +00:00
|
|
|
elif returned == utils.consts.PERMISSION_FORCE_SUCCESS:
|
|
|
|
force_success = True
|
2019-01-28 23:57:12 +00:00
|
|
|
elif returned:
|
2019-01-28 23:29:52 +00:00
|
|
|
error = returned
|
2019-01-29 08:06:59 +00:00
|
|
|
|
|
|
|
if hard_fail or (not force_success and error):
|
|
|
|
if error:
|
|
|
|
stderr.write(error).send(command_method)
|
|
|
|
target.buffer.skip_next()
|
2019-01-29 15:38:04 +00:00
|
|
|
return
|
2018-10-03 16:01:10 +00:00
|
|
|
|
|
|
|
if hook.kwargs.get("remove_empty", True):
|
|
|
|
args_split = list(filter(None, args_split))
|
|
|
|
|
2016-03-29 15:22:22 +00:00
|
|
|
min_args = hook.kwargs.get("min_args")
|
|
|
|
if min_args and len(args_split) < min_args:
|
2019-01-29 08:32:22 +00:00
|
|
|
command_prefix = ""
|
|
|
|
if is_channel:
|
|
|
|
command_prefix = self._command_prefix(event["server"],
|
|
|
|
target)
|
|
|
|
usage = self._get_usage(hook, command, command_prefix)
|
2018-10-03 16:01:26 +00:00
|
|
|
if usage:
|
2018-10-28 11:50:56 +00:00
|
|
|
stderr.write("Not enough arguments, usage: %s" %
|
2019-01-23 20:35:28 +00:00
|
|
|
usage).send(command_method)
|
2016-04-10 16:31:55 +00:00
|
|
|
else:
|
2018-10-03 16:01:26 +00:00
|
|
|
stderr.write("Not enough arguments (minimum: %d)" %
|
2019-01-23 20:35:28 +00:00
|
|
|
min_args).send(command_method)
|
2016-03-29 15:22:22 +00:00
|
|
|
else:
|
|
|
|
args = " ".join(args_split)
|
|
|
|
server = event["server"]
|
|
|
|
user = event["user"]
|
2018-10-16 13:47:01 +00:00
|
|
|
try:
|
|
|
|
self.events.on("received.command").on(command
|
|
|
|
).call_unsafe_limited(1, user=user, server=server,
|
|
|
|
target=target, args=args, tags=event["tags"],
|
|
|
|
args_split=args_split, stdout=stdout, stderr=stderr,
|
|
|
|
command=command.lower(), is_channel=is_channel)
|
2018-10-16 13:49:01 +00:00
|
|
|
except utils.EventError as e:
|
2018-10-16 14:15:20 +00:00
|
|
|
stderr.write(str(e))
|
2018-10-16 13:47:01 +00:00
|
|
|
|
2018-07-14 08:50:12 +00:00
|
|
|
if not hook.kwargs.get("skip_out", False):
|
2019-01-23 20:35:28 +00:00
|
|
|
command_method = self._command_method(
|
|
|
|
target, event["server"])
|
|
|
|
stdout.send(command_method)
|
|
|
|
stderr.send(command_method)
|
2018-07-14 08:50:12 +00:00
|
|
|
target.last_stdout = stdout
|
|
|
|
target.last_stderr = stderr
|
2018-09-30 10:43:34 +00:00
|
|
|
target.buffer.skip_next()
|
2018-09-09 16:09:04 +00:00
|
|
|
event.eat()
|
2016-03-29 15:22:22 +00:00
|
|
|
|
2019-01-29 08:32:22 +00:00
|
|
|
def _command_prefix(self, server, channel):
|
|
|
|
return channel.get_setting("command-prefix",
|
|
|
|
server.get_setting("command-prefix", "!"))
|
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.message.channel", priority=EventManager.PRIORITY_LOW)
|
2016-03-29 11:56:58 +00:00
|
|
|
def channel_message(self, event):
|
2018-11-12 22:55:40 +00:00
|
|
|
commands_enabled = event["channel"].get_setting("commands", True)
|
|
|
|
if not commands_enabled:
|
|
|
|
return
|
2018-11-12 22:59:21 +00:00
|
|
|
prefixed_commands = event["channel"].get_setting("prefixed-commands", True)
|
2018-11-12 22:55:40 +00:00
|
|
|
|
2019-01-29 08:32:22 +00:00
|
|
|
command_prefix = self._command_prefix(event["server"], event["channel"])
|
2016-03-29 11:56:58 +00:00
|
|
|
if event["message_split"][0].startswith(command_prefix):
|
2018-11-12 22:59:21 +00:00
|
|
|
if not prefixed_commands:
|
|
|
|
return
|
2016-03-29 11:56:58 +00:00
|
|
|
command = event["message_split"][0].replace(
|
|
|
|
command_prefix, "", 1).lower()
|
2016-03-29 15:22:22 +00:00
|
|
|
self.message(event, command)
|
2016-03-30 11:49:46 +00:00
|
|
|
elif len(event["message_split"]) > 1 and self.is_highlight(
|
|
|
|
event["server"], event["message_split"][0]):
|
|
|
|
command = event["message_split"][1].lower()
|
|
|
|
self.message(event, command, 2)
|
2016-03-29 15:22:22 +00:00
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.message.private", priority=EventManager.PRIORITY_LOW)
|
2016-03-29 11:56:58 +00:00
|
|
|
def private_message(self, event):
|
2016-03-29 15:22:22 +00:00
|
|
|
if event["message_split"]:
|
|
|
|
command = event["message_split"][0].lower()
|
|
|
|
self.message(event, command)
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2018-09-26 17:26:10 +00:00
|
|
|
def _get_help(self, hook):
|
2018-09-30 16:29:09 +00:00
|
|
|
return hook.get_kwarg("help", None) or hook.docstring.description
|
2019-01-29 08:32:22 +00:00
|
|
|
def _get_usage(self, hook, command, command_prefix=""):
|
2019-01-29 08:33:32 +00:00
|
|
|
command = "%s%s" % (command_prefix, command)
|
2018-10-28 11:50:56 +00:00
|
|
|
usage = hook.get_kwarg("usage", None)
|
2018-12-29 21:38:03 +00:00
|
|
|
if usage:
|
|
|
|
usages = [usage]
|
|
|
|
else:
|
2018-10-28 11:50:56 +00:00
|
|
|
usages = hook.docstring.var_items.get("usage", None)
|
2018-12-29 21:35:06 +00:00
|
|
|
|
|
|
|
if usages:
|
|
|
|
return " | ".join(
|
|
|
|
"%s %s" % (command, usage) for usage in usages)
|
2018-10-28 11:50:56 +00:00
|
|
|
return usage
|
|
|
|
|
2018-10-04 10:04:24 +00:00
|
|
|
def _get_prefix(self, hook):
|
|
|
|
return hook.get_kwarg("prefix", None)
|
2018-10-10 09:42:41 +00:00
|
|
|
def _get_alias_of(self, hook):
|
|
|
|
return hook.get_kwarg("alias_of", None)
|
2018-09-26 17:26:10 +00:00
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.help")
|
2016-03-29 11:56:58 +00:00
|
|
|
def help(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Show help for a given command
|
|
|
|
:usage: [command]
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2016-03-29 11:56:58 +00:00
|
|
|
if event["args"]:
|
|
|
|
command = event["args_split"][0].lower()
|
2018-08-31 11:55:52 +00:00
|
|
|
if command in self.events.on("received").on(
|
2016-03-29 11:56:58 +00:00
|
|
|
"command").get_children():
|
2018-09-19 12:25:12 +00:00
|
|
|
hooks = self.events.on("received.command").on(command).get_hooks()
|
2018-09-26 17:26:10 +00:00
|
|
|
help = self._get_help(hooks[0])
|
2018-09-26 14:58:16 +00:00
|
|
|
|
|
|
|
if help:
|
2018-09-29 09:50:25 +00:00
|
|
|
event["stdout"].write("%s: %s" % (command, help))
|
2016-04-05 17:41:03 +00:00
|
|
|
else:
|
|
|
|
event["stderr"].write("No help available for %s" % command)
|
|
|
|
else:
|
|
|
|
event["stderr"].write("Unknown command '%s'" % command)
|
2016-03-29 11:56:58 +00:00
|
|
|
else:
|
|
|
|
help_available = []
|
2018-09-19 12:25:12 +00:00
|
|
|
for child in self.events.on("received.command").get_children():
|
|
|
|
hooks = self.events.on("received.command").on(child).get_hooks()
|
2018-09-26 17:26:10 +00:00
|
|
|
|
2018-10-10 09:42:41 +00:00
|
|
|
if hooks and self._get_help(hooks[0]
|
|
|
|
) and not self._get_alias_of(hooks[0]):
|
2016-03-29 11:56:58 +00:00
|
|
|
help_available.append(child)
|
2018-10-10 09:42:41 +00:00
|
|
|
|
2016-03-29 11:56:58 +00:00
|
|
|
help_available = sorted(help_available)
|
|
|
|
event["stdout"].write("Commands: %s" % ", ".join(help_available))
|
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.usage", min_args=1)
|
2016-04-05 17:41:03 +00:00
|
|
|
def usage(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Show the usage for a given command
|
|
|
|
:usage: <command>
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-09 08:06:17 +00:00
|
|
|
command_prefix = ""
|
2018-09-09 07:59:36 +00:00
|
|
|
if event["is_channel"]:
|
2019-01-29 08:32:22 +00:00
|
|
|
command_prefix = self._command_prefix(event["server"],
|
|
|
|
event["target"])
|
2018-09-09 00:19:00 +00:00
|
|
|
|
2016-04-05 17:41:03 +00:00
|
|
|
command = event["args_split"][0].lower()
|
2018-08-31 11:55:52 +00:00
|
|
|
if command in self.events.on("received").on(
|
2016-04-05 17:41:03 +00:00
|
|
|
"command").get_children():
|
2018-09-19 12:25:12 +00:00
|
|
|
hooks = self.events.on("received.command").on(command).get_hooks()
|
2019-01-29 08:36:47 +00:00
|
|
|
usage = self._get_usage(hooks[0], command, command_prefix)
|
2018-09-30 16:29:09 +00:00
|
|
|
|
|
|
|
if usage:
|
2018-10-28 11:54:43 +00:00
|
|
|
event["stdout"].write("Usage: %s" % usage)
|
2016-04-05 17:41:03 +00:00
|
|
|
else:
|
|
|
|
event["stderr"].write("No usage help available for %s" % command)
|
|
|
|
else:
|
|
|
|
event["stderr"].write("Unknown command '%s'" % command)
|
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.more", skip_out=True)
|
2016-03-29 11:56:58 +00:00
|
|
|
def more(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Show more output from the last command
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2016-03-29 15:22:22 +00:00
|
|
|
if event["target"].last_stdout and event["target"].last_stdout.has_text():
|
2019-01-25 07:11:45 +00:00
|
|
|
event["target"].last_stdout.send(
|
|
|
|
self._command_method(event["target"], event["server"]))
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.ignore", min_args=1)
|
2018-09-06 15:05:14 +00:00
|
|
|
def ignore(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Ignore commands from a given user
|
|
|
|
:usage: <nickname>
|
|
|
|
:permission: ignore
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-06 15:05:14 +00:00
|
|
|
user = event["server"].get_user(event["args_split"][0])
|
|
|
|
if user.get_setting("ignore", False):
|
|
|
|
event["stderr"].write("I'm already ignoring '%s'" %
|
|
|
|
user.nickname)
|
|
|
|
else:
|
|
|
|
user.set_setting("ignore", True)
|
|
|
|
event["stdout"].write("Now ignoring '%s'" % user.nickname)
|
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.unignore", min_args=1)
|
2018-09-06 15:05:14 +00:00
|
|
|
def unignore(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Unignore commands from a given user
|
|
|
|
:usage: <nickname>
|
|
|
|
:permission: unignore
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-06 15:05:14 +00:00
|
|
|
user = event["server"].get_user(event["args_split"][0])
|
|
|
|
if not user.get_setting("ignore", False):
|
|
|
|
event["stderr"].write("I'm not ignoring '%s'" % user.nickname)
|
|
|
|
else:
|
|
|
|
user.set_setting("ignore", False)
|
|
|
|
event["stdout"].write("Removed ignore for '%s'" % user.nickname)
|
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("send.stdout")
|
2016-03-29 11:56:58 +00:00
|
|
|
def send_stdout(self, event):
|
2018-10-02 20:40:34 +00:00
|
|
|
stdout = StdOut(event["server"], event["module_name"],
|
|
|
|
event["target"], event.get("msgid", None))
|
2018-11-07 11:27:10 +00:00
|
|
|
|
|
|
|
if event.get("hide_prefix", False):
|
|
|
|
stdout.hide_prefix()
|
|
|
|
|
2019-01-23 21:39:05 +00:00
|
|
|
stdout.write(event["message"]).send(
|
|
|
|
self._command_method(event["target"], event["server"]))
|
2016-03-29 11:56:58 +00:00
|
|
|
if stdout.has_text():
|
|
|
|
event["target"].last_stdout = stdout
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("send.stderr")
|
2016-03-29 11:56:58 +00:00
|
|
|
def send_stderr(self, event):
|
2018-10-02 20:40:34 +00:00
|
|
|
stderr = StdErr(event["server"], event["module_name"],
|
|
|
|
event["target"], event.get("msgid", None))
|
2018-11-07 11:27:10 +00:00
|
|
|
|
|
|
|
if event.get("hide_prefix", False):
|
|
|
|
stderr.hide_prefix()
|
|
|
|
|
2019-01-23 21:39:05 +00:00
|
|
|
stderr.write(event["message"]).send(
|
|
|
|
self._command_method(event["target"], event["server"]))
|
2016-03-29 11:56:58 +00:00
|
|
|
if stderr.has_text():
|
|
|
|
event["target"].last_stderr = stderr
|
2018-12-22 01:00:38 +00:00
|
|
|
|
|
|
|
@utils.hook("received.command.alias", min_args=2)
|
|
|
|
def add_alias(self, event):
|
|
|
|
"""
|
|
|
|
:help: Add a command alias
|
|
|
|
:usage: <alias> <command> <args...>
|
|
|
|
:permission: command-alias
|
|
|
|
"""
|
|
|
|
alias = event["args_split"][0].lower()
|
|
|
|
command = " ".join(event["args_split"][1:])
|
|
|
|
aliases = self._get_aliases(event["server"])
|
|
|
|
aliases[alias] = command
|
|
|
|
self._set_aliases(event["server"], aliases)
|
|
|
|
event["stdout"].write("Added '%s' alias" % alias)
|
2018-12-22 01:05:47 +00:00
|
|
|
|
|
|
|
@utils.hook("received.command.removealias", min_args=1)
|
|
|
|
def remove_alias(self, event):
|
|
|
|
"""
|
|
|
|
:help: Remove a command alias
|
|
|
|
:usage: <alias>
|
|
|
|
:permission: command-alias
|
|
|
|
"""
|
|
|
|
alias = event["args_split"][0].lower()
|
|
|
|
aliases = self._get_aliases(event["server"])
|
|
|
|
|
|
|
|
if not alias in aliases:
|
|
|
|
raise utils.EventError("No '%s' alias" % alias)
|
|
|
|
|
|
|
|
del aliases[alias]
|
2018-12-22 01:06:42 +00:00
|
|
|
self._set_aliases(event["server"], aliases)
|
2018-12-22 01:05:47 +00:00
|
|
|
event["stdout"].write("Removed '%s' alias" % alias)
|