2019-06-24 21:56:38 +00:00
|
|
|
#--depends-on commands
|
|
|
|
|
|
|
|
import difflib
|
|
|
|
from src import ModuleManager, utils
|
|
|
|
|
2019-10-30 11:48:35 +00:00
|
|
|
SETTING = utils.BoolSetting("command-suggestions",
|
|
|
|
"Disable/enable command suggestions")
|
|
|
|
@utils.export("serverset", SETTING)
|
|
|
|
@utils.export("channelset", SETTING)
|
2019-06-24 21:56:38 +00:00
|
|
|
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):
|
2019-10-30 11:48:35 +00:00
|
|
|
if not event["server"].get_setting("command-suggestions",
|
|
|
|
event["target"].get_setting("command-suggestions", True)):
|
|
|
|
return
|
|
|
|
|
2019-06-24 21:56:38 +00:00
|
|
|
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]))
|