test specified

This commit is contained in:
deathbybandaid 2019-09-19 15:17:20 -04:00
parent 540f5f20cd
commit c9347b7f54
3 changed files with 32 additions and 14 deletions

View File

@ -106,6 +106,7 @@ def prerun(t_command_type='module', t_command_subtype=None):
# special handling
botcom = special_handling(botcom)
botcom = updatable_content(bot, botcom, trigger)
args_pass, botcom = trigger_hyphen_arg_handler(bot, trigger, botcom)
@ -434,6 +435,28 @@ def trigger_cant_run(bot, trigger, botcom, message=None):
return False
def updatable_content(bot, botcom, trigger):
# commands that can be updated
if botcom.dict["dict"][botcom.dict["responsekey"]]["updates_enabled"]:
customresponses = []
if botcom.dict["dict"][botcom.dict["responsekey"]]["updates_enabled"] == "shared":
customresponses = botdb.get_nick_value(str(bot.nick), botcom.dict["dict"]["validcoms"][0] + "_" + str(botcom.dict["responsekey"]), 'sayings') or []
elif botcom.dict["dict"][botcom.dict["responsekey"]]["updates_enabled"] == "user":
customresponses = botdb.get_nick_value(str(trigger.nick), botcom.dict["dict"]["validcoms"][0] + "_" + str(botcom.dict["responsekey"]), 'sayings') or []
if not len(customresponses):
if len(botcom.dict["dict"][botcom.dict["responsekey"]]["responses"]):
savevalues = botcom.dict["dict"][botcom.dict["responsekey"]]["responses"]
else:
savevalues = ["Please use --add to add custom content!"]
if botcom.dict["dict"][botcom.dict["responsekey"]]["updates_enabled"] == "shared":
botdb.set_nick_value(str(bot.nick), botcom.dict["dict"]["validcoms"][0] + "_" + str(botcom.dict["responsekey"]), savevalues)
elif botcom.dict["dict"][botcom.dict["responsekey"]]["updates_enabled"] == "user":
botdb.set_nick_value(str(trigger.nick), botcom.dict["dict"]["validcoms"][0] + "_" + str(botcom.dict["responsekey"]), savevalues)
else:
botcom.dict["dict"][botcom.dict["responsekey"]]["responses"] = customresponses
return botcom
def special_handling(botcom):
botcom.dict["responsekey"] = "?default"
@ -504,7 +527,11 @@ def trigger_hyphen_arg_handler(bot, trigger, botcom):
# handle numbered args
elif str(botcom.dict["hyphen_arg"]).isdigit() or botcom.dict["hyphen_arg"] in [-1, 'random']:
botcom.dict["specified"] = botcom.dict["hyphen_arg"]
return True, botcom
if not botcom.dict["dict"][botcom.dict["responsekey"]]["selection_allowed"]:
botmessagelog.messagelog_error(botcom.dict["log_id"], "The " + str(botcom.dict["realcom"]) + " " + str(botcom.dict["responsekey"] or '') + " response list cannot be specified.")
return False, botcom
else:
return True, botcom
elif botcom.dict["hyphen_arg"] in ['check', "test"]:
if botcom.dict["com"].lower() != botcom.dict["realcom"]:

View File

@ -256,6 +256,9 @@ class BotRead():
if dict_from_file[specialcase]["updates_enabled"] not in ["shared", "user"]:
dict_from_file[specialcase]["updates_enabled"] = "shared"
if "selection_allowed" not in list(dict_from_file[specialcase].keys()):
dict_from_file[specialcase]["selection_allowed"] = True
if "?default" in dict_from_file["nonstockoptions"]:
dict_from_file["nonstockoptions"].remove("?default")

View File

@ -38,16 +38,7 @@ def bot_dictcom_process(bot, trigger, botcom):
fulltext = spicemanip(botcom.dict['args'], 0)
# commands that can be updated
if botcom.dict["dict"][botcom.dict["responsekey"]]["updates_enabled"]:
if botcom.dict["dict"][botcom.dict["responsekey"]]["updates_enabled"] == "shared":
SpiceBot.dictcoms.adjust_nick_array(str(SpiceBot.config.nick), 'sayings', botcom.dict["realcom"] + "_" + str(botcom.dict["responsekey"]), botcom.dict["dict"][botcom.dict["responsekey"]]["responses"], 'startup')
botcom.dict["dict"][botcom.dict["responsekey"]]["responses"] = SpiceBot.db.get_nick_value(str(bot.nick), botcom.dict["dict"]["validcoms"][0] + "_" + str(botcom.dict["responsekey"]), 'sayings') or []
elif botcom.dict["dict"][botcom.dict["responsekey"]]["updates_enabled"] == "user":
SpiceBot.dictcoms.adjust_nick_array(str(trigger.nick), 'sayings', botcom.dict["realcom"] + "_" + str(botcom.dict["responsekey"]), botcom.dict["dict"][botcom.dict["responsekey"]]["responses"], 'startup')
botcom.dict["dict"][botcom.dict["responsekey"]]["responses"] = SpiceBot.db.get_nick_value(str(trigger.nick), botcom.dict["dict"]["validcoms"][0] + "_" + str(botcom.dict["responsekey"]), 'sayings') or []
elif botcom.dict["specified"] == 'add':
if botcom.dict["specified"] == 'add':
if fulltext in botcom.dict["dict"][botcom.dict["responsekey"]]["responses"]:
return bot.osd("The following was already in the " + str(botcom.dict["realcom"]) + " " + str(botcom.dict["responsekey"] or '') + " entry list: '" + str(fulltext) + "'")
@ -71,9 +62,6 @@ def bot_dictcom_process(bot, trigger, botcom):
return bot.osd("The following was removed from the " + str(botcom.dict["realcom"]) + " " + str(botcom.dict["responsekey"] or '') + " entry list: '" + str(fulltext) + "'")
elif botcom.dict["specified"] and not botcom.dict["dict"][botcom.dict["responsekey"]]["selection_allowed"]:
return bot.osd("The " + str(botcom.dict["realcom"]) + " " + str(botcom.dict["responsekey"] or '') + " response list cannot be specified.")
botcom.dict["target"] = False
botcom.dict["success"] = True