Make propability-based command suggestions on unknown command
This commit is contained in:
parent
7f0af15e2d
commit
746db08d40
1 changed files with 22 additions and 0 deletions
22
modules/unknown_command.py
Normal file
22
modules/unknown_command.py
Normal file
|
@ -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]))
|
Loading…
Reference in a new issue