test
This commit is contained in:
parent
3f372fe494
commit
ffd7a0ebdb
@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
|
from operator import itemgetter
|
||||||
|
from difflib import SequenceMatcher
|
||||||
|
|
||||||
from sopel.trigger import PreTrigger
|
from sopel.trigger import PreTrigger
|
||||||
|
|
||||||
@ -140,6 +142,22 @@ class Commands():
|
|||||||
else:
|
else:
|
||||||
return "rule"
|
return "rule"
|
||||||
|
|
||||||
|
def search_similar_commands(self, searchitem):
|
||||||
|
|
||||||
|
sim_listitems, sim_num = [], []
|
||||||
|
command_types = ["command", "nickname_command", "action_command"]
|
||||||
|
searchlists = [self.valid_sopel_commands, self.valid_sopel_nickname_commands, self.valid_sopel_action_commands]
|
||||||
|
for command_type, searchlist in zip(command_types, searchlists):
|
||||||
|
for listitem in searchlist:
|
||||||
|
similarlevel = SequenceMatcher(None, searchitem.lower(), listitem.lower()).ratio()
|
||||||
|
if similarlevel >= .75:
|
||||||
|
# command_type
|
||||||
|
sim_listitems.append(listitem)
|
||||||
|
sim_num.append(similarlevel)
|
||||||
|
|
||||||
|
if len(sim_listitems) and len(sim_num):
|
||||||
|
sim_num, sim_listitems = (list(x) for x in zip(*sorted(zip(sim_num, sim_listitems), key=itemgetter(0))))
|
||||||
|
|
||||||
def is_real_command(self, trigger_dict):
|
def is_real_command(self, trigger_dict):
|
||||||
|
|
||||||
if trigger_dict["trigger_type"] == "command":
|
if trigger_dict["trigger_type"] == "command":
|
||||||
|
|||||||
@ -48,7 +48,11 @@ def prerun():
|
|||||||
|
|
||||||
# The command is not valid
|
# The command is not valid
|
||||||
if comrun.is_catchall and not comrun.is_real_command:
|
if comrun.is_catchall and not comrun.is_real_command:
|
||||||
bot.say("Invalid command: %s" % comrun.command["trigger_command"])
|
valid_command_results = sb.commands.search_similar_commands(comrun.command["trigger_command"])
|
||||||
|
if not len(valid_command_results):
|
||||||
|
comrun.osd("%s does not appear to be a valid command." % comrun.command["trigger_command"])
|
||||||
|
else:
|
||||||
|
comrun.osd("%s does not appear to be a valid command. Possible Matches: %s" % (comrun.command["trigger_command"], valid_command_results))
|
||||||
return
|
return
|
||||||
|
|
||||||
# At this point, we update the re.match for trigger
|
# At this point, we update the re.match for trigger
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user