diff options
| author | 2019-06-24 22:56:38 +0100 | |
|---|---|---|
| committer | 2019-06-24 22:56:38 +0100 | |
| commit | 746db08d40dcb6658ea69f6e190a0b38da8bc153 (patch) | |
| tree | 7135ba8243f8a9b48f1bc3ba4aa214bd38ba63f9 /modules | |
| parent | send is_channel kwarg on unknown.command event (diff) | |
| signature | ||
Make propability-based command suggestions on unknown command
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/unknown_command.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/modules/unknown_command.py b/modules/unknown_command.py new file mode 100644 index 00000000..386def9f --- /dev/null +++ b/modules/unknown_command.py @@ -0,0 +1,22 @@ +#--depends-on commands + +import difflib +from src import ModuleManager, utils + +class Module(ModuleManager.BaseModule): + def _all_command_hooks(self): + return self.events.on("received.command").get_children() + + @utils.hook("unknown.command") + def unknown_command(self, event): + all_commands = self._all_command_hooks() + match = difflib.get_close_matches(event["command"], all_commands, + cutoff=0.7) + if match: + nickname = "" + if event["is_channel"]: + nickname = "%s: " % event["user"].nickname + + event["target"].send_message( + "%sUnknown command. Did you mean %s%s?" % ( + nickname, event["command_prefix"], match[0])) |
