mirror of
https://github.com/evennia/evennia.git
synced 2026-04-05 07:27:17 +02:00
Changed how command not found errors are handled by default: Implemented a cos-likeness algorithm (Coling 2008) for comparing strings, which allows for decent suggestions and speed.
This commit is contained in:
parent
4678234e9a
commit
0c292b5ff2
4 changed files with 76 additions and 12 deletions
|
|
@ -42,6 +42,7 @@ from django.conf import settings
|
|||
from src.comms.channelhandler import CHANNELHANDLER
|
||||
from src.utils import logger, utils
|
||||
from src.commands.cmdparser import at_multimatch_cmd
|
||||
from src.utils.utils import string_suggestions
|
||||
|
||||
__all__ = ("cmdhandler",)
|
||||
|
||||
|
|
@ -191,7 +192,12 @@ def cmdhandler(caller, raw_string, testing=False):
|
|||
if syscmd:
|
||||
sysarg = raw_string
|
||||
else:
|
||||
sysarg = "Huh? (Type \"help\" for help)"
|
||||
sysarg = "Command '%s' is not available." % raw_string
|
||||
suggestions = string_suggestions(raw_string, cmdset.get_all_cmd_keys_and_aliases(), cutoff=0.7, maxnum=3)
|
||||
if suggestions:
|
||||
sysarg += " Did you maybe mean %s?" % utils.list_to_string(suggestions, 'or', addquote=True)
|
||||
else:
|
||||
sysarg += " Type \"help\" for help."
|
||||
raise ExecSystemCommand(syscmd, sysarg)
|
||||
|
||||
if len(matches) > 1:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue