1
0
Fork 0

Suggest command(s) on typo

This commit is contained in:
nemunaire 2015-11-12 19:15:09 +01:00
parent 2ebd86b80f
commit 38412c1c16
1 changed files with 13 additions and 1 deletions

View File

@ -90,7 +90,10 @@ class MessageTreater:
msg -- message to treat
"""
for h in self.hm.get_hooks("in", type(msg).__name__):
res = False
hooks = self.hm.get_hooks("in", type(msg).__name__)
for h in hooks:
if h.can_read(msg.to, msg.server) and h.match(msg):
res = h.run(msg)
@ -104,6 +107,15 @@ class MessageTreater:
yield res
from nemubot.message.command import Command as CommandMessage
if res is False and isinstance(msg, CommandMessage):
from nemubot.hooks import Command as CommandHook
from nemubot.exception import IMException
from nemubot.tools.human import guess
suggest = [s for s in guess(msg.cmd, [h.name for h in hooks if isinstance(h, CommandHook) and h.name is not None])]
if len(suggest) >= 1:
yield IMException("Unknown command %s. Would you mean: %s?" % (msg.cmd, ", ".join(suggest))).fill_response(msg)
def _post_treat(self, msg):
"""Modify output Messages