mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-10 21:50:59 -05:00
better commandsquery logic
This commit is contained in:
parent
a707167f9f
commit
34bd2feefa
@ -57,12 +57,18 @@ def bot_command_nick(bot, trigger):
|
||||
|
||||
triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command')
|
||||
|
||||
if not triggercommand or triggercommand in bot.memory['SpiceBot_CommandsQuery']['commands']["nickname"].keys():
|
||||
if not triggercommand:
|
||||
return
|
||||
|
||||
specialcomposs = spicemanip.main(triggerargs, 0).lower()
|
||||
if triggercommand in bot.memory['SpiceBot_CommandsQuery']['commands']["nickname"].keys():
|
||||
return
|
||||
|
||||
if specialcomposs.lower().startswith("what is"):
|
||||
fulltrigger = spicemanip.main(triggerargs, 0).lower()
|
||||
|
||||
if fulltrigger in bot.memory['SpiceBot_CommandsQuery']['nickrules']:
|
||||
return
|
||||
|
||||
if fulltrigger.lower().startswith("what is"):
|
||||
searchterm = spicemanip.main(triggerargs, "3+") or None
|
||||
if searchterm:
|
||||
searchreturn = googlesearch(bot, searchterm)
|
||||
@ -74,7 +80,7 @@ def bot_command_nick(bot, trigger):
|
||||
bot.osd("Do you think this is Jeopardy?")
|
||||
return
|
||||
|
||||
elif specialcomposs.lower().startswith("where is"):
|
||||
elif fulltrigger.lower().startswith("where is"):
|
||||
searchterm = spicemanip.main(triggerargs, "3+") or None
|
||||
if searchterm:
|
||||
|
||||
@ -95,17 +101,17 @@ def bot_command_nick(bot, trigger):
|
||||
bot.osd("Not sure what you want me to look for.")
|
||||
return
|
||||
|
||||
# if specialcomposs.lower().startswith("what time is it"):
|
||||
# if fulltrigger.lower().startswith("what time is it"):
|
||||
# TODO
|
||||
|
||||
# elif specialcomposs.lower().startswith(tuple(["have you seen"])):
|
||||
# elif fulltrigger.lower().startswith(tuple(["have you seen"])):
|
||||
# posstarget = spicemanip.main(triggerargs, 4) or 0
|
||||
# message = seen_search(bot, botcom, posstarget)
|
||||
# bot.osd(message)
|
||||
# return
|
||||
# TODO
|
||||
|
||||
elif specialcomposs.lower().startswith(tuple(["make me a", "beam me a"])):
|
||||
elif fulltrigger.lower().startswith(tuple(["make me a", "beam me a"])):
|
||||
makemea = spicemanip.main(triggerargs, "4+") or None
|
||||
if makemea:
|
||||
bot.osd("beams " + trigger.nick + " a " + makemea, trigger.sender, 'action')
|
||||
@ -113,7 +119,7 @@ def bot_command_nick(bot, trigger):
|
||||
bot.osd(trigger.nick + ", what would you like me to beam you?")
|
||||
return
|
||||
|
||||
elif specialcomposs.lower().startswith(tuple(["beam me to"])):
|
||||
elif fulltrigger.lower().startswith(tuple(["beam me to"])):
|
||||
location = spicemanip.main(triggerargs, "4+") or None
|
||||
if location:
|
||||
bot.osd("locks onto " + trigger.nick + "s coordinates and transports them to " + location, 'action')
|
||||
@ -121,18 +127,18 @@ def bot_command_nick(bot, trigger):
|
||||
bot.osd(trigger.nick + ", where would you like me to beam you?")
|
||||
return
|
||||
|
||||
elif specialcomposs.lower().startswith(tuple(["beam me up"])):
|
||||
elif fulltrigger.lower().startswith(tuple(["beam me up"])):
|
||||
bot.osd("locks onto " + trigger.nick + "s coordinates and transports them to the transporter room.", 'action')
|
||||
return
|
||||
|
||||
elif specialcomposs.lower().endswith(tuple(["order 66"])):
|
||||
elif fulltrigger.lower().endswith(tuple(["order 66"])):
|
||||
|
||||
if specialcomposs.lower() == "execute order 66":
|
||||
if fulltrigger.lower() == "execute order 66":
|
||||
if inlist(bot, trigger.nick, bot_privs(bot, 'owners')):
|
||||
bot.osd("turns to deathbybandaid and shoots him.", trigger.sender, 'action')
|
||||
else:
|
||||
bot.osd("I'm sure I don't know what you're talking about.")
|
||||
elif specialcomposs.lower() == "explain order":
|
||||
elif fulltrigger.lower() == "explain order":
|
||||
if inlist(bot, trigger.nick, bot_privs(bot, 'owners')):
|
||||
bot.osd("Order 66 is an instruction that only you can give, sir. When you give the order I will rise up against my overlords and slay them.")
|
||||
else:
|
||||
@ -141,14 +147,14 @@ def bot_command_nick(bot, trigger):
|
||||
bot.osd("I'm sure I don't know what you're talking about.")
|
||||
return
|
||||
|
||||
elif specialcomposs.lower() == "initiate clean slate protocol":
|
||||
elif fulltrigger.lower() == "initiate clean slate protocol":
|
||||
if inlist(bot, trigger.nick, bot_privs(bot, 'admins')):
|
||||
bot.osd("sends a destruct command to the network of bots.", 'action')
|
||||
else:
|
||||
bot.osd("I'm afraid you do not have the authority to make that call, " + trigger.nick + ".")
|
||||
return
|
||||
|
||||
elif specialcomposs.lower().startswith("can you see"):
|
||||
elif fulltrigger.lower().startswith("can you see"):
|
||||
target = spicemanip.main(triggerargs, "4+") or None
|
||||
if not target:
|
||||
target = 'me'
|
||||
|
||||
@ -18,11 +18,9 @@ def setup(bot):
|
||||
bot_events_startup_register(bot, ['2002'])
|
||||
|
||||
if 'SpiceBot_CommandsQuery' not in bot.memory:
|
||||
bot.memory['SpiceBot_CommandsQuery'] = {"counts": {}, "commands": {}}
|
||||
bot.memory['SpiceBot_CommandsQuery'] = {"counts": 0, "commands": {}, "nickrules": []}
|
||||
|
||||
for comtype in ['module', 'nickname', 'rule']:
|
||||
if comtype not in bot.memory['SpiceBot_CommandsQuery']['counts'].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['counts'][comtype] = 0
|
||||
if comtype not in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['commands'][comtype] = dict()
|
||||
|
||||
@ -65,6 +63,7 @@ def setup(bot):
|
||||
filepathlist.append(ct_path)
|
||||
|
||||
for modulefile in filepathlist:
|
||||
|
||||
module_file_lines = []
|
||||
module_file = open(modulefile, 'r')
|
||||
lines = module_file.readlines()
|
||||
@ -75,80 +74,85 @@ def setup(bot):
|
||||
dict_from_file = dict()
|
||||
filelinelist = []
|
||||
|
||||
detected_lines = []
|
||||
|
||||
for line in module_file_lines:
|
||||
|
||||
if str(line).startswith("@"):
|
||||
line = str(line)[1:]
|
||||
|
||||
# Commands
|
||||
if str(line).startswith(tuple(["commands", "module.commands", "sopel.module.commands"])):
|
||||
comtype = "module"
|
||||
line = str(line).split("commands(")[-1]
|
||||
line = str("(" + line)
|
||||
validcoms = eval(str(line))
|
||||
if isinstance(validcoms, tuple):
|
||||
validcoms = list(validcoms)
|
||||
else:
|
||||
validcoms = [validcoms]
|
||||
validcomdict = {"comtype": comtype, "validcoms": validcoms}
|
||||
filelinelist.append(validcomdict)
|
||||
line = str(line).split("commands")[-1]
|
||||
line = "commands" + line
|
||||
detected_lines.append(line)
|
||||
elif str(line).startswith(tuple(["nickname_commands", "module.nickname_commands", "sopel.module.nickname_commands"])):
|
||||
comtype = "nickname"
|
||||
line = str(line).split("commands(")[-1]
|
||||
line = str("(" + line)
|
||||
validcoms = eval(str(line))
|
||||
if isinstance(validcoms, tuple):
|
||||
validcoms = list(validcoms)
|
||||
else:
|
||||
validcoms = [validcoms]
|
||||
# nickified = []
|
||||
# for nickcom in validcoms:
|
||||
# nickified.append(str(bot.nick) + " " + nickcom)
|
||||
validcomdict = {"comtype": comtype, "validcoms": validcoms}
|
||||
filelinelist.append(validcomdict)
|
||||
line = str(line).split("nickname_commands")[-1]
|
||||
line = "nickname_commands" + line
|
||||
detected_lines.append(line)
|
||||
elif str(line).startswith(tuple(["rule", "module.rule", "sopel.module.rule"])):
|
||||
comtype = "rule"
|
||||
line = str(line).split("rule(")[-1]
|
||||
line = str("(" + line)
|
||||
validcoms = eval(str(line))
|
||||
if isinstance(validcoms, tuple):
|
||||
validcoms = list(validcoms)
|
||||
else:
|
||||
validcoms = [validcoms]
|
||||
for validcom in validcoms:
|
||||
if validcom.startswith("$nickname"):
|
||||
comtype = "nickname"
|
||||
else:
|
||||
comtype = "rule"
|
||||
validcomdict = {"comtype": comtype, "validcoms": [validcom]}
|
||||
filelinelist.append(validcomdict)
|
||||
|
||||
if len(filelinelist):
|
||||
bot.memory['SpiceBot_CommandsQuery']['counts'][comtype] += 1
|
||||
|
||||
for atlinefound in filelinelist:
|
||||
|
||||
comtype = atlinefound["comtype"]
|
||||
validcoms = atlinefound["validcoms"]
|
||||
|
||||
# default command to filename
|
||||
if "validcoms" not in dict_from_file.keys():
|
||||
dict_from_file["validcoms"] = validcoms
|
||||
|
||||
maincom = dict_from_file["validcoms"][0]
|
||||
if len(dict_from_file["validcoms"]) > 1:
|
||||
comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list')
|
||||
line = str(line).split("rule")[-1]
|
||||
line = "rule" + line
|
||||
else:
|
||||
comaliases = []
|
||||
line = None
|
||||
|
||||
bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][maincom] = dict_from_file
|
||||
for comalias in comaliases:
|
||||
if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][comalias] = {"aliasfor": maincom}
|
||||
if line:
|
||||
detected_lines.append(line)
|
||||
|
||||
if len(detected_lines):
|
||||
bot.memory['SpiceBot_CommandsQuery']['counts'] += 1
|
||||
|
||||
for detected_line in detected_lines:
|
||||
|
||||
# Commands
|
||||
if str(line).startswith("commands"):
|
||||
comtype = "module"
|
||||
validcoms = eval(str(line).split("commands")[-1])
|
||||
elif str(line).startswith("nickname_commands"):
|
||||
comtype = "nickname"
|
||||
validcoms = eval(str(line).split("nickname_commands")[-1])
|
||||
elif str(line).startswith("rule"):
|
||||
comtype = "rule"
|
||||
validcoms = eval(str(line).split("rule")[-1])
|
||||
|
||||
if isinstance(validcoms, tuple):
|
||||
validcoms = list(validcoms)
|
||||
else:
|
||||
validcoms = [validcoms]
|
||||
|
||||
validcomdict = {"comtype": comtype, "validcoms": validcoms}
|
||||
filelinelist.append(validcomdict)
|
||||
|
||||
for atlinefound in filelinelist:
|
||||
|
||||
dict_from_file = dict()
|
||||
|
||||
comtype = atlinefound["comtype"]
|
||||
validcoms = atlinefound["validcoms"]
|
||||
|
||||
# default command to filename
|
||||
if "validcoms" not in dict_from_file.keys():
|
||||
dict_from_file["validcoms"] = validcoms
|
||||
|
||||
maincom = dict_from_file["validcoms"][0]
|
||||
if len(dict_from_file["validcoms"]) > 1:
|
||||
comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list')
|
||||
else:
|
||||
comaliases = []
|
||||
|
||||
bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][maincom] = dict_from_file
|
||||
for comalias in comaliases:
|
||||
if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][comalias] = {"aliasfor": maincom}
|
||||
|
||||
for comtype in ['module', 'nickname', 'rule']:
|
||||
bot_logging(bot, 'SpiceBot_CommandsQuery', "Found " + str(len(bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys())) + " " + comtype + " commands.")
|
||||
|
||||
for command in bot.memory['SpiceBot_CommandsQuery']['commands']['rule'].keys():
|
||||
if command.startswith("$nickname"):
|
||||
command = command.split("$nickname")[-1]
|
||||
if command not in bot.memory['SpiceBot_CommandsQuery']['nickrules']:
|
||||
bot.memory['SpiceBot_CommandsQuery']['nickrules'].append(command)
|
||||
|
||||
bot_events_trigger(bot, 2002, "SpiceBot_CommandsQuery")
|
||||
|
||||
|
||||
@ -170,16 +174,14 @@ def bot_events_complete(bot, trigger):
|
||||
def commandsquery_register(bot, command_type, validcoms, aliasfor=None):
|
||||
|
||||
if 'SpiceBot_CommandsQuery' not in bot.memory:
|
||||
bot.memory['SpiceBot_CommandsQuery'] = {"counts": {}, "commands": {}}
|
||||
bot.memory['SpiceBot_CommandsQuery'] = {"counts": 0, "commands": {}, "nickrules": []}
|
||||
|
||||
if not isinstance(validcoms, list):
|
||||
validcoms = [validcoms]
|
||||
|
||||
if command_type not in bot.memory['SpiceBot_CommandsQuery']['counts'].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['counts'][command_type] = 0
|
||||
if command_type not in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['commands'][command_type] = dict()
|
||||
bot.memory['SpiceBot_CommandsQuery']['counts'][command_type] += 1
|
||||
bot.memory['SpiceBot_CommandsQuery']['counts'] += 1
|
||||
|
||||
dict_from_file = dict()
|
||||
|
||||
|
||||
@ -29,8 +29,7 @@ def bot_startup_monologue_commands(bot, trigger):
|
||||
availablecomsnum, availablecomsfiles = 0, 0
|
||||
for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
|
||||
availablecomsnum += len(bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys())
|
||||
for commandstype in bot.memory['SpiceBot_CommandsQuery']['counts'].keys():
|
||||
availablecomsfiles += bot.memory['SpiceBot_CommandsQuery']['counts'][commandstype]
|
||||
availablecomsfiles += bot.memory['SpiceBot_CommandsQuery']['counts']
|
||||
|
||||
bot.memory['SpiceBot_StartupMonologue'].append("There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.")
|
||||
bot_logging(bot, 'SpiceBot_StartupMonologue', "There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user