query command processing changes

This commit is contained in:
deathbybandaid 2019-05-13 10:56:35 -04:00
parent 73a75b3347
commit 6a2633d383
2 changed files with 24 additions and 32 deletions

View File

@ -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

View File

@ -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')