From 6a2633d3831967f688362a6b9bc9363602d2cb8b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 10:56:35 -0400 Subject: [PATCH] query command processing changes --- .../SpiceBot_CommandsQuery/QueryCommand.py | 53 +++++++++---------- sopel_modules/SpiceBot_SBTools/__init__.py | 3 -- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index ed3cefd..c1f18a9 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -24,47 +24,42 @@ def query_detection(bot, trigger): commands_list = bot.memory['SpiceBot_CommandsQuery']['commands_all'] triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'query_command') - bot.say(str(triggerargs)) - bot.say(str(triggercommand)) - - triggerargsarray = spicemanip.main(trigger, 'create') # command issued, check if valid - querycommand = spicemanip.main(triggerargsarray, 1).lower()[1:] or None - if not querycommand: + if not triggercommand: return - bot.say(str(querycommand)) - bot.say("no querycommand") + bot.say("no triggercommand") + bot.say(str(triggercommand)) - if len(querycommand) == 1: + if len(triggercommand) == 1: commandlist = [] for command in commands_list.keys(): - if command.lower().startswith(querycommand): + if command.lower().startswith(triggercommand): commandlist.append(command) if commandlist == []: - bot.notice("No commands match " + str(querycommand) + ".", trigger.nick) + bot.notice("No commands match " + str(triggercommand) + ".", trigger.nick) return else: - bot.notice("The following commands match " + str(querycommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) + bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) return - elif querycommand.endswith("+"): - querycommand = querycommand[:-1] - if querycommand not in commands_list.keys(): - bot.notice("The " + str(querycommand) + " does not appear to be valid.") + elif triggercommand.endswith("+"): + triggercommand = triggercommand[:-1] + if triggercommand not in commands_list.keys(): + bot.notice("The " + str(triggercommand) + " does not appear to be valid.") return - realcom = querycommand - if "aliasfor" in commands_list[querycommand].keys(): - realcom = commands_list[querycommand]["aliasfor"] + realcom = triggercommand + if "aliasfor" in commands_list[triggercommand].keys(): + realcom = commands_list[triggercommand]["aliasfor"] validcomlist = commands_list[realcom]["validcoms"] - bot.notice("The following commands match " + str(querycommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick) + bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick) return - elif querycommand.endswith('?'): - querycommand = querycommand[:-1] + elif triggercommand.endswith('?'): + triggercommand = triggercommand[:-1] sim_com, sim_num = [], [] for com in commands_list.keys(): - similarlevel = SequenceMatcher(None, querycommand.lower(), com.lower()).ratio() + similarlevel = SequenceMatcher(None, triggercommand.lower(), com.lower()).ratio() sim_com.append(com) sim_num.append(similarlevel) sim_num, sim_com = (list(x) for x in zip(*sorted(zip(sim_num, sim_com), key=itemgetter(0)))) @@ -74,21 +69,21 @@ def query_detection(bot, trigger): if listnumb <= 10: relist.append(str(item)) listnumb += 1 - bot.notice("The following commands may match " + str(querycommand) + ": " + spicemanip.main(relist, 'andlist') + ".", trigger.nick) + bot.notice("The following commands may match " + str(triggercommand) + ": " + spicemanip.main(relist, 'andlist') + ".", trigger.nick) return - elif querycommand in commands_list.keys(): - bot.notice("The following commands match " + str(querycommand) + ": " + str(querycommand) + ".", trigger.nick) + elif triggercommand in commands_list.keys(): + bot.notice("The following commands match " + str(triggercommand) + ": " + str(triggercommand) + ".", trigger.nick) return else: commandlist = [] for command in commands_list.keys(): - if command.lower().startswith(querycommand): + if command.lower().startswith(triggercommand): commandlist.append(command) if commandlist == []: - bot.notice("No commands match " + str(querycommand) + ".", trigger.nick) + bot.notice("No commands match " + str(triggercommand) + ".", trigger.nick) return else: - bot.notice("The following commands match " + str(querycommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) + bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) return diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 22d5ea6..fb4054b 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -47,9 +47,6 @@ def sopel_triggerargs(bot, trigger, command_type='module_command'): if command_type in ['nickname_command']: command = spicemanip.main(triggerargs, 2).lower() triggerargs = spicemanip.main(triggerargs, '3+', 'list') - elif command_type in ['query_command']: - command = spicemanip.main(triggerargs, 1).lower()[1:] - triggerargs = spicemanip.main(triggerargs, '2+', 'list') else: command = spicemanip.main(triggerargs, 1).lower()[1:] triggerargs = spicemanip.main(triggerargs, '2+', 'list')