diff options
| author | 2016-03-30 12:49:46 +0100 | |
|---|---|---|
| committer | 2016-03-30 12:49:46 +0100 | |
| commit | dc24b6b6807b882febe66b33e59132b417ccd80d (patch) | |
| tree | ab8c7c019dfb1dd1495d0d988172fb8b48145010 | |
| parent | added a line I forgot to add to dispose of nonvisible users. (diff) | |
made channel commands prefixable with the bot's nickname, not just the command prefix.
| -rw-r--r-- | modules/commands.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/modules/commands.py b/modules/commands.py index 60ab511f..07fbbaed 100644 --- a/modules/commands.py +++ b/modules/commands.py @@ -1,4 +1,3 @@ - STR_MORE = " (more...)" STR_CONTINUED = "(...continued) " @@ -66,7 +65,12 @@ class Module(object): return self.bot.events.on("received").on("command").on(command ).get_hooks()[0] - def message(self, event, command): + def is_highlight(self, server, s): + return s.lower() == server.nickname_lower or (s.lower().startswith( + server.nickname_lower) and len(s) == len(server.nickname_lower + )+1 and s[-1] in [":", ","]) + + def message(self, event, command, args_index=1): if self.has_command(command): hook = self.get_hook(command) is_channel = False @@ -92,7 +96,7 @@ class Module(object): if returned: stderr.write(returned).send() return - args_split = list(filter(None, event["message_split"][1:])) + args_split = list(filter(None, event["message_split"][args_index:])) min_args = hook.kwargs.get("min_args") if min_args and len(args_split) < min_args: stderr.write("Not enough arguments (minimum: %d)" % min_args @@ -117,6 +121,10 @@ class Module(object): command = event["message_split"][0].replace( command_prefix, "", 1).lower() self.message(event, command) + 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) def private_message(self, event): if event["message_split"]: |
