diff options
Diffstat (limited to 'src/core_modules')
| -rw-r--r-- | src/core_modules/admin.py | 12 | ||||
| -rw-r--r-- | src/core_modules/aliases.py | 19 | ||||
| -rw-r--r-- | src/core_modules/banmask.py | 24 | ||||
| -rw-r--r-- | src/core_modules/channel_access.py | 2 | ||||
| -rw-r--r-- | src/core_modules/command_spec/__init__.py | 4 | ||||
| -rw-r--r-- | src/core_modules/commands/__init__.py | 38 | ||||
| -rw-r--r-- | src/core_modules/commands/outs.py | 7 | ||||
| -rw-r--r-- | src/core_modules/line_handler/__init__.py | 4 | ||||
| -rw-r--r-- | src/core_modules/line_handler/core.py | 6 | ||||
| -rw-r--r-- | src/core_modules/line_handler/message.py | 4 | ||||
| -rw-r--r-- | src/core_modules/mode_lists.py | 4 | ||||
| -rw-r--r-- | src/core_modules/more.py | 2 | ||||
| -rw-r--r-- | src/core_modules/perform.py | 52 |
13 files changed, 110 insertions, 68 deletions
diff --git a/src/core_modules/admin.py b/src/core_modules/admin.py index f87927b1..5008952d 100644 --- a/src/core_modules/admin.py +++ b/src/core_modules/admin.py @@ -32,9 +32,17 @@ class Module(ModuleManager.BaseModule): @utils.kwarg("permission", "part") @utils.kwarg("require_mode", "high") @utils.kwarg("require_access", "high,part") - @utils.spec("!r~channel") + @utils.spec("!-privateonly !<channel>word") + @utils.spec("!-channelonly ?<channel>word") def part(self, event): - event["server"].send_part(event["spec"][0].name) + event["server"].send_part(event["spec"][0] or event["target"].name) + + @utils.hook("received.command.join") + @utils.kwarg("help", "Join a given channel") + @utils.kwarg("permission", "join") + @utils.spec("!<channel>word") + def join(self, event): + event["server"].send_join(event["spec"][0]) def _id_from_alias(self, alias): return self.bot.database.servers.get_by_alias(alias) diff --git a/src/core_modules/aliases.py b/src/core_modules/aliases.py index b6ca8961..b5ed86f1 100644 --- a/src/core_modules/aliases.py +++ b/src/core_modules/aliases.py @@ -3,6 +3,8 @@ from src import EventManager, ModuleManager, utils SETTING_PREFIX = "command-alias-" +class VariableKeyError(KeyError): + pass class Module(ModuleManager.BaseModule): def _arg_replace(self, s, args_split, kwargs): vars = {} @@ -11,7 +13,11 @@ class Module(ModuleManager.BaseModule): vars["%d-" % i] = " ".join(args_split[i:]) vars["-"] = " ".join(args_split) vars.update(kwargs) - return utils.parse.format_token_replace(s, vars) + + not_found, new_s = utils.parse.format_token_replace(s, vars) + if not_found: + raise VariableKeyError(f"not found: {not_found!r}") + return new_s def _get_alias(self, server, target, command): setting = "%s%s" % (SETTING_PREFIX, command) @@ -45,9 +51,14 @@ class Module(ModuleManager.BaseModule): if event["command"].args: given_args = event["command"].args.split(" ") - event["command"].command = alias - event["command"].args = self._arg_replace(alias_args, given_args, - event["kwargs"]) + try: + event["command"].args = self._arg_replace(alias_args, + given_args, event["kwargs"]) + except VariableKeyError: + pass + else: + event["command"].command = alias + @utils.hook("received.command.alias", permission="alias") diff --git a/src/core_modules/banmask.py b/src/core_modules/banmask.py new file mode 100644 index 00000000..bc33d4a9 --- /dev/null +++ b/src/core_modules/banmask.py @@ -0,0 +1,24 @@ +from src import ModuleManager, utils + +SETTING = utils.Setting("ban-format", + "Set ban format " + "(${n} = nick, ${u} = username, ${h} = hostname, ${a} = account", + example="*!${u}@${h}") + +@utils.export("channelset", SETTING) +@utils.export("serverset", SETTING) +class Module(ModuleManager.BaseModule): + def _format_hostmask(self, user, s): + vars = {} + vars["n"] = vars["nickname"] = user.nickname + vars["u"] = vars["username"] = user.username + vars["h"] = vars["hostname"] = user.hostname + vars["a"] = vars["account"] = user.account or "" + missing, out = utils.parse.format_token_replace(s, vars) + return out + @utils.export("ban-mask") + def banmask(self, server, channel, user): + format = channel.get_setting("ban-format", + server.get_setting("ban-format", "*!${u}@${h}")) + return self._format_hostmask(user, format) + diff --git a/src/core_modules/channel_access.py b/src/core_modules/channel_access.py index 662599e0..a8c371a8 100644 --- a/src/core_modules/channel_access.py +++ b/src/core_modules/channel_access.py @@ -21,7 +21,7 @@ class Module(ModuleManager.BaseModule): user_access = target.get_user_setting(user.get_id(), "access", []) - identified = self.exports.get_one("is-identified")(user) + identified = self.exports.get("is-identified")(user) matched = list(set(required_access)&set(user_access)) return ("*" in user_access or matched) and identified diff --git a/src/core_modules/command_spec/__init__.py b/src/core_modules/command_spec/__init__.py index 34fd5aef..6345d342 100644 --- a/src/core_modules/command_spec/__init__.py +++ b/src/core_modules/command_spec/__init__.py @@ -48,7 +48,7 @@ class Module(ModuleManager.BaseModule): if argument_type.type in types.TYPES: func = types.TYPES[argument_type.type] else: - func = self.exports.get_one( + func = self.exports.get( "command-spec.%s" % argument_type.type) if func: @@ -142,7 +142,7 @@ class Module(ModuleManager.BaseModule): usages = [ utils.parse.argument_spec_human(s, context) for s in specs] command = "%s%s" % (event["command_prefix"], event["command"]) - usages = ["%s%s" % (command, u) for u in usages] + usages = ["%s %s" % (command, u) for u in usages] error_out = "%s (Usage: %s)" % (overall_error, " | ".join(usages)) diff --git a/src/core_modules/commands/__init__.py b/src/core_modules/commands/__init__.py index a5c5faa6..3a0e74cd 100644 --- a/src/core_modules/commands/__init__.py +++ b/src/core_modules/commands/__init__.py @@ -8,8 +8,8 @@ COMMAND_METHOD = "command-method" COMMAND_METHODS = ["PRIVMSG", "NOTICE"] STR_MORE = " (more...)" +STR_CONTINUED = "(...continued) " STR_MORE_LEN = len(STR_MORE.encode("utf8")) -STR_CONTINUED = "(...continued)" WORD_BOUNDARIES = [" "] NON_ALPHANUMERIC = [char for char in string.printable if not char.isalnum()] @@ -73,12 +73,12 @@ class Module(ModuleManager.BaseModule): self.bot.get_setting(COMMAND_METHOD, default))).upper() def _find_command_hook(self, server, target, is_channel, command, user, - args): + command_prefix, args): if not self.has_command(command): command_event = CommandEvent(command, args) self.events.on("get.command").call(command=command_event, server=server, target=target, is_channel=is_channel, user=user, - kwargs={}) + command_prefix=command_prefix, kwargs={}) command = command_event.command args = command_event.args @@ -237,29 +237,25 @@ class Module(ModuleManager.BaseModule): color = utils.consts.RED line_str = obj.pop() + prefix = "" if obj.prefix: - line_str = "[%s] %s" % ( - utils.irc.color(obj.prefix, color), line_str) + prefix = "[%s] " % utils.irc.color(obj.prefix, color) + if obj._overflowed: + prefix = "%s%s" % (prefix, STR_CONTINUED) method = self._command_method(server, target, is_channel) if not method in ["PRIVMSG", "NOTICE"]: raise ValueError("Unknown command-method '%s'" % method) - line = IRCLine.ParsedLine(method, [target_str, line_str], - tags=tags) - valid, trunc = line.truncate(server.hostmask(), - margin=STR_MORE_LEN) + line = server.new_line(method, [target_str, prefix], tags=tags) + + overflow = line.push_last(line_str, human_trunc=True, + extra_margin=STR_MORE_LEN) + if overflow: + line.push_last(STR_MORE) + obj.insert(overflow) + obj._overflowed = True - if trunc: - if not trunc[0] in WORD_BOUNDARIES: - for boundary in WORD_BOUNDARIES: - left, *right = valid.rsplit(boundary, 1) - if right: - valid = left - trunc = right[0]+trunc - obj.insert("%s %s" % (STR_CONTINUED, trunc)) - valid = valid+STR_MORE - line = IRCLine.parse_line(valid) if obj._assured: line.assure() server.send(line) @@ -309,7 +305,7 @@ class Module(ModuleManager.BaseModule): try: hook, command, args_split = self._find_command_hook( event["server"], event["channel"], True, command, - event["user"], args) + event["user"], command_prefix, args) except BadContextException: event["channel"].send_message( "%s: That command is not valid in a channel" % @@ -371,7 +367,7 @@ class Module(ModuleManager.BaseModule): try: hook, command, args_split = self._find_command_hook( event["server"], event["user"], False, command, - event["user"], args) + event["user"], "", args) except BadContextException: event["user"].send_message( "That command is not valid in a PM") diff --git a/src/core_modules/commands/outs.py b/src/core_modules/commands/outs.py index e82ceefd..c6b489ae 100644 --- a/src/core_modules/commands/outs.py +++ b/src/core_modules/commands/outs.py @@ -6,6 +6,13 @@ class StdOut(object): self.prefix = prefix self._lines = [] self._assured = False + self._overflowed = False + + def copy_from(self, other): + self.prefix = other.prefix + self._lines = other._lines + self._assured = other._assured + self._overflowed = other._overflowed def assure(self): self._assured = True diff --git a/src/core_modules/line_handler/__init__.py b/src/core_modules/line_handler/__init__.py index a77dc451..f23a98ed 100644 --- a/src/core_modules/line_handler/__init__.py +++ b/src/core_modules/line_handler/__init__.py @@ -205,6 +205,10 @@ class Module(ModuleManager.BaseModule): @utils.hook("raw.received.chghost") def chghost(self, event): user.chghost(self.events, event) + # RPL_VISIBLEHOST, telling us what our hostname (and sometimes username) is + @utils.hook("raw.received.396") + def handle_396(self, event): + core.handle_396(event) # IRCv3 SETNAME, to change a user's realname @utils.hook("raw.received.setname") diff --git a/src/core_modules/line_handler/core.py b/src/core_modules/line_handler/core.py index a7075613..aa862a03 100644 --- a/src/core_modules/line_handler/core.py +++ b/src/core_modules/line_handler/core.py @@ -165,3 +165,9 @@ def handle_433(event): _nick_in_use(event["server"]) def handle_437(event): _nick_in_use(event["server"]) + +def handle_396(event): + username, sep, hostname = event["line"].args[1].rpartition("@") + event["server"].hostname = hostname + if sep: + event["server"].username = username diff --git a/src/core_modules/line_handler/message.py b/src/core_modules/line_handler/message.py index 87b91c9e..b3e64be1 100644 --- a/src/core_modules/line_handler/message.py +++ b/src/core_modules/line_handler/message.py @@ -64,7 +64,7 @@ def message(events, event): action = False - if message: + if not message == None: ctcp_message = utils.irc.parse_ctcp(message) if ctcp_message: @@ -97,7 +97,7 @@ def message(events, event): hook = events.on(direction).on(event_type).on(context) buffer_line = None - if message: + if not message == None: buffer_line = IRCBuffer.BufferLine(user.nickname, message, action, event["line"].tags, from_self, event["line"].command) diff --git a/src/core_modules/mode_lists.py b/src/core_modules/mode_lists.py index f560ffa0..37918608 100644 --- a/src/core_modules/mode_lists.py +++ b/src/core_modules/mode_lists.py @@ -24,7 +24,7 @@ class Module(ModuleManager.BaseModule): @utils.hook("received.348") def on_348(self, event): mode = self._excepts(event["server"]) - self._mode_list_mask(event, mode, event["line"].args[3]) + self._mode_list_mask(event, mode, event["line"].args[2]) @utils.hook("received.349") def on_349(self, event): self._mode_list_end(event, self._excepts(event["server"])) @@ -35,7 +35,7 @@ class Module(ModuleManager.BaseModule): @utils.hook("received.346") def on_346(self, event): mode = self._invex(event["server"]) - self._mode_list_mask(event, mode, event["line"].args[3]) + self._mode_list_mask(event, mode, event["line"].args[2]) @utils.hook("received.347") def on_347(self, event): self._mode_list_end(event, self._invex(event["server"])) diff --git a/src/core_modules/more.py b/src/core_modules/more.py index 52849938..bc76fb6b 100644 --- a/src/core_modules/more.py +++ b/src/core_modules/more.py @@ -20,4 +20,4 @@ class Module(ModuleManager.BaseModule): def more(self, event): last_stdout = event["target"]._last_stdout if last_stdout and last_stdout.has_text(): - event["stdout"].write_lines(last_stdout.get_all()) + event["stdout"].copy_from(last_stdout) diff --git a/src/core_modules/perform.py b/src/core_modules/perform.py index 832cab54..06f8cd89 100644 --- a/src/core_modules/perform.py +++ b/src/core_modules/perform.py @@ -24,53 +24,39 @@ class Module(ModuleManager.BaseModule): self._execute(event["server"], commands, NICK=event["server"].nickname, CHAN=event["channel"].name) - def _perform(self, target, args_split): - subcommand = args_split[0].lower() + def _perform(self, target, spec): + subcommand = spec[0] current_perform = target.get_setting("perform", []) if subcommand == "list": return "Configured commands: %s" % ", ".join(current_perform) message = None if subcommand == "add": - if not len(args_split) > 1: - raise utils.EventError("Please provide a raw command to add") - current_perform.append(" ".join(args_split[1:])) + current_perform.append(spec[1]) message = "Added command" elif subcommand == "remove": - if not len(args_split) > 1: - raise utils.EventError("Please provide an index to remove") - if not args_split[1].isdigit(): - raise utils.EventError("Please provide a number") - index = int(args_split[1]) + index = spec[1] if not index < len(current_perform): raise utils.EventError("Index out of bounds") - current_perform.pop(index) - message = "Removed command" - else: - raise utils.EventError("Unknown subcommand '%s'" % subcommand) + command = current_perform.pop(index) + message = "Removed command %d (%s)" % (index, command) target.set_setting("perform", current_perform) return message - @utils.hook("received.command.perform", min_args=1) - @utils.kwarg("min_args", 1) + @utils.hook("received.command.perform", permission="perform", + help="Edit on-connect command configuration") + @utils.hook("received.command.cperform", permission="perform", + help="Edit channel on-join command configuration", channel_only=True) @utils.kwarg("help", "Edit on-connect command configuration") - @utils.kwarg("usage", "list") - @utils.kwarg("usage", "add <raw command>") - @utils.kwarg("usage", "remove <index>") - @utils.kwarg("permission", "perform") + @utils.spec("!'list") + @utils.spec("!'add !<command>string") + @utils.spec("!'remove !<index>int") def perform(self, event): - event["stdout"].write(self._perform(event["server"], - event["args_split"])) + if event["command"] == "perform": + target = event["server"] + elif event["command"] == "cperform": + target = event["target"] - @utils.hook("received.command.cperform", min_args=1) - @utils.kwarg("min_args", 1) - @utils.kwarg("channel_only", True) - @utils.kwarg("help", "Edit channel on-join command configuration") - @utils.kwarg("usage", "list") - @utils.kwarg("usage", "add <raw command>") - @utils.kwarg("usage", "remove <index>") - @utils.kwarg("permission", "cperform") - def cperform(self, event): - event["stdout"].write(self._perform(event["target"], - event["args_split"])) + out = self._perform(target, event["spec"]) + event["stdout"].write("%s: %s" % (event["user"].nickname, out)) |
