mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-12 22:49:53 -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')
|
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
|
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
|
searchterm = spicemanip.main(triggerargs, "3+") or None
|
||||||
if searchterm:
|
if searchterm:
|
||||||
searchreturn = googlesearch(bot, searchterm)
|
searchreturn = googlesearch(bot, searchterm)
|
||||||
@ -74,7 +80,7 @@ def bot_command_nick(bot, trigger):
|
|||||||
bot.osd("Do you think this is Jeopardy?")
|
bot.osd("Do you think this is Jeopardy?")
|
||||||
return
|
return
|
||||||
|
|
||||||
elif specialcomposs.lower().startswith("where is"):
|
elif fulltrigger.lower().startswith("where is"):
|
||||||
searchterm = spicemanip.main(triggerargs, "3+") or None
|
searchterm = spicemanip.main(triggerargs, "3+") or None
|
||||||
if searchterm:
|
if searchterm:
|
||||||
|
|
||||||
@ -95,17 +101,17 @@ def bot_command_nick(bot, trigger):
|
|||||||
bot.osd("Not sure what you want me to look for.")
|
bot.osd("Not sure what you want me to look for.")
|
||||||
return
|
return
|
||||||
|
|
||||||
# if specialcomposs.lower().startswith("what time is it"):
|
# if fulltrigger.lower().startswith("what time is it"):
|
||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
# elif specialcomposs.lower().startswith(tuple(["have you seen"])):
|
# elif fulltrigger.lower().startswith(tuple(["have you seen"])):
|
||||||
# posstarget = spicemanip.main(triggerargs, 4) or 0
|
# posstarget = spicemanip.main(triggerargs, 4) or 0
|
||||||
# message = seen_search(bot, botcom, posstarget)
|
# message = seen_search(bot, botcom, posstarget)
|
||||||
# bot.osd(message)
|
# bot.osd(message)
|
||||||
# return
|
# return
|
||||||
# TODO
|
# 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
|
makemea = spicemanip.main(triggerargs, "4+") or None
|
||||||
if makemea:
|
if makemea:
|
||||||
bot.osd("beams " + trigger.nick + " a " + makemea, trigger.sender, 'action')
|
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?")
|
bot.osd(trigger.nick + ", what would you like me to beam you?")
|
||||||
return
|
return
|
||||||
|
|
||||||
elif specialcomposs.lower().startswith(tuple(["beam me to"])):
|
elif fulltrigger.lower().startswith(tuple(["beam me to"])):
|
||||||
location = spicemanip.main(triggerargs, "4+") or None
|
location = spicemanip.main(triggerargs, "4+") or None
|
||||||
if location:
|
if location:
|
||||||
bot.osd("locks onto " + trigger.nick + "s coordinates and transports them to " + location, 'action')
|
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?")
|
bot.osd(trigger.nick + ", where would you like me to beam you?")
|
||||||
return
|
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')
|
bot.osd("locks onto " + trigger.nick + "s coordinates and transports them to the transporter room.", 'action')
|
||||||
return
|
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')):
|
if inlist(bot, trigger.nick, bot_privs(bot, 'owners')):
|
||||||
bot.osd("turns to deathbybandaid and shoots him.", trigger.sender, 'action')
|
bot.osd("turns to deathbybandaid and shoots him.", trigger.sender, 'action')
|
||||||
else:
|
else:
|
||||||
bot.osd("I'm sure I don't know what you're talking about.")
|
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')):
|
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.")
|
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:
|
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.")
|
bot.osd("I'm sure I don't know what you're talking about.")
|
||||||
return
|
return
|
||||||
|
|
||||||
elif specialcomposs.lower() == "initiate clean slate protocol":
|
elif fulltrigger.lower() == "initiate clean slate protocol":
|
||||||
if inlist(bot, trigger.nick, bot_privs(bot, 'admins')):
|
if inlist(bot, trigger.nick, bot_privs(bot, 'admins')):
|
||||||
bot.osd("sends a destruct command to the network of bots.", 'action')
|
bot.osd("sends a destruct command to the network of bots.", 'action')
|
||||||
else:
|
else:
|
||||||
bot.osd("I'm afraid you do not have the authority to make that call, " + trigger.nick + ".")
|
bot.osd("I'm afraid you do not have the authority to make that call, " + trigger.nick + ".")
|
||||||
return
|
return
|
||||||
|
|
||||||
elif specialcomposs.lower().startswith("can you see"):
|
elif fulltrigger.lower().startswith("can you see"):
|
||||||
target = spicemanip.main(triggerargs, "4+") or None
|
target = spicemanip.main(triggerargs, "4+") or None
|
||||||
if not target:
|
if not target:
|
||||||
target = 'me'
|
target = 'me'
|
||||||
|
|||||||
@ -18,11 +18,9 @@ def setup(bot):
|
|||||||
bot_events_startup_register(bot, ['2002'])
|
bot_events_startup_register(bot, ['2002'])
|
||||||
|
|
||||||
if 'SpiceBot_CommandsQuery' not in bot.memory:
|
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']:
|
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():
|
if comtype not in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
|
||||||
bot.memory['SpiceBot_CommandsQuery']['commands'][comtype] = dict()
|
bot.memory['SpiceBot_CommandsQuery']['commands'][comtype] = dict()
|
||||||
|
|
||||||
@ -65,6 +63,7 @@ def setup(bot):
|
|||||||
filepathlist.append(ct_path)
|
filepathlist.append(ct_path)
|
||||||
|
|
||||||
for modulefile in filepathlist:
|
for modulefile in filepathlist:
|
||||||
|
|
||||||
module_file_lines = []
|
module_file_lines = []
|
||||||
module_file = open(modulefile, 'r')
|
module_file = open(modulefile, 'r')
|
||||||
lines = module_file.readlines()
|
lines = module_file.readlines()
|
||||||
@ -75,59 +74,58 @@ def setup(bot):
|
|||||||
dict_from_file = dict()
|
dict_from_file = dict()
|
||||||
filelinelist = []
|
filelinelist = []
|
||||||
|
|
||||||
|
detected_lines = []
|
||||||
|
|
||||||
for line in module_file_lines:
|
for line in module_file_lines:
|
||||||
|
|
||||||
if str(line).startswith("@"):
|
if str(line).startswith("@"):
|
||||||
line = str(line)[1:]
|
line = str(line)[1:]
|
||||||
|
|
||||||
# Commands
|
|
||||||
if str(line).startswith(tuple(["commands", "module.commands", "sopel.module.commands"])):
|
if str(line).startswith(tuple(["commands", "module.commands", "sopel.module.commands"])):
|
||||||
comtype = "module"
|
line = str(line).split("commands")[-1]
|
||||||
line = str(line).split("commands(")[-1]
|
line = "commands" + line
|
||||||
line = str("(" + line)
|
detected_lines.append(line)
|
||||||
validcoms = eval(str(line))
|
|
||||||
if isinstance(validcoms, tuple):
|
|
||||||
validcoms = list(validcoms)
|
|
||||||
else:
|
|
||||||
validcoms = [validcoms]
|
|
||||||
validcomdict = {"comtype": comtype, "validcoms": validcoms}
|
|
||||||
filelinelist.append(validcomdict)
|
|
||||||
elif str(line).startswith(tuple(["nickname_commands", "module.nickname_commands", "sopel.module.nickname_commands"])):
|
elif str(line).startswith(tuple(["nickname_commands", "module.nickname_commands", "sopel.module.nickname_commands"])):
|
||||||
|
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"])):
|
||||||
|
line = str(line).split("rule")[-1]
|
||||||
|
line = "rule" + line
|
||||||
|
else:
|
||||||
|
line = None
|
||||||
|
|
||||||
|
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"
|
comtype = "nickname"
|
||||||
line = str(line).split("commands(")[-1]
|
validcoms = eval(str(line).split("nickname_commands")[-1])
|
||||||
line = str("(" + line)
|
elif str(line).startswith("rule"):
|
||||||
validcoms = eval(str(line))
|
comtype = "rule"
|
||||||
|
validcoms = eval(str(line).split("rule")[-1])
|
||||||
|
|
||||||
if isinstance(validcoms, tuple):
|
if isinstance(validcoms, tuple):
|
||||||
validcoms = list(validcoms)
|
validcoms = list(validcoms)
|
||||||
else:
|
else:
|
||||||
validcoms = [validcoms]
|
validcoms = [validcoms]
|
||||||
# nickified = []
|
|
||||||
# for nickcom in validcoms:
|
|
||||||
# nickified.append(str(bot.nick) + " " + nickcom)
|
|
||||||
validcomdict = {"comtype": comtype, "validcoms": validcoms}
|
validcomdict = {"comtype": comtype, "validcoms": validcoms}
|
||||||
filelinelist.append(validcomdict)
|
filelinelist.append(validcomdict)
|
||||||
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:
|
for atlinefound in filelinelist:
|
||||||
|
|
||||||
|
dict_from_file = dict()
|
||||||
|
|
||||||
comtype = atlinefound["comtype"]
|
comtype = atlinefound["comtype"]
|
||||||
validcoms = atlinefound["validcoms"]
|
validcoms = atlinefound["validcoms"]
|
||||||
|
|
||||||
@ -149,6 +147,12 @@ def setup(bot):
|
|||||||
for comtype in ['module', 'nickname', 'rule']:
|
for comtype in ['module', 'nickname', 'rule']:
|
||||||
bot_logging(bot, 'SpiceBot_CommandsQuery', "Found " + str(len(bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys())) + " " + comtype + " commands.")
|
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")
|
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):
|
def commandsquery_register(bot, command_type, validcoms, aliasfor=None):
|
||||||
|
|
||||||
if 'SpiceBot_CommandsQuery' not in bot.memory:
|
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):
|
if not isinstance(validcoms, list):
|
||||||
validcoms = [validcoms]
|
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():
|
if command_type not in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
|
||||||
bot.memory['SpiceBot_CommandsQuery']['commands'][command_type] = dict()
|
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()
|
dict_from_file = dict()
|
||||||
|
|
||||||
|
|||||||
@ -29,8 +29,7 @@ def bot_startup_monologue_commands(bot, trigger):
|
|||||||
availablecomsnum, availablecomsfiles = 0, 0
|
availablecomsnum, availablecomsfiles = 0, 0
|
||||||
for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
|
for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
|
||||||
availablecomsnum += len(bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].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']
|
||||||
availablecomsfiles += bot.memory['SpiceBot_CommandsQuery']['counts'][commandstype]
|
|
||||||
|
|
||||||
bot.memory['SpiceBot_StartupMonologue'].append("There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.")
|
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.")
|
bot_logging(bot, 'SpiceBot_StartupMonologue', "There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user