From c9347b7f54070e94c4a3b2e0b6c8eac1b2e2a15c Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 19 Sep 2019 15:17:20 -0400 Subject: [PATCH] test specified --- sopel_modules/SpiceBot/Prerun.py | 29 ++++++++++++++++++- sopel_modules/SpiceBot/Read.py | 3 ++ .../SpiceBot_Core_Commands/DictComs.py | 14 +-------- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 932cd8d..4525de1 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -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"]: diff --git a/sopel_modules/SpiceBot/Read.py b/sopel_modules/SpiceBot/Read.py index 4e2cc66..e717f53 100644 --- a/sopel_modules/SpiceBot/Read.py +++ b/sopel_modules/SpiceBot/Read.py @@ -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") diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index a6a5e93..eaac311 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -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