aboutsummaryrefslogtreecommitdiff
path: root/modules/command_suggestions.py
diff options
context:
space:
mode:
authorGravatar jesopo2019-06-24 22:58:14 +0100
committerGravatar jesopo2019-06-24 22:58:14 +0100
commit5e11c3fb9d4f746dc2422f151efa1b0c08a7731a (patch)
tree9483d0ebf898e21cd9e31d4efc8a2b719a173710 /modules/command_suggestions.py
parentMake propability-based command suggestions on unknown command (diff)
signature
unknown_command.py -> command_suggestions.py
Diffstat (limited to 'modules/command_suggestions.py')
-rw-r--r--modules/command_suggestions.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/modules/command_suggestions.py b/modules/command_suggestions.py
new file mode 100644
index 00000000..386def9f
--- /dev/null
+++ b/modules/command_suggestions.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]))