From 5a62d405315bc9de1d1588155701146a298be2a5 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 09:29:28 -0400 Subject: [PATCH 01/96] add --- sopel_modules/SpiceBot/Read.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Read.py b/sopel_modules/SpiceBot/Read.py index 0b3e33e..79c3ff6 100644 --- a/sopel_modules/SpiceBot/Read.py +++ b/sopel_modules/SpiceBot/Read.py @@ -204,7 +204,7 @@ class BotRead(): if "example" not in list(dict_from_file.keys()): dict_from_file["example"] = "$maincom" # TODO - #if dict_from_file["comtype"] == "nickname": + # if dict_from_file["comtype"] == "nickname": # dict_from_file["example"] = str(botconfig.nick + " $maincom") # else: # dict_from_file["example"] = str(botconfig.core.prefix_list[0] + "$maincom") @@ -220,6 +220,9 @@ class BotRead(): if "privs" not in list(dict_from_file.keys()): dict_from_file["privs"] = [] + if "hardcoded_channel_block" not in list(dict_from_file.keys()): + dict_from_file["hardcoded_channel_block"] = [] + return dict_from_file From c92420bb5d4f759fd810c30354ef1960f75a732f Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 09:36:03 -0400 Subject: [PATCH 02/96] hardcoded block --- sopel_modules/SpiceBot/Prerun.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index aee4d0d..237e86e 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -328,6 +328,10 @@ def trigger_runstatus(bot, trigger): if trigger.sb["hyphen_arg"]: return False + if not trigger.is_privmsg: + if str(trigger.sender).lower() in [x.lower() for x in trigger.sb["dict"]["hardcoded_channel_block"]]: + botmessagelog.messagelog_error(trigger.sb["log_id"], "The " + str(trigger.sb["comtext"]) + " command cannot be used in " + str(trigger.sender) + " because it is hardcoded not to.") + if trigger.sb["runcount"] > 1: # check channel multirun blocks if not trigger.is_privmsg: From 03aefc7c505d35f2b1d1f50f9edfe2dfa402bcf4 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 10:03:51 -0400 Subject: [PATCH 03/96] , botcom --- sopel_modules/SpiceBot/Prerun.py | 218 ++++++------ .../SpiceBot_Core_Commands/BotPrivs.py | 14 +- .../SpiceBot_Core_Commands/Channels.py | 32 +- .../SpiceBot_Core_Commands/Commands.py | 4 +- .../SpiceBot_Core_Commands/CommandsQuery.py | 92 ++--- .../SpiceBot_Core_Commands/DictComs.py | 322 +++++++++--------- sopel_modules/SpiceBot_Core_Commands/Gif.py | 20 +- sopel_modules/SpiceBot_Core_Commands/Logs.py | 10 +- .../SpiceBot_Core_Commands/Messaging.py | 30 +- .../Runtime_Controls.py | 12 +- .../SpiceBot_Core_Commands/Search.py | 24 +- .../SpiceBot_Core_Commands/Sherlock.py | 6 +- 12 files changed, 392 insertions(+), 392 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 237e86e..a951b48 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -87,7 +87,7 @@ def prerun(t_command_type='module', t_command_subtype=None): # split into && groupings and_split = trigger_and_split(trigger_args) - # Create dict listings for trigger.sb + # Create dict listings for botcom.dict argsdict_list = trigger_argsdict_list(argsdict_default, and_split) # Run the function for all splits @@ -95,12 +95,12 @@ def prerun(t_command_type='module', t_command_subtype=None): runcount = 0 for argsdict in argsdict_list: runcount += 1 - trigger.sb = copy.deepcopy(argsdict) + botcom.dict = copy.deepcopy(argsdict) - trigger.sb["runcount"] = runcount + botcom.dict["runcount"] = runcount - trigger.sb["args"], trigger.sb["hyphen_arg"] = trigger_hyphen_args(trigger.sb["args"]) - if not trigger.sb["hyphen_arg"]: + botcom.dict["args"], botcom.dict["hyphen_arg"] = trigger_hyphen_args(botcom.dict["args"]) + if not botcom.dict["hyphen_arg"]: # check if anything prohibits the nick from running the command if trigger_runstatus(bot, trigger): function(bot, trigger, botcom, *args, **kwargs) @@ -165,15 +165,15 @@ def prerun_query(t_command_type='module', t_command_subtype=None): argsdict_default["dict"] = botcommands.get_command_dict("query", 'nickname') - # Create dict listings for trigger.sb + # Create dict listings for botcom.dict argsdict = trigger_argsdict_single(argsdict_default, trigger_args) # Run the function for all splits botmessagelog.messagelog_start(bot, trigger, argsdict_default["log_id"], argsdict_default["realcomtext"]) - trigger.sb = copy.deepcopy(argsdict) + botcom.dict = copy.deepcopy(argsdict) - trigger.sb["runcount"] = 1 + botcom.dict["runcount"] = 1 # check if anything prohibits the nick from running the command if trigger_runstatus_query(bot, trigger): @@ -267,11 +267,11 @@ def trigger_runstatus_query(bot, trigger): return False # Allow permissions for enabling and disabling commands via hyphenargs - if trigger.sb["adminswitch"]: + if botcom.dict["adminswitch"]: if command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): return True else: - botmessagelog.messagelog_error(trigger.sb["log_id"], "The admin switch (-a) is for use by authorized nicks ONLY.") + botmessagelog.messagelog_error(botcom.dict["log_id"], "The admin switch (-a) is for use by authorized nicks ONLY.") return False # don't run commands that are disabled in channels @@ -288,25 +288,25 @@ def trigger_runstatus_query(bot, trigger): # don't run commands that are disabled in channels if not trigger.is_privmsg: channel_disabled_list = botcommands.get_commands_disabled(str(trigger.sender)) - if trigger.sb["realcomref"] in list(channel_disabled_list.keys()): - reason = channel_disabled_list[trigger.sb["realcomref"]]["reason"] - timestamp = channel_disabled_list[trigger.sb["realcomref"]]["timestamp"] - bywhom = channel_disabled_list[trigger.sb["realcomref"]]["disabledby"] - message = "The " + str(trigger.sb["comtext"]) + " command was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) + if botcom.dict["realcomref"] in list(channel_disabled_list.keys()): + reason = channel_disabled_list[botcom.dict["realcomref"]]["reason"] + timestamp = channel_disabled_list[botcom.dict["realcomref"]]["timestamp"] + bywhom = channel_disabled_list[botcom.dict["realcomref"]]["disabledby"] + message = "The " + str(botcom.dict["comtext"]) + " command was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) return trigger_cant_run(bot, trigger, message) # don't run commands that are disabled for specific users nick_disabled_list = botcommands.get_commands_disabled(str(trigger.nick)) - if trigger.sb["realcomref"] in list(nick_disabled_list.keys()): - bywhom = nick_disabled_list[trigger.sb["realcomref"]]["disabledby"] + if botcom.dict["realcomref"] in list(nick_disabled_list.keys()): + bywhom = nick_disabled_list[botcom.dict["realcomref"]]["disabledby"] if botusers.ID(bywhom) != botusers.ID(trigger.nick): - reason = nick_disabled_list[trigger.sb["realcomref"]]["reason"] - timestamp = nick_disabled_list[trigger.sb["realcomref"]]["timestamp"] - message = "The " + str(trigger.sb["comtext"]) + " command was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) + reason = nick_disabled_list[botcom.dict["realcomref"]]["reason"] + timestamp = nick_disabled_list[botcom.dict["realcomref"]]["timestamp"] + message = "The " + str(botcom.dict["comtext"]) + " command was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) return trigger_cant_run(bot, trigger, message) else: - botcommands.unset_command_disabled(trigger.sb["realcomref"], trigger.nick) - botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["comtext"] + " is now enabled for " + str(trigger.nick)) + botcommands.unset_command_disabled(botcom.dict["realcomref"], trigger.nick) + botmessagelog.messagelog_error(botcom.dict["log_id"], botcom.dict["comtext"] + " is now enabled for " + str(trigger.nick)) return True @@ -318,75 +318,75 @@ def trigger_runstatus(bot, trigger): return False # Allow permissions for enabling and disabling commands via hyphenargs - if trigger.sb["adminswitch"]: + if botcom.dict["adminswitch"]: if command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): return True else: - botmessagelog.messagelog_error(trigger.sb["log_id"], "The admin switch (-a) is for use by authorized nicks ONLY.") + botmessagelog.messagelog_error(botcom.dict["log_id"], "The admin switch (-a) is for use by authorized nicks ONLY.") return False - if trigger.sb["hyphen_arg"]: + if botcom.dict["hyphen_arg"]: return False if not trigger.is_privmsg: - if str(trigger.sender).lower() in [x.lower() for x in trigger.sb["dict"]["hardcoded_channel_block"]]: - botmessagelog.messagelog_error(trigger.sb["log_id"], "The " + str(trigger.sb["comtext"]) + " command cannot be used in " + str(trigger.sender) + " because it is hardcoded not to.") + if str(trigger.sender).lower() in [x.lower() for x in botcom.dict["dict"]["hardcoded_channel_block"]]: + botmessagelog.messagelog_error(botcom.dict["log_id"], "The " + str(botcom.dict["comtext"]) + " command cannot be used in " + str(trigger.sender) + " because it is hardcoded not to.") - if trigger.sb["runcount"] > 1: + if botcom.dict["runcount"] > 1: # check channel multirun blocks if not trigger.is_privmsg: channel_disabled_list = botcommands.get_commands_disabled(str(trigger.sender), "multirun") - if trigger.sb["realcomref"] in list(channel_disabled_list.keys()): - reason = channel_disabled_list[trigger.sb["realcomref"]]["reason"] - timestamp = channel_disabled_list[trigger.sb["realcomref"]]["timestamp"] - bywhom = channel_disabled_list[trigger.sb["realcomref"]]["disabledby"] - message = "The " + str(trigger.sb["comtext"]) + " command multirun usage was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) + if botcom.dict["realcomref"] in list(channel_disabled_list.keys()): + reason = channel_disabled_list[botcom.dict["realcomref"]]["reason"] + timestamp = channel_disabled_list[botcom.dict["realcomref"]]["timestamp"] + bywhom = channel_disabled_list[botcom.dict["realcomref"]]["disabledby"] + message = "The " + str(botcom.dict["comtext"]) + " command multirun usage was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) return trigger_cant_run(bot, trigger, message) # don't run commands that are disabled for specific users nick_disabled_list = botcommands.get_commands_disabled(str(trigger.nick), "multirun") - if trigger.sb["realcomref"] in list(nick_disabled_list.keys()): - bywhom = nick_disabled_list[trigger.sb["realcomref"]]["disabledby"] + if botcom.dict["realcomref"] in list(nick_disabled_list.keys()): + bywhom = nick_disabled_list[botcom.dict["realcomref"]]["disabledby"] if botusers.ID(bywhom) != botusers.ID(trigger.nick): - reason = nick_disabled_list[trigger.sb["realcomref"]]["reason"] - timestamp = nick_disabled_list[trigger.sb["realcomref"]]["timestamp"] - message = "The " + str(trigger.sb["comtext"]) + " command was multirun unsage disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) + reason = nick_disabled_list[botcom.dict["realcomref"]]["reason"] + timestamp = nick_disabled_list[botcom.dict["realcomref"]]["timestamp"] + message = "The " + str(botcom.dict["comtext"]) + " command was multirun unsage disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) return trigger_cant_run(bot, trigger, message) else: - botcommands.unset_command_disabled(trigger.sb["realcomref"], trigger.nick, "multirun") - botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["comtext"] + " multirun is now enabled for " + str(trigger.nick)) + botcommands.unset_command_disabled(botcom.dict["realcomref"], trigger.nick, "multirun") + botmessagelog.messagelog_error(botcom.dict["log_id"], botcom.dict["comtext"] + " multirun is now enabled for " + str(trigger.nick)) # don't run commands that are disabled in channels if not trigger.is_privmsg: channel_disabled_list = botcommands.get_commands_disabled(str(trigger.sender)) - if trigger.sb["realcomref"] in list(channel_disabled_list.keys()): - reason = channel_disabled_list[trigger.sb["realcomref"]]["reason"] - timestamp = channel_disabled_list[trigger.sb["realcomref"]]["timestamp"] - bywhom = channel_disabled_list[trigger.sb["realcomref"]]["disabledby"] - message = "The " + str(trigger.sb["comtext"]) + " command was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) + if botcom.dict["realcomref"] in list(channel_disabled_list.keys()): + reason = channel_disabled_list[botcom.dict["realcomref"]]["reason"] + timestamp = channel_disabled_list[botcom.dict["realcomref"]]["timestamp"] + bywhom = channel_disabled_list[botcom.dict["realcomref"]]["disabledby"] + message = "The " + str(botcom.dict["comtext"]) + " command was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) return trigger_cant_run(bot, trigger, message) # don't run commands that are disabled for specific users nick_disabled_list = botcommands.get_commands_disabled(str(trigger.nick)) - if trigger.sb["realcomref"] in list(nick_disabled_list.keys()): - bywhom = nick_disabled_list[trigger.sb["realcomref"]]["disabledby"] + if botcom.dict["realcomref"] in list(nick_disabled_list.keys()): + bywhom = nick_disabled_list[botcom.dict["realcomref"]]["disabledby"] if botusers.ID(bywhom) != botusers.ID(trigger.nick): - reason = nick_disabled_list[trigger.sb["realcomref"]]["reason"] - timestamp = nick_disabled_list[trigger.sb["realcomref"]]["timestamp"] - message = "The " + str(trigger.sb["comtext"]) + " command was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) + reason = nick_disabled_list[botcom.dict["realcomref"]]["reason"] + timestamp = nick_disabled_list[botcom.dict["realcomref"]]["timestamp"] + message = "The " + str(botcom.dict["comtext"]) + " command was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) return trigger_cant_run(bot, trigger, message) else: - botcommands.unset_command_disabled(trigger.sb["realcomref"], trigger.nick) - botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["comtext"] + " is now enabled for " + str(trigger.nick)) + botcommands.unset_command_disabled(botcom.dict["realcomref"], trigger.nick) + botmessagelog.messagelog_error(botcom.dict["log_id"], botcom.dict["comtext"] + " is now enabled for " + str(trigger.nick)) return True def trigger_cant_run(bot, trigger, message=None): if message: - botmessagelog.messagelog_error(trigger.sb["log_id"], message) + botmessagelog.messagelog_error(botcom.dict["log_id"], message) if command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): - botmessagelog.messagelog_error(trigger.sb["log_id"], "You however are authorized to bypass this warning with the (-a) admin switch.") + botmessagelog.messagelog_error(botcom.dict["log_id"], "You however are authorized to bypass this warning with the (-a) admin switch.") return False @@ -423,137 +423,137 @@ def trigger_hyphen_arg_handler(bot, trigger): # Commands that cannot run via privmsg # TODO --check should work for commands that don't exist - if trigger.sb["hyphen_arg"] in ['check']: - if trigger.sb["com"].lower() != trigger.sb["realcom"]: - botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["comtext"] + " is a valid alias command for " + trigger.sb["realcomtext"]) + if botcom.dict["hyphen_arg"] in ['check']: + if botcom.dict["com"].lower() != botcom.dict["realcom"]: + botmessagelog.messagelog(botcom.dict["log_id"], botcom.dict["comtext"] + " is a valid alias command for " + botcom.dict["realcomtext"]) else: - botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["comtext"] + " is a valid command") + botmessagelog.messagelog(botcom.dict["log_id"], botcom.dict["comtext"] + " is a valid command") return - elif trigger.sb["hyphen_arg"] in [ + elif botcom.dict["hyphen_arg"] in [ 'enable', 'disable', 'block', 'unblock', "activate", "deactivate", "on", "off" ]: - target = spicemanip.main(trigger.sb["args"], 1) or trigger.nick + target = spicemanip.main(botcom.dict["args"], 1) or trigger.nick if not target: - if trigger.sb["hyphen_arg"] in ['enable', 'unblock', "activate", "on"]: - botmessagelog.messagelog_error(trigger.sb["log_id"], "Who/Where am I enabling " + str(trigger.sb["comtext"]) + " usage for?") + if botcom.dict["hyphen_arg"] in ['enable', 'unblock', "activate", "on"]: + botmessagelog.messagelog_error(botcom.dict["log_id"], "Who/Where am I enabling " + str(botcom.dict["comtext"]) + " usage for?") else: - botmessagelog.messagelog_error(trigger.sb["log_id"], "Who/Where am I disabling " + str(trigger.sb["comtext"]) + " usage for?") + botmessagelog.messagelog_error(botcom.dict["log_id"], "Who/Where am I disabling " + str(botcom.dict["comtext"]) + " usage for?") return - trigger.sb["args"] = spicemanip.main(trigger.sb["args"], "2+", "list") + botcom.dict["args"] = spicemanip.main(botcom.dict["args"], "2+", "list") if not botdb.check_nick_id(target) and not botchannels.check_channel_bot(target, True): - botmessagelog.messagelog_error(trigger.sb["log_id"], "I don't know who/what " + str(target) + " is.") + botmessagelog.messagelog_error(botcom.dict["log_id"], "I don't know who/what " + str(target) + " is.") return if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): if target != trigger.nick: - if trigger.sb["hyphen_arg"] in ['enable', 'unblock', "activate", "on"]: - botmessagelog.messagelog_error(trigger.sb["log_id"], "I was unable to enable this command for " + str(target) + " due to privilege issues.") + if botcom.dict["hyphen_arg"] in ['enable', 'unblock', "activate", "on"]: + botmessagelog.messagelog_error(botcom.dict["log_id"], "I was unable to enable this command for " + str(target) + " due to privilege issues.") else: - botmessagelog.messagelog_error(trigger.sb["log_id"], "I was unable to disable this command for " + str(target) + " due to privilege issues.") + botmessagelog.messagelog_error(botcom.dict["log_id"], "I was unable to disable this command for " + str(target) + " due to privilege issues.") return - if trigger.sb["hyphen_arg"] in ['enable', 'unblock', "activate", "on"]: + if botcom.dict["hyphen_arg"] in ['enable', 'unblock', "activate", "on"]: - if not botcommands.check_commands_disabled(trigger.sb["realcomref"], target): - botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["comtext"] + " is already enabled for " + str(target)) + if not botcommands.check_commands_disabled(botcom.dict["realcomref"], target): + botmessagelog.messagelog_error(botcom.dict["log_id"], botcom.dict["comtext"] + " is already enabled for " + str(target)) return - botcommands.unset_command_disabled(trigger.sb["realcomref"], target) - botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["comtext"] + " is now enabled for " + str(target)) + botcommands.unset_command_disabled(botcom.dict["realcomref"], target) + botmessagelog.messagelog(botcom.dict["log_id"], botcom.dict["comtext"] + " is now enabled for " + str(target)) return else: - if botcommands.check_commands_disabled(trigger.sb["realcomref"], target): - botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["comtext"] + " is already disabled for " + str(target)) + if botcommands.check_commands_disabled(botcom.dict["realcomref"], target): + botmessagelog.messagelog_error(botcom.dict["log_id"], botcom.dict["comtext"] + " is already disabled for " + str(target)) return - trailingmessage = spicemanip.main(trigger.sb["args"], 0) or "No reason given." + trailingmessage = spicemanip.main(botcom.dict["args"], 0) or "No reason given." timestamp = str(datetime.datetime.utcnow()) - botcommands.set_command_disabled(trigger.sb["realcomref"], target, timestamp, trailingmessage, trigger.nick) - botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["comtext"] + " is now disabled for " + str(target)) + botcommands.set_command_disabled(botcom.dict["realcomref"], target, timestamp, trailingmessage, trigger.nick) + botmessagelog.messagelog(botcom.dict["log_id"], botcom.dict["comtext"] + " is now disabled for " + str(target)) return - if trigger.sb["hyphen_arg"] in ['multirun', 'multiruns']: + if botcom.dict["hyphen_arg"] in ['multirun', 'multiruns']: - onoff = spicemanip.main(trigger.sb["args"], 1) or None + onoff = spicemanip.main(botcom.dict["args"], 1) or None if not onoff or onoff not in ['enable', 'unblock', "activate", "on"]: - botmessagelog.messagelog_error(trigger.sb["log_id"], "Do you want to enable or disable " + str(trigger.sb["comtext"]) + " multirun usage?") + botmessagelog.messagelog_error(botcom.dict["log_id"], "Do you want to enable or disable " + str(botcom.dict["comtext"]) + " multirun usage?") return - target = spicemanip.main(trigger.sb["args"], 1) or trigger.nick + target = spicemanip.main(botcom.dict["args"], 1) or trigger.nick if not target: if onoff in ['enable', 'unblock', "activate", "on"]: - botmessagelog.messagelog_error(trigger.sb["log_id"], "Who/Where am I enabling " + str(trigger.sb["comtext"]) + " multirun usage for?") + botmessagelog.messagelog_error(botcom.dict["log_id"], "Who/Where am I enabling " + str(botcom.dict["comtext"]) + " multirun usage for?") else: - botmessagelog.messagelog_error(trigger.sb["log_id"], "Who/Where am I disabling " + str(trigger.sb["comtext"]) + " multirun usage for?") + botmessagelog.messagelog_error(botcom.dict["log_id"], "Who/Where am I disabling " + str(botcom.dict["comtext"]) + " multirun usage for?") return - trigger.sb["args"] = spicemanip.main(trigger.sb["args"], "2+", "list") + botcom.dict["args"] = spicemanip.main(botcom.dict["args"], "2+", "list") if not botdb.check_nick_id(target) and not botchannels.check_channel_bot(target, True): - botmessagelog.messagelog_error(trigger.sb["log_id"], "I don't know who/what " + str(target) + " is.") + botmessagelog.messagelog_error(botcom.dict["log_id"], "I don't know who/what " + str(target) + " is.") return if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): if target != trigger.nick: if onoff in ['enable', 'unblock', "activate", "on"]: - botmessagelog.messagelog_error(trigger.sb["log_id"], "I was unable to enable multirun usage on " + str(trigger.sb["comtext"]) + " for " + str(target) + " due to privilege issues.") + botmessagelog.messagelog_error(botcom.dict["log_id"], "I was unable to enable multirun usage on " + str(botcom.dict["comtext"]) + " for " + str(target) + " due to privilege issues.") else: - botmessagelog.messagelog_error(trigger.sb["log_id"], "I was unable to enable multirun usage on " + str(trigger.sb["comtext"]) + " for " + str(target) + " due to privilege issues.") + botmessagelog.messagelog_error(botcom.dict["log_id"], "I was unable to enable multirun usage on " + str(botcom.dict["comtext"]) + " for " + str(target) + " due to privilege issues.") return if onoff in ['enable', 'unblock', "activate", "on"]: - if not botcommands.check_commands_disabled(trigger.sb["realcomref"], target, "multirun"): - botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["comtext"] + " multirun is already enabled for " + str(target)) + if not botcommands.check_commands_disabled(botcom.dict["realcomref"], target, "multirun"): + botmessagelog.messagelog_error(botcom.dict["log_id"], botcom.dict["comtext"] + " multirun is already enabled for " + str(target)) return - botcommands.unset_command_disabled(trigger.sb["realcomref"], target, "multirun") - botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["comtext"] + " multirun is now enabled for " + str(target)) + botcommands.unset_command_disabled(botcom.dict["realcomref"], target, "multirun") + botmessagelog.messagelog(botcom.dict["log_id"], botcom.dict["comtext"] + " multirun is now enabled for " + str(target)) return else: - if botcommands.check_commands_disabled(trigger.sb["realcomref"], target, "multirun"): - botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["comtext"] + " multirun is already disabled for " + str(target)) + if botcommands.check_commands_disabled(botcom.dict["realcomref"], target, "multirun"): + botmessagelog.messagelog_error(botcom.dict["log_id"], botcom.dict["comtext"] + " multirun is already disabled for " + str(target)) return - trailingmessage = spicemanip.main(trigger.sb["args"], 0) or "No reason given." + trailingmessage = spicemanip.main(botcom.dict["args"], 0) or "No reason given." timestamp = str(datetime.datetime.utcnow()) - botcommands.set_command_disabled(trigger.sb["realcomref"], target, timestamp, trailingmessage, trigger.nick, "multirun") - botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["comtext"] + " multirun is now disabled for " + str(target)) + botcommands.set_command_disabled(botcom.dict["realcomref"], target, timestamp, trailingmessage, trigger.nick, "multirun") + botmessagelog.messagelog(botcom.dict["log_id"], botcom.dict["comtext"] + " multirun is now disabled for " + str(target)) return - elif trigger.sb["hyphen_arg"] in ['example', 'usage']: - botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["comtext"] + ": " + str(trigger.sb["dict"]["example"])) + elif botcom.dict["hyphen_arg"] in ['example', 'usage']: + botmessagelog.messagelog(botcom.dict["log_id"], botcom.dict["comtext"] + ": " + str(botcom.dict["dict"]["example"])) return - elif trigger.sb["hyphen_arg"] in ['filename', 'filepath']: - botmessagelog.messagelog(trigger.sb["log_id"], "The " + str(trigger.sb["comtext"]) + " file is located at " + str(trigger.sb["dict"][trigger.sb["hyphen_arg"]])) + elif botcom.dict["hyphen_arg"] in ['filename', 'filepath']: + botmessagelog.messagelog(botcom.dict["log_id"], "The " + str(botcom.dict["comtext"]) + " file is located at " + str(botcom.dict["dict"][botcom.dict["hyphen_arg"]])) return - elif trigger.sb["hyphen_arg"] in ['foldername', 'folderpath']: - botmessagelog.messagelog(trigger.sb["log_id"], "The " + str(trigger.sb["comtext"]) + " folder is located at " + str(trigger.sb["dict"][trigger.sb["hyphen_arg"]])) + elif botcom.dict["hyphen_arg"] in ['foldername', 'folderpath']: + botmessagelog.messagelog(botcom.dict["log_id"], "The " + str(botcom.dict["comtext"]) + " folder is located at " + str(botcom.dict["dict"][botcom.dict["hyphen_arg"]])) return - elif trigger.sb["hyphen_arg"] in ['author']: - botmessagelog.messagelog(trigger.sb["log_id"], "The author of the " + str(trigger.sb["comtext"]) + " command is " + trigger.sb["dict"]["author"] + ".") + elif botcom.dict["hyphen_arg"] in ['author']: + botmessagelog.messagelog(botcom.dict["log_id"], "The author of the " + str(botcom.dict["comtext"]) + " command is " + botcom.dict["dict"]["author"] + ".") return - elif trigger.sb["hyphen_arg"] in ['contribs', 'contrib', "contributors"]: - botmessagelog.messagelog(trigger.sb["log_id"], "The contributors of the " + str(trigger.sb["comtext"]) + " command are " + spicemanip.main(trigger.sb["dict"]["contributors"], "andlist") + ".") + elif botcom.dict["hyphen_arg"] in ['contribs', 'contrib', "contributors"]: + botmessagelog.messagelog(botcom.dict["log_id"], "The contributors of the " + str(botcom.dict["comtext"]) + " command are " + spicemanip.main(botcom.dict["dict"]["contributors"], "andlist") + ".") return - elif trigger.sb["hyphen_arg"] in ['alias', 'aliases']: - botmessagelog.messagelog(trigger.sb["log_id"], "The alaises of the " + str(trigger.sb["comtext"]) + " command are " + spicemanip.main(trigger.sb["dict"]["validcoms"], "andlist") + ".") + elif botcom.dict["hyphen_arg"] in ['alias', 'aliases']: + botmessagelog.messagelog(botcom.dict["log_id"], "The alaises of the " + str(botcom.dict["comtext"]) + " command are " + spicemanip.main(botcom.dict["dict"]["validcoms"], "andlist") + ".") return return diff --git a/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py b/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py index be1b25f..f67a7c8 100644 --- a/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py +++ b/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py @@ -12,19 +12,19 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('owners', 'owner') def bot_command_owners(bot, trigger, botcom): - bot_command_process(bot, trigger) + bot_command_process(bot, trigger, botcom) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('admins', 'admin') def bot_command_admins(bot, trigger, botcom): - bot_command_process(bot, trigger) + bot_command_process(bot, trigger, botcom) -def bot_command_process(bot, trigger): +def bot_command_process(bot, trigger, botcom): - if not trigger.sb['com'].endswith("s"): - trigger.sb['com'] = str(trigger.sb['com'] + "s") + if not botcom.dict['com'].endswith("s"): + botcom.dict['com'] = str(botcom.dict['com'] + "s") - privlist = spicemanip.main(SpiceBot.bot_privs(trigger.sb['com']), 'andlist') - bot.osd(str(bot.nick) + " " + trigger.sb['com'] + ": " + privlist) + privlist = spicemanip.main(SpiceBot.bot_privs(botcom.dict['com']), 'andlist') + bot.osd(str(bot.nick) + " " + botcom.dict['com'] + ": " + privlist) diff --git a/sopel_modules/SpiceBot_Core_Commands/Channels.py b/sopel_modules/SpiceBot_Core_Commands/Channels.py index e7c0814..8a5acb3 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Channels.py +++ b/sopel_modules/SpiceBot_Core_Commands/Channels.py @@ -14,12 +14,12 @@ import sopel_modules.SpiceBot as SpiceBot @sopel.module.nickname_commands('channels', 'channel') def nickname_comand_channels(bot, trigger, botcom): - if not len(trigger.sb['args']): + if not len(botcom.dict['args']): commandused = 'list' else: - commandused = spicemanip.main(trigger.sb['args'], 1).lower() + commandused = spicemanip.main(botcom.dict['args'], 1).lower() - trigger.sb['args'] = spicemanip.main(trigger.sb['args'], '2+', 'list') + botcom.dict['args'] = spicemanip.main(botcom.dict['args'], '2+', 'list') if commandused == 'list': botcount = len(list(bot.channels.keys())) @@ -48,7 +48,7 @@ def nickname_comand_channels(bot, trigger, botcom): elif commandused == 'update': if not trigger.admin: - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "You do not have permission to update the channel listing.") + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "You do not have permission to update the channel listing.") return SpiceBot.channels.bot_part_empty(bot) SpiceBot.channels.channel_list_request(bot) @@ -62,12 +62,12 @@ def nickname_comand_channels(bot, trigger, botcom): return elif commandused == 'topic': - if not len(trigger.sb['args']): - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "Channel name input missing.") + if not len(botcom.dict['args']): + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel name input missing.") return - channel = spicemanip.main(trigger.sb['args'], 1) + channel = spicemanip.main(botcom.dict['args'], 1) if not SpiceBot.inlist(channel.lower(), list(SpiceBot.channels.dict['list'].keys())): - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "Channel name {} not valid.".format(channel)) + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel name {} not valid.".format(channel)) return topic = SpiceBot.channels.dict['list'][channel.lower()]['topic'] channel = SpiceBot.channels.dict['list'][channel.lower()]['name'] @@ -75,19 +75,19 @@ def nickname_comand_channels(bot, trigger, botcom): return if commandused.upper() in ['OP', 'HOP', 'VOICE', 'OWNER', 'ADMIN']: - if not len(trigger.sb['args']): + if not len(botcom.dict['args']): if trigger.is_privmsg: - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "Channel name required.") + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel name required.") return else: channel = trigger.sender else: - channel = spicemanip.main(trigger.sb['args'], 1) + channel = spicemanip.main(botcom.dict['args'], 1) if not SpiceBot.inlist(channel.lower(), list(SpiceBot.channels.dict['list'].keys())): - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "Channel name {} not valid.".format(channel)) + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel name {} not valid.".format(channel)) return if not SpiceBot.inlist(channel.lower(), list(bot.channels.keys())): - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "I need to be in {} to see nick privileges.".format(channel)) + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "I need to be in {} to see nick privileges.".format(channel)) return privlist = SpiceBot.channel_privs(bot, channel, commandused.upper()) @@ -102,12 +102,12 @@ def nickname_comand_channels(bot, trigger, botcom): # Users List if commandused == 'users': - channel = spicemanip.main(trigger.sb['args'], 1) + channel = spicemanip.main(botcom.dict['args'], 1) if not SpiceBot.inlist(channel.lower(), list(SpiceBot.channels.dict['list'].keys())): - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "Channel name {} not valid.".format(channel)) + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel name {} not valid.".format(channel)) return if not SpiceBot.inlist(channel.lower(), list(bot.channels.keys())): - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "I need to be in {} to see user list.".format(channel)) + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "I need to be in {} to see user list.".format(channel)) return dispmsg = [] if not len(list(bot.channels[channel].privileges.keys())): diff --git a/sopel_modules/SpiceBot_Core_Commands/Commands.py b/sopel_modules/SpiceBot_Core_Commands/Commands.py index 195706c..624047d 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Commands.py +++ b/sopel_modules/SpiceBot_Core_Commands/Commands.py @@ -18,10 +18,10 @@ import sopel_modules.SpiceBot as SpiceBot @sopel.module.nickname_commands('commands', 'command') def nickname_comand_commands(bot, trigger, botcom): - if not len(trigger.sb['args']): + if not len(botcom.dict['args']): commandused = 'list' else: - commandused = spicemanip.main(trigger.sb['args'], 1).lower() + commandused = spicemanip.main(botcom.dict['args'], 1).lower() if commandused == 'list': availablecomsnum, availablecomsfiles = 0, [] diff --git a/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py b/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py index 3091f31..d9c9e73 100644 --- a/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py +++ b/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py @@ -23,14 +23,14 @@ def query_trigger(bot, trigger, botcom): def query_detection_nick(bot, trigger, botcom): # command issued, check if valid - if not trigger.sb['com'] or not len(trigger.sb['com']): + if not botcom.dict['com'] or not len(botcom.dict['com']): return - if not trigger.sb['com'][0] == bot.config.SpiceBot_Commands.query_prefix: + if not botcom.dict['com'][0] == bot.config.SpiceBot_Commands.query_prefix: return - trigger.sb['com'] = trigger.sb['com'][1:] + botcom.dict['com'] = botcom.dict['com'][1:] - if not SpiceBot.letters_in_string(trigger.sb['com']): + if not SpiceBot.letters_in_string(botcom.dict['com']): return commands_list = dict() @@ -38,49 +38,49 @@ def query_detection_nick(bot, trigger, botcom): if com not in list(commands_list.keys()): commands_list[com] = SpiceBot.commands.dict['commands']['nickname'][com] - if trigger.sb['com'].endswith("+"): + if botcom.dict['com'].endswith("+"): - trigger.sb['com'] = trigger.sb['com'][:-1] - if not trigger.sb['com'] or not len(trigger.sb['com']): + botcom.dict['com'] = botcom.dict['com'][:-1] + if not botcom.dict['com'] or not len(botcom.dict['com']): return - if trigger.sb['com'].lower() not in list(commands_list.keys()): - dispmsg = ["Cannot find any alias " + bot.nick + " commands: No valid commands match " + str(trigger.sb['com']) + "."] - closestmatches = SpiceBot.similar_list(trigger.sb['com'], list(commands_list.keys()), 10, 'reverse') + if botcom.dict['com'].lower() not in list(commands_list.keys()): + dispmsg = ["Cannot find any alias " + bot.nick + " commands: No valid commands match " + str(botcom.dict['com']) + "."] + closestmatches = SpiceBot.similar_list(botcom.dict['com'], list(commands_list.keys()), 10, 'reverse') if len(closestmatches): - dispmsg.append("The following " + bot.nick + " commands match " + str(trigger.sb['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".") + dispmsg.append("The following " + bot.nick + " commands match " + str(botcom.dict['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".") bot.osd(dispmsg, trigger.nick, 'notice') return - realcom = trigger.sb['com'] - if "aliasfor" in list(commands_list[trigger.sb['com']].keys()): - realcom = commands_list[trigger.sb['com']]["aliasfor"] + realcom = botcom.dict['com'] + if "aliasfor" in list(commands_list[botcom.dict['com']].keys()): + realcom = commands_list[botcom.dict['com']]["aliasfor"] validcomlist = commands_list[realcom]["validcoms"] - bot.osd("The following " + bot.nick + " commands match " + str(trigger.sb['com']) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick, 'notice') + bot.osd("The following " + bot.nick + " commands match " + str(botcom.dict['com']) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick, 'notice') return - if trigger.sb['com'].endswith(bot.config.SpiceBot_Commands.query_prefix): + if botcom.dict['com'].endswith(bot.config.SpiceBot_Commands.query_prefix): - trigger.sb['com'] = trigger.sb['com'][:-1] - if not trigger.sb['com'] or not len(trigger.sb['com']): + botcom.dict['com'] = botcom.dict['com'][:-1] + if not botcom.dict['com'] or not len(botcom.dict['com']): return - closestmatches = SpiceBot.similar_list(trigger.sb['com'], list(commands_list.keys()), 10, 'reverse') + closestmatches = SpiceBot.similar_list(botcom.dict['com'], list(commands_list.keys()), 10, 'reverse') if not len(closestmatches): - bot.osd("Cannot find any similar " + bot.nick + " commands for " + str(trigger.sb['com']) + ".", trigger.nick, 'notice') + bot.osd("Cannot find any similar " + bot.nick + " commands for " + str(botcom.dict['com']) + ".", trigger.nick, 'notice') else: - bot.osd("The following " + bot.nick + " commands may match " + str(trigger.sb['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick, 'notice') + bot.osd("The following " + bot.nick + " commands may match " + str(botcom.dict['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick, 'notice') return commandlist = [] for command in list(commands_list.keys()): - if command.lower().startswith(str(trigger.sb['com']).lower()): + if command.lower().startswith(str(botcom.dict['com']).lower()): commandlist.append(command) if not len(commandlist): - bot.osd("No " + bot.nick + " commands start with " + str(trigger.sb['com']) + ".", trigger.nick, 'notice') + bot.osd("No " + bot.nick + " commands start with " + str(botcom.dict['com']) + ".", trigger.nick, 'notice') else: - bot.osd("The following " + bot.nick + " commands start with " + str(trigger.sb['com']) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick, 'notice') + bot.osd("The following " + bot.nick + " commands start with " + str(botcom.dict['com']) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick, 'notice') @SpiceBot.prerun_query('module', 'module') @@ -88,10 +88,10 @@ def query_detection_nick(bot, trigger, botcom): def query_detection(bot, trigger, botcom): # command issued, check if valid - if not trigger.sb['com'] or not len(trigger.sb['com']): + if not botcom.dict['com'] or not len(botcom.dict['com']): return - if not SpiceBot.letters_in_string(trigger.sb['com']): + if not SpiceBot.letters_in_string(botcom.dict['com']): return commands_list = dict() @@ -101,46 +101,46 @@ def query_detection(bot, trigger, botcom): if com not in list(commands_list.keys()): commands_list[com] = SpiceBot.commands.dict['commands'][commandstype][com] - if trigger.sb['com'][:-1] == "+": + if botcom.dict['com'][:-1] == "+": - trigger.sb['com'] = trigger.sb['com'][:-1] - if not trigger.sb['com'] or not len(trigger.sb['com']): + botcom.dict['com'] = botcom.dict['com'][:-1] + if not botcom.dict['com'] or not len(botcom.dict['com']): return - if trigger.sb['com'].lower() not in list(commands_list.keys()): - dispmsg = ["Cannot find any alias commands: No valid commands match " + str(trigger.sb['com']) + "."] - closestmatches = SpiceBot.similar_list(trigger.sb['com'], list(commands_list.keys()), 10, 'reverse') + if botcom.dict['com'].lower() not in list(commands_list.keys()): + dispmsg = ["Cannot find any alias commands: No valid commands match " + str(botcom.dict['com']) + "."] + closestmatches = SpiceBot.similar_list(botcom.dict['com'], list(commands_list.keys()), 10, 'reverse') if len(closestmatches): - dispmsg.append("The following commands match " + str(trigger.sb['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".") + dispmsg.append("The following commands match " + str(botcom.dict['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".") bot.osd(dispmsg, trigger.nick, 'notice') return - realcom = trigger.sb['com'] - if "aliasfor" in list(commands_list[trigger.sb['com']].keys()): - realcom = commands_list[trigger.sb['com']]["aliasfor"] + realcom = botcom.dict['com'] + if "aliasfor" in list(commands_list[botcom.dict['com']].keys()): + realcom = commands_list[botcom.dict['com']]["aliasfor"] validcomlist = commands_list[realcom]["validcoms"] - bot.osd("The following commands match " + str(trigger.sb['com']) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick, 'notice') + bot.osd("The following commands match " + str(botcom.dict['com']) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick, 'notice') return - if trigger.sb['com'][:-1] == "?": + if botcom.dict['com'][:-1] == "?": - trigger.sb['com'] = trigger.sb['com'][:-1] - if not trigger.sb['com'] or not len(trigger.sb['com']): + botcom.dict['com'] = botcom.dict['com'][:-1] + if not botcom.dict['com'] or not len(botcom.dict['com']): return - closestmatches = SpiceBot.similar_list(trigger.sb['com'], list(commands_list.keys()), 10, 'reverse') + closestmatches = SpiceBot.similar_list(botcom.dict['com'], list(commands_list.keys()), 10, 'reverse') if not len(closestmatches): - bot.osd("Cannot find any similar commands for " + str(trigger.sb['com']) + ".", trigger.nick, 'notice') + bot.osd("Cannot find any similar commands for " + str(botcom.dict['com']) + ".", trigger.nick, 'notice') else: - bot.osd("The following commands may match " + str(trigger.sb['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick, 'notice') + bot.osd("The following commands may match " + str(botcom.dict['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick, 'notice') return commandlist = [] for command in list(commands_list.keys()): - if command.lower().startswith(str(trigger.sb['com']).lower()): + if command.lower().startswith(str(botcom.dict['com']).lower()): commandlist.append(command) if not len(commandlist): - bot.osd("No commands start with " + str(trigger.sb['com']) + ".", trigger.nick, 'notice') + bot.osd("No commands start with " + str(botcom.dict['com']) + ".", trigger.nick, 'notice') else: - bot.osd("The following commands start with " + str(trigger.sb['com']) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick, 'notice') + bot.osd("The following commands start with " + str(botcom.dict['com']) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick, 'notice') diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index f83d454..4d1b529 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -20,78 +20,78 @@ import time @sopel.module.commands('(.*)') def command_dictcom(bot, trigger, botcom): - if trigger.sb['com'] not in list(SpiceBot.commands.dict['commands']["dictcom"].keys()): + if botcom.dict['com'] not in list(SpiceBot.commands.dict['commands']["dictcom"].keys()): return - bot_dictcom_process(bot, trigger) + bot_dictcom_process(bot, trigger, botcom) return time.time() -def bot_dictcom_process(bot, trigger): +def bot_dictcom_process(bot, trigger, botcom): # use the default key, unless otherwise specified - trigger.sb["responsekey"] = "?default" + botcom.dict["responsekey"] = "?default" # handling for special cases - posscom = spicemanip.main(trigger.sb['args'], 1) - if posscom.lower() in [command.lower() for command in trigger.sb["dict"].keys()]: - for command in trigger.sb["dict"].keys(): + posscom = spicemanip.main(botcom.dict['args'], 1) + if posscom.lower() in [command.lower() for command in botcom.dict["dict"].keys()]: + for command in botcom.dict["dict"].keys(): if command.lower() == posscom.lower(): posscom = command - trigger.sb["responsekey"] = posscom - trigger.sb['args'] = spicemanip.main(trigger.sb['args'], '2+', 'list') - trigger.sb["dict"][trigger.sb["responsekey"]]["type"] = trigger.sb["dict"][trigger.sb["responsekey"]]["type"] + botcom.dict["responsekey"] = posscom + botcom.dict['args'] = spicemanip.main(botcom.dict['args'], '2+', 'list') + botcom.dict["dict"][botcom.dict["responsekey"]]["type"] = botcom.dict["dict"][botcom.dict["responsekey"]]["type"] - trigger.sb["nonstockoptions"] = [] - for command in trigger.sb["dict"].keys(): + botcom.dict["nonstockoptions"] = [] + for command in botcom.dict["dict"].keys(): if command not in ["?default", "validcoms", "type", "hardcoded_channel_block"]: - trigger.sb["nonstockoptions"].append(command) + botcom.dict["nonstockoptions"].append(command) # This allows users to specify which reply by number by using an ! and a digit (first or last in string) validspecifides = ['last', 'random', 'count', 'view', 'add', 'del', 'remove', 'special'] - trigger.sb["specified"] = None - argone = spicemanip.main(trigger.sb['args'], 1) + botcom.dict["specified"] = None + argone = spicemanip.main(botcom.dict['args'], 1) if str(argone).startswith("--") and len(str(argone)) > 2: if str(argone[2:]).isdigit(): - trigger.sb["specified"] = int(argone[2:]) + botcom.dict["specified"] = int(argone[2:]) elif SpiceBot.inlist(str(argone[2:]), validspecifides): - trigger.sb["specified"] = str(argone[2:]).lower() - elif SpiceBot.inlist(str(argone[2:]), trigger.sb["nonstockoptions"]): - trigger.sb["specified"] = str(argone[2:]).lower() - trigger.sb["responsekey"] = trigger.sb["specified"] + botcom.dict["specified"] = str(argone[2:]).lower() + elif SpiceBot.inlist(str(argone[2:]), botcom.dict["nonstockoptions"]): + botcom.dict["specified"] = str(argone[2:]).lower() + botcom.dict["responsekey"] = botcom.dict["specified"] else: try: - trigger.sb["specified"] = w2n.word_to_num(str(argone[1:])) - trigger.sb["specified"] = int(trigger.sb["specified"]) + botcom.dict["specified"] = w2n.word_to_num(str(argone[1:])) + botcom.dict["specified"] = int(botcom.dict["specified"]) except ValueError: - trigger.sb["specified"] = None - if trigger.sb["specified"]: - trigger.sb['args'] = spicemanip.main(trigger.sb['args'], '2+', 'list') + botcom.dict["specified"] = None + if botcom.dict["specified"]: + botcom.dict['args'] = spicemanip.main(botcom.dict['args'], '2+', 'list') # commands that can be updated - if trigger.sb["dict"][trigger.sb["responsekey"]]["updates_enabled"]: - if trigger.sb["dict"][trigger.sb["responsekey"]]["updates_enabled"] == "shared": - SpiceBot.dictcoms.adjust_nick_array(str(SpiceBot.config.nick), 'sayings', trigger.sb["realcom"] + "_" + str(trigger.sb["responsekey"]), trigger.sb["dict"][trigger.sb["responsekey"]]["responses"], 'startup') - trigger.sb["dict"][trigger.sb["responsekey"]]["responses"] = SpiceBot.db.get_nick_value(str(bot.nick), trigger.sb["dict"]["validcoms"][0] + "_" + str(trigger.sb["responsekey"]), 'sayings') or [] - elif trigger.sb["dict"][trigger.sb["responsekey"]]["updates_enabled"] == "user": - SpiceBot.dictcoms.adjust_nick_array(str(trigger.nick), 'sayings', trigger.sb["realcom"] + "_" + str(trigger.sb["responsekey"]), trigger.sb["dict"][trigger.sb["responsekey"]]["responses"], 'startup') - trigger.sb["dict"][trigger.sb["responsekey"]]["responses"] = SpiceBot.db.get_nick_value(str(trigger.nick), trigger.sb["dict"]["validcoms"][0] + "_" + str(trigger.sb["responsekey"]), 'sayings') or [] + 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 [] - if trigger.sb["specified"] == 'special': - nonstockoptions = spicemanip.main(trigger.sb["nonstockoptions"], "andlist") - return bot.osd("The special options for " + str(trigger.sb["realcom"]) + " command include: " + str(nonstockoptions) + ".") + if botcom.dict["specified"] == 'special': + nonstockoptions = spicemanip.main(botcom.dict["nonstockoptions"], "andlist") + return bot.osd("The special options for " + str(botcom.dict["realcom"]) + " command include: " + str(nonstockoptions) + ".") - elif trigger.sb["specified"] == 'count': - return bot.osd("The " + str(trigger.sb["realcom"]) + " " + str(trigger.sb["responsekey"] or '') + " command has " + str(len(trigger.sb["dict"][trigger.sb["responsekey"]]["responses"])) + " entries.") + elif botcom.dict["specified"] == 'count': + return bot.osd("The " + str(botcom.dict["realcom"]) + " " + str(botcom.dict["responsekey"] or '') + " command has " + str(len(botcom.dict["dict"][botcom.dict["responsekey"]]["responses"])) + " entries.") - elif trigger.sb["specified"] == 'view': - if trigger.sb["dict"][trigger.sb["responsekey"]]["responses"] == []: - return bot.osd("The " + str(trigger.sb["realcom"]) + " " + str(trigger.sb["responsekey"] or '') + " command appears to have no entries!") + elif botcom.dict["specified"] == 'view': + if botcom.dict["dict"][botcom.dict["responsekey"]]["responses"] == []: + return bot.osd("The " + str(botcom.dict["realcom"]) + " " + str(botcom.dict["responsekey"] or '') + " command appears to have no entries!") else: - bot.osd("The " + str(trigger.sb["realcom"]) + " " + str(trigger.sb["responsekey"] or '') + " command contains:", trigger.nick, 'notice') + bot.osd("The " + str(botcom.dict["realcom"]) + " " + str(botcom.dict["responsekey"] or '') + " command contains:", trigger.nick, 'notice') listnumb, relist = 1, [] - for item in trigger.sb["dict"][trigger.sb["responsekey"]]["responses"]: + for item in botcom.dict["dict"][botcom.dict["responsekey"]]["responses"]: if isinstance(item, dict): relist.append(str("[#" + str(listnumb) + "] COMPLEX dict Entry")) elif isinstance(item, list): @@ -101,143 +101,143 @@ def bot_dictcom_process(bot, trigger): bot.osd(relist, trigger.nick) return - elif trigger.sb["specified"] == 'add': + elif botcom.dict["specified"] == 'add': - if not trigger.sb["dict"][trigger.sb["responsekey"]]["updates_enabled"]: - return bot.osd("The " + str(trigger.sb["realcom"]) + " " + str(trigger.sb["responsekey"] or '') + " entry list cannot be updated.") + if not botcom.dict["dict"][botcom.dict["responsekey"]]["updates_enabled"]: + return bot.osd("The " + str(botcom.dict["realcom"]) + " " + str(botcom.dict["responsekey"] or '') + " entry list cannot be updated.") - fulltext = spicemanip.main(trigger.sb['args'], 0) + fulltext = spicemanip.main(botcom.dict['args'], 0) if not fulltext: - return bot.osd("What would you like to add to the " + str(trigger.sb["realcom"]) + " " + str(trigger.sb["responsekey"] or '') + " entry list?") + return bot.osd("What would you like to add to the " + str(botcom.dict["realcom"]) + " " + str(botcom.dict["responsekey"] or '') + " entry list?") - if fulltext in trigger.sb["dict"][trigger.sb["responsekey"]]["responses"]: - return bot.osd("The following was already in the " + str(trigger.sb["realcom"]) + " " + str(trigger.sb["responsekey"] or '') + " entry list: '" + str(fulltext) + "'") + 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) + "'") - if trigger.sb["dict"][trigger.sb["responsekey"]]["updates_enabled"] == "shared": - SpiceBot.dictcoms.adjust_nick_array(str(bot.nick), 'sayings', trigger.sb["realcom"] + "_" + str(trigger.sb["responsekey"]), fulltext, trigger.sb["specified"]) - elif trigger.sb["dict"][trigger.sb["responsekey"]]["updates_enabled"] == "user": - SpiceBot.dictcoms.adjust_nick_array(str(trigger.nick), 'sayings', trigger.sb["realcom"] + "_" + str(trigger.sb["responsekey"]), fulltext, trigger.sb["specified"]) + if botcom.dict["dict"][botcom.dict["responsekey"]]["updates_enabled"] == "shared": + SpiceBot.dictcoms.adjust_nick_array(str(bot.nick), 'sayings', botcom.dict["realcom"] + "_" + str(botcom.dict["responsekey"]), fulltext, botcom.dict["specified"]) + 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"]), fulltext, botcom.dict["specified"]) - return bot.osd("The following was added to the " + str(trigger.sb["realcom"]) + " " + str(trigger.sb["responsekey"] or '') + " entry list: '" + str(fulltext) + "'") + return bot.osd("The following was added to the " + str(botcom.dict["realcom"]) + " " + str(botcom.dict["responsekey"] or '') + " entry list: '" + str(fulltext) + "'") - elif trigger.sb["specified"] in ['del', 'remove']: + elif botcom.dict["specified"] in ['del', 'remove']: - if not trigger.sb["dict"][trigger.sb["responsekey"]]["updates_enabled"]: - return bot.osd("The " + str(trigger.sb["realcom"]) + " " + str(trigger.sb["responsekey"] or '') + " entry list cannot be updated.") + if not botcom.dict["dict"][botcom.dict["responsekey"]]["updates_enabled"]: + return bot.osd("The " + str(botcom.dict["realcom"]) + " " + str(botcom.dict["responsekey"] or '') + " entry list cannot be updated.") - fulltext = spicemanip.main(trigger.sb['args'], 0) + fulltext = spicemanip.main(botcom.dict['args'], 0) if not fulltext: - return bot.osd("What would you like to remove from the " + str(trigger.sb["realcom"]) + " " + str(trigger.sb["responsekey"] or '') + " entry list?") + return bot.osd("What would you like to remove from the " + str(botcom.dict["realcom"]) + " " + str(botcom.dict["responsekey"] or '') + " entry list?") - if fulltext not in trigger.sb["dict"][trigger.sb["responsekey"]]["responses"]: - return bot.osd("The following was already not in the " + str(trigger.sb["realcom"]) + " " + str(trigger.sb["responsekey"] or '') + " entry list: '" + str(fulltext) + "'") + if fulltext not in botcom.dict["dict"][botcom.dict["responsekey"]]["responses"]: + return bot.osd("The following was already not in the " + str(botcom.dict["realcom"]) + " " + str(botcom.dict["responsekey"] or '') + " entry list: '" + str(fulltext) + "'") - if trigger.sb["dict"][trigger.sb["responsekey"]]["updates_enabled"] == "shared": - SpiceBot.dictcoms.adjust_nick_array(str(bot.nick), 'sayings', trigger.sb["realcom"] + "_" + str(trigger.sb["responsekey"]), fulltext, trigger.sb["specified"]) - elif trigger.sb["dict"][trigger.sb["responsekey"]]["updates_enabled"] == "user": - SpiceBot.dictcoms.adjust_nick_array(str(trigger.nick), 'sayings', trigger.sb["realcom"] + "_" + str(trigger.sb["responsekey"]), fulltext, trigger.sb["specified"]) + if botcom.dict["dict"][botcom.dict["responsekey"]]["updates_enabled"] == "shared": + SpiceBot.dictcoms.adjust_nick_array(str(bot.nick), 'sayings', botcom.dict["realcom"] + "_" + str(botcom.dict["responsekey"]), fulltext, botcom.dict["specified"]) + 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"]), fulltext, botcom.dict["specified"]) - return bot.osd("The following was removed from the " + str(trigger.sb["realcom"]) + " " + str(trigger.sb["responsekey"] or '') + " entry list: '" + str(fulltext) + "'") + return bot.osd("The following was removed from the " + str(botcom.dict["realcom"]) + " " + str(botcom.dict["responsekey"] or '') + " entry list: '" + str(fulltext) + "'") - elif trigger.sb["specified"] and not trigger.sb["dict"][trigger.sb["responsekey"]]["selection_allowed"]: - return bot.osd("The " + str(trigger.sb["realcom"]) + " " + str(trigger.sb["responsekey"] or '') + " response list cannot be specified.") + 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.") - trigger.sb["target"] = False + botcom.dict["target"] = False - trigger.sb["success"] = True - if trigger.sb["dict"][trigger.sb["responsekey"]]["type"] in ['simple', 'fillintheblank', "target", 'targetplusreason', 'sayings', "readfromfile", "readfromurl", "ascii_art", "translate", "responses"]: + botcom.dict["success"] = True + if botcom.dict["dict"][botcom.dict["responsekey"]]["type"] in ['simple', 'fillintheblank', "target", 'targetplusreason', 'sayings', "readfromfile", "readfromurl", "ascii_art", "translate", "responses"]: return bot_dictcom_responses(bot, trigger) else: - command_function_run = str('bot_dictcom_' + trigger.sb["dict"][trigger.sb["responsekey"]]["type"] + '(bot, trigger)') + command_function_run = str('bot_dictcom_' + botcom.dict["dict"][botcom.dict["responsekey"]]["type"] + '(bot, trigger, botcom)') eval(command_function_run) -def bot_dictcom_responses(bot, trigger): +def bot_dictcom_responses(bot, trigger, botcom): commandrunconsensus = [] reaction = False # A target is required - if trigger.sb["dict"][trigger.sb["responsekey"]]["target_required"]: + if botcom.dict["dict"][botcom.dict["responsekey"]]["target_required"]: # try first term as a target - posstarget = spicemanip.main(trigger.sb['args'], 1) or 0 - targetbypass = trigger.sb["dict"][trigger.sb["responsekey"]]["target_bypass"] + posstarget = spicemanip.main(botcom.dict['args'], 1) or 0 + targetbypass = botcom.dict["dict"][botcom.dict["responsekey"]]["target_bypass"] targetchecking = SpiceBot.users.target_check(bot, trigger, posstarget, targetbypass) if not targetchecking["targetgood"]: - if trigger.sb["dict"][trigger.sb["responsekey"]]["target_backup"]: - trigger.sb["target"] = trigger.sb["dict"][trigger.sb["responsekey"]]["target_backup"] - if trigger.sb["target"] == 'instigator': - trigger.sb["target"] = trigger.nick - elif trigger.sb["target"] == 'random': - trigger.sb["target"] = SpiceBot.users.random_valid_target(bot, trigger, 'random') + if botcom.dict["dict"][botcom.dict["responsekey"]]["target_backup"]: + botcom.dict["target"] = botcom.dict["dict"][botcom.dict["responsekey"]]["target_backup"] + if botcom.dict["target"] == 'instigator': + botcom.dict["target"] = trigger.nick + elif botcom.dict["target"] == 'random': + botcom.dict["target"] = SpiceBot.users.random_valid_target(bot, trigger, 'random') else: for reason in ['self', 'bot', 'bots', 'offline', 'unknown', 'privmsg', 'diffchannel', 'diffbot']: - if targetchecking["reason"] == reason and trigger.sb["dict"][trigger.sb["responsekey"]]["react_"+reason]: + if targetchecking["reason"] == reason and botcom.dict["dict"][botcom.dict["responsekey"]]["react_"+reason]: reaction = True - commandrunconsensus.append(trigger.sb["dict"][trigger.sb["responsekey"]]["react_"+reason]) + commandrunconsensus.append(botcom.dict["dict"][botcom.dict["responsekey"]]["react_"+reason]) if not reaction: commandrunconsensus.append([targetchecking["error"]]) else: - trigger.sb["target"] = spicemanip.main(trigger.sb['args'], 1) - trigger.sb['args'] = spicemanip.main(trigger.sb['args'], '2+', 'list') + botcom.dict["target"] = spicemanip.main(botcom.dict['args'], 1) + botcom.dict['args'] = spicemanip.main(botcom.dict['args'], '2+', 'list') # $blank input - trigger.sb["completestring"] = spicemanip.main(trigger.sb['args'], 0) or '' - if trigger.sb["dict"][trigger.sb["responsekey"]]["blank_required"]: + botcom.dict["completestring"] = spicemanip.main(botcom.dict['args'], 0) or '' + if botcom.dict["dict"][botcom.dict["responsekey"]]["blank_required"]: - if trigger.sb["completestring"] == '' or not trigger.sb["completestring"]: + if botcom.dict["completestring"] == '' or not botcom.dict["completestring"]: - if trigger.sb["dict"][trigger.sb["responsekey"]]["blank_backup"]: - trigger.sb["completestring"] = trigger.sb["dict"][trigger.sb["responsekey"]]["blank_backup"] + if botcom.dict["dict"][botcom.dict["responsekey"]]["blank_backup"]: + botcom.dict["completestring"] = botcom.dict["dict"][botcom.dict["responsekey"]]["blank_backup"] else: - commandrunconsensus.append(trigger.sb["dict"][trigger.sb["responsekey"]]["blank_fail"]) + commandrunconsensus.append(botcom.dict["dict"][botcom.dict["responsekey"]]["blank_fail"]) - if trigger.sb["dict"][trigger.sb["responsekey"]]["blank_phrasehandle"]: - if trigger.sb["dict"][trigger.sb["responsekey"]]["blank_phrasehandle"] != []: - if spicemanip.main(trigger.sb["completestring"], 1).lower() not in trigger.sb["dict"][trigger.sb["responsekey"]]["blank_phrasehandle"]: - trigger.sb["completestring"] = trigger.sb["dict"][trigger.sb["responsekey"]]["blank_phrasehandle"][0] + " " + trigger.sb["completestring"] - elif spicemanip.main(trigger.sb["completestring"], 1).lower() in trigger.sb["dict"][trigger.sb["responsekey"]]["blank_phrasehandle"]: - if spicemanip.main(trigger.sb["completestring"], 1).lower() != trigger.sb["dict"][trigger.sb["responsekey"]]["blank_phrasehandle"][0]: - trigger.sb['args'] = spicemanip.main(trigger.sb['args'], '2+', 'list') - if trigger.sb['args'] != []: - trigger.sb["completestring"] = trigger.sb["dict"][trigger.sb["responsekey"]]["blank_phrasehandle"][0] + " " + spicemanip.main(trigger.sb['args'], 0) + if botcom.dict["dict"][botcom.dict["responsekey"]]["blank_phrasehandle"]: + if botcom.dict["dict"][botcom.dict["responsekey"]]["blank_phrasehandle"] != []: + if spicemanip.main(botcom.dict["completestring"], 1).lower() not in botcom.dict["dict"][botcom.dict["responsekey"]]["blank_phrasehandle"]: + botcom.dict["completestring"] = botcom.dict["dict"][botcom.dict["responsekey"]]["blank_phrasehandle"][0] + " " + botcom.dict["completestring"] + elif spicemanip.main(botcom.dict["completestring"], 1).lower() in botcom.dict["dict"][botcom.dict["responsekey"]]["blank_phrasehandle"]: + if spicemanip.main(botcom.dict["completestring"], 1).lower() != botcom.dict["dict"][botcom.dict["responsekey"]]["blank_phrasehandle"][0]: + botcom.dict['args'] = spicemanip.main(botcom.dict['args'], '2+', 'list') + if botcom.dict['args'] != []: + botcom.dict["completestring"] = botcom.dict["dict"][botcom.dict["responsekey"]]["blank_phrasehandle"][0] + " " + spicemanip.main(botcom.dict['args'], 0) if commandrunconsensus != []: - trigger.sb["success"] = False - if trigger.sb["dict"][trigger.sb["responsekey"]]["response_fail"] and not reaction: - trigger.sb["dict"][trigger.sb["responsekey"]]["responses"] = trigger.sb["dict"][trigger.sb["responsekey"]]["response_fail"] + botcom.dict["success"] = False + if botcom.dict["dict"][botcom.dict["responsekey"]]["response_fail"] and not reaction: + botcom.dict["dict"][botcom.dict["responsekey"]]["responses"] = botcom.dict["dict"][botcom.dict["responsekey"]]["response_fail"] else: - trigger.sb["dict"][trigger.sb["responsekey"]]["responses"] = commandrunconsensus[0] + botcom.dict["dict"][botcom.dict["responsekey"]]["responses"] = commandrunconsensus[0] - bot_dictcom_reply_shared(bot, trigger) + bot_dictcom_reply_shared(bot, trigger, botcom) -def bot_dictcom_reply_shared(bot, trigger): +def bot_dictcom_reply_shared(bot, trigger, botcom): - if trigger.sb["specified"]: - if trigger.sb["specified"] > len(trigger.sb["dict"][trigger.sb["responsekey"]]["responses"]): - currentspecified = len(trigger.sb["dict"][trigger.sb["responsekey"]]["responses"]) + if botcom.dict["specified"]: + if botcom.dict["specified"] > len(botcom.dict["dict"][botcom.dict["responsekey"]]["responses"]): + currentspecified = len(botcom.dict["dict"][botcom.dict["responsekey"]]["responses"]) else: - currentspecified = trigger.sb["specified"] - trigger.sb["replies"] = spicemanip.main(trigger.sb["dict"][trigger.sb["responsekey"]]["responses"], currentspecified, 'return') - trigger.sb["replynum"] = currentspecified + currentspecified = botcom.dict["specified"] + botcom.dict["replies"] = spicemanip.main(botcom.dict["dict"][botcom.dict["responsekey"]]["responses"], currentspecified, 'return') + botcom.dict["replynum"] = currentspecified else: - trigger.sb["replies"] = spicemanip.main(trigger.sb["dict"][trigger.sb["responsekey"]]["responses"], 'random', 'return') + botcom.dict["replies"] = spicemanip.main(botcom.dict["dict"][botcom.dict["responsekey"]]["responses"], 'random', 'return') try: - trigger.sb["replynum"] = trigger.sb["dict"][trigger.sb["responsekey"]]["responses"].index(trigger.sb["replies"]) + botcom.dict["replynum"] = botcom.dict["dict"][botcom.dict["responsekey"]]["responses"].index(botcom.dict["replies"]) except Exception as e: - trigger.sb["replynum"] = e - trigger.sb["replynum"] = 0 - trigger.sb["replynum"] += 1 - trigger.sb["totalreplies"] = len(trigger.sb["dict"][trigger.sb["responsekey"]]["responses"]) + botcom.dict["replynum"] = e + botcom.dict["replynum"] = 0 + botcom.dict["replynum"] += 1 + botcom.dict["totalreplies"] = len(botcom.dict["dict"][botcom.dict["responsekey"]]["responses"]) # This handles responses in list form - if not isinstance(trigger.sb["replies"], list): - trigger.sb["replies"] = [trigger.sb["replies"]] + if not isinstance(botcom.dict["replies"], list): + botcom.dict["replies"] = [botcom.dict["replies"]] - for rply in trigger.sb["replies"]: + for rply in botcom.dict["replies"]: # replies that can be evaluated as code if rply.startswith("time.sleep"): @@ -246,31 +246,31 @@ def bot_dictcom_reply_shared(bot, trigger): # random number if "$randnum" in rply: - if trigger.sb["dict"][trigger.sb["responsekey"]]["randnum"]: - randno = randint(trigger.sb["dict"][trigger.sb["responsekey"]]["randnum"][0], trigger.sb["dict"][trigger.sb["responsekey"]]["randnum"][1]) + if botcom.dict["dict"][botcom.dict["responsekey"]]["randnum"]: + randno = randint(botcom.dict["dict"][botcom.dict["responsekey"]]["randnum"][0], botcom.dict["dict"][botcom.dict["responsekey"]]["randnum"][1]) else: randno = randint(0, 50) rply = rply.replace("$randnum", str(randno)) # blank if "$blank" in rply: - rply = rply.replace("$blank", trigger.sb["completestring"] or '') + rply = rply.replace("$blank", botcom.dict["completestring"] or '') # the remaining input if "$input" in rply: - rply = rply.replace("$input", spicemanip.main(trigger.sb['args'], 0) or trigger.sb["realcom"]) + rply = rply.replace("$input", spicemanip.main(botcom.dict['args'], 0) or botcom.dict["realcom"]) # translation - if trigger.sb["dict"][trigger.sb["responsekey"]]["translations"]: - rply = SpiceBot.translate.bot_translate_process(rply, trigger.sb["dict"][trigger.sb["responsekey"]]["translations"]) + if botcom.dict["dict"][botcom.dict["responsekey"]]["translations"]: + rply = SpiceBot.translate.bot_translate_process(rply, botcom.dict["dict"][botcom.dict["responsekey"]]["translations"]) # text to precede the output - if trigger.sb["dict"][trigger.sb["responsekey"]]["prefixtext"] and trigger.sb["success"]: - rply = spicemanip.main(trigger.sb["dict"][trigger.sb["responsekey"]]["prefixtext"], 'random') + rply + if botcom.dict["dict"][botcom.dict["responsekey"]]["prefixtext"] and botcom.dict["success"]: + rply = spicemanip.main(botcom.dict["dict"][botcom.dict["responsekey"]]["prefixtext"], 'random') + rply # text to follow the output - if trigger.sb["dict"][trigger.sb["responsekey"]]["suffixtext"] and trigger.sb["success"]: - rply = rply + spicemanip.main(trigger.sb["dict"][trigger.sb["responsekey"]]["suffixtext"], 'random') + if botcom.dict["dict"][botcom.dict["responsekey"]]["suffixtext"] and botcom.dict["success"]: + rply = rply + spicemanip.main(botcom.dict["dict"][botcom.dict["responsekey"]]["suffixtext"], 'random') # trigger.nick if "$instigator" in rply: @@ -294,7 +294,7 @@ def bot_dictcom_reply_shared(bot, trigger): # target if "$target" in rply: - targetnames = trigger.sb["target"] or '' + targetnames = botcom.dict["target"] or '' if "$targets" in rply: if targetnames.lower() == "your": targetnames = targetnames @@ -309,23 +309,23 @@ def bot_dictcom_reply_shared(bot, trigger): # smaller variations for the text if "$replyvariation" in rply: - if trigger.sb["dict"][trigger.sb["responsekey"]]["replyvariation"] != []: - variation = spicemanip.main(trigger.sb["dict"][trigger.sb["responsekey"]]["replyvariation"], 'random') + if botcom.dict["dict"][botcom.dict["responsekey"]]["replyvariation"] != []: + variation = spicemanip.main(botcom.dict["dict"][botcom.dict["responsekey"]]["replyvariation"], 'random') rply = rply.replace("$replyvariation", variation) else: rply = rply.replace("$replyvariation", '') # smaller variations for the text if "$responsekey" in rply: - rply = rply.replace("$responsekey", str(trigger.sb["responsekey"])) + rply = rply.replace("$responsekey", str(botcom.dict["responsekey"])) if "$index" in rply: - rply = rply.replace("$index", str(str(trigger.sb["replynum"]) + "/" + str(trigger.sb["totalreplies"]))) + rply = rply.replace("$index", str(str(botcom.dict["replynum"]) + "/" + str(botcom.dict["totalreplies"]))) # display special options for this command if "$specialoptions" in rply: nonstockoptions = [] - for command in trigger.sb["dict"].keys(): + for command in botcom.dict["dict"].keys(): if command not in ["?default", "validcoms", "contributors", "author", "type", "filepath", "filename", "hardcoded_channel_block", "description", "exampleresponse", "example", "usage", "privs"]: nonstockoptions.append(command) nonstockoptions = spicemanip.main(nonstockoptions, "andlist") @@ -341,26 +341,26 @@ def bot_dictcom_reply_shared(bot, trigger): bot.osd(rply, trigger.sender, rplytype) -def bot_dictcom_gif(bot, trigger): +def bot_dictcom_gif(bot, trigger, botcom): - if trigger.sb["dict"][trigger.sb["responsekey"]]["blank_required"] and not trigger.sb["completestring"]: - trigger.sb["dict"][trigger.sb["responsekey"]]["responses"] = trigger.sb["dict"][trigger.sb["responsekey"]]["blank_fail"] - return bot_dictcom_reply_shared(bot, trigger) - elif trigger.sb["dict"][trigger.sb["responsekey"]]["blank_required"] and trigger.sb["completestring"]: - queries = [trigger.sb["completestring"]] + if botcom.dict["dict"][botcom.dict["responsekey"]]["blank_required"] and not botcom.dict["completestring"]: + botcom.dict["dict"][botcom.dict["responsekey"]]["responses"] = botcom.dict["dict"][botcom.dict["responsekey"]]["blank_fail"] + return bot_dictcom_reply_shared(bot, trigger, botcom) + elif botcom.dict["dict"][botcom.dict["responsekey"]]["blank_required"] and botcom.dict["completestring"]: + queries = [botcom.dict["completestring"]] else: - queries = trigger.sb["dict"][trigger.sb["responsekey"]]["responses"] + queries = botcom.dict["dict"][botcom.dict["responsekey"]]["responses"] # which api's are we using to search - if "queryapi" in trigger.sb["dict"].keys(): - searchapis = trigger.sb["dict"][trigger.sb["responsekey"]]["queryapi"] + if "queryapi" in botcom.dict["dict"].keys(): + searchapis = botcom.dict["dict"][botcom.dict["responsekey"]]["queryapi"] else: searchapis = list(SpiceBot.gif.valid_api.keys()) - if trigger.sb["specified"]: - if trigger.sb["specified"] > len(queries): - trigger.sb["specified"] = len(queries) - query = spicemanip.main(queries, trigger.sb["specified"], 'return') + if botcom.dict["specified"]: + if botcom.dict["specified"] > len(queries): + botcom.dict["specified"] = len(queries) + query = spicemanip.main(queries, botcom.dict["specified"], 'return') else: query = spicemanip.main(queries, 'random', 'return') @@ -374,18 +374,18 @@ def bot_dictcom_gif(bot, trigger): gifdict = SpiceBot.gif.get_gif(searchdict) if gifdict["error"]: - trigger.sb["success"] = False - if trigger.sb["dict"][trigger.sb["responsekey"]]["search_fail"]: - gifdict["error"] = trigger.sb["dict"][trigger.sb["responsekey"]]["search_fail"] - trigger.sb["dict"][trigger.sb["responsekey"]]["responses"] = [gifdict["error"]] + botcom.dict["success"] = False + if botcom.dict["dict"][botcom.dict["responsekey"]]["search_fail"]: + gifdict["error"] = botcom.dict["dict"][botcom.dict["responsekey"]]["search_fail"] + botcom.dict["dict"][botcom.dict["responsekey"]]["responses"] = [gifdict["error"]] else: - trigger.sb["dict"][trigger.sb["responsekey"]]["responses"] = [str(gifdict['gifapi'].title() + " Result (" + str(query) + " #" + str(gifdict["returnnum"]) + "): " + str(gifdict["returnurl"]))] + botcom.dict["dict"][botcom.dict["responsekey"]]["responses"] = [str(gifdict['gifapi'].title() + " Result (" + str(query) + " #" + str(gifdict["returnnum"]) + "): " + str(gifdict["returnurl"]))] - trigger.sb["specified"] = False - bot_dictcom_reply_shared(bot, trigger) + botcom.dict["specified"] = False + bot_dictcom_reply_shared(bot, trigger, botcom) -def bot_dictcom_feeds(bot, trigger): +def bot_dictcom_feeds(bot, trigger, botcom): return bot.osd("WIP") """ @@ -394,7 +394,7 @@ def bot_dictcom_feeds(bot, trigger): bot_startup_requirements_set(bot, "feeds") - feed = trigger.sb["dict"][trigger.sb["responsekey"]]["responses"][0] + feed = botcom.dict["dict"][botcom.dict["responsekey"]]["responses"][0] if feed not in bot.memory['feeds'].keys(): return bot.osd(feed + " does not appear to be a valid feed.") @@ -407,5 +407,5 @@ def bot_dictcom_feeds(bot, trigger): """ -def bot_dictcom_search(bot, trigger): +def bot_dictcom_search(bot, trigger, botcom): bot.say("testing done") diff --git a/sopel_modules/SpiceBot_Core_Commands/Gif.py b/sopel_modules/SpiceBot_Core_Commands/Gif.py index c2406c5..41fc1e9 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Gif.py +++ b/sopel_modules/SpiceBot_Core_Commands/Gif.py @@ -15,17 +15,17 @@ import spicemanip @sopel.module.commands('gif') def gif_trigger(bot, trigger, botcom): - if not len(trigger.sb['args']): - return SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "Please present a query to search.") + if not len(botcom.dict['args']): + return SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Please present a query to search.") - query = spicemanip.main(trigger.sb['args'], 0) + query = spicemanip.main(botcom.dict['args'], 0) searchapis = list(SpiceBot.gif.valid_api.keys()) searchdict = {"query": query, "gifsearch": searchapis} gifdict = SpiceBot.gif.get_gif(searchdict) if gifdict["error"]: - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], gifdict["error"]) + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], gifdict["error"]) else: bot.osd(str(gifdict['gifapi'].title() + " Result (" + str(query) + " #" + str(gifdict["returnnum"]) + "): " + str(gifdict["returnurl"]))) @@ -34,18 +34,18 @@ def gif_trigger(bot, trigger, botcom): @sopel.module.commands('(.*)') def gifapi_triggers(bot, trigger, botcom): - if trigger.sb['com'] not in list(SpiceBot.gif.valid_api.keys()): + if botcom.dict['com'] not in list(SpiceBot.gif.valid_api.keys()): return - if not len(trigger.sb['args']): - return SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "Please present a query to search.") + if not len(botcom.dict['args']): + return SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Please present a query to search.") - query = spicemanip.main(trigger.sb['args'], 0) - searchdict = {"query": query, "gifsearch": trigger.sb['com']} + query = spicemanip.main(botcom.dict['args'], 0) + searchdict = {"query": query, "gifsearch": botcom.dict['com']} gifdict = SpiceBot.gif.get_gif(searchdict) if gifdict["error"]: - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], gifdict["error"]) + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], gifdict["error"]) else: bot.osd(str(gifdict['gifapi'].title() + " Result (" + str(query) + " #" + str(gifdict["returnnum"]) + "): " + str(gifdict["returnurl"]))) diff --git a/sopel_modules/SpiceBot_Core_Commands/Logs.py b/sopel_modules/SpiceBot_Core_Commands/Logs.py index 2046ffb..9928540 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Logs.py +++ b/sopel_modules/SpiceBot_Core_Commands/Logs.py @@ -17,10 +17,10 @@ import sopel_modules.SpiceBot as SpiceBot def bot_command_logs(bot, trigger, botcom): if not SpiceBot.command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "I was unable to process this Bot Nick command due to privilege issues.") + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "I was unable to process this Bot Nick command due to privilege issues.") return - logtype = spicemanip.main(trigger.sb['args'], 1) or None + logtype = spicemanip.main(botcom.dict['args'], 1) or None if not logtype: bot.osd("Current valid log(s) include: " + spicemanip.main(list(SpiceBot.logs.dict["list"].keys()), 'andlist'), trigger.sender, 'action') return @@ -28,9 +28,9 @@ def bot_command_logs(bot, trigger, botcom): if not SpiceBot.inlist(logtype, list(SpiceBot.logs.dict["list"].keys())): closestmatches = SpiceBot.similar_list(logtype, list(SpiceBot.logs.dict["list"].keys()), 10, 'reverse') if not len(closestmatches): - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "No valid logs match " + str(logtype) + ".", trigger.nick, 'notice') + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "No valid logs match " + str(logtype) + ".", trigger.nick, 'notice') else: - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "The following commands may match " + str(logtype) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick, 'notice') + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "The following commands may match " + str(logtype) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick, 'notice') return @@ -39,7 +39,7 @@ def bot_command_logs(bot, trigger, botcom): logindex = SpiceBot.logs.get_logs(logtype) if not len(logindex): - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "No logs found for " + str(logtype) + ".") + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "No logs found for " + str(logtype) + ".") return bot.osd("Is Examining " + str(logtype) + " log(s).") diff --git a/sopel_modules/SpiceBot_Core_Commands/Messaging.py b/sopel_modules/SpiceBot_Core_Commands/Messaging.py index ce1b295..27c8385 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Messaging.py +++ b/sopel_modules/SpiceBot_Core_Commands/Messaging.py @@ -12,42 +12,42 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('action') def bot_command_action(bot, trigger, botcom): - bot_command_process(bot, trigger) + bot_command_process(bot, trigger, botcom) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('notice') def bot_command_notice(bot, trigger, botcom): - bot_command_process(bot, trigger) + bot_command_process(bot, trigger, botcom) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('privmsg', 'say', 'msg') def bot_command_privmsg(bot, trigger, botcom): - bot_command_process(bot, trigger) + bot_command_process(bot, trigger, botcom) -def bot_command_process(bot, trigger): +def bot_command_process(bot, trigger, botcom): if not SpiceBot.command_permissions_check(bot, trigger, ['admins', 'owner']): - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "I was unable to process this Bot Nick command due to privilege issues.") + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "I was unable to process this Bot Nick command due to privilege issues.") return - if trigger.sb['com'] in ['say', 'msg']: - trigger.sb['com'] = 'privmsg' + if botcom.dict['com'] in ['say', 'msg']: + botcom.dict['com'] = 'privmsg' - if not len(trigger.sb['args']): - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "You must specify a channel or nick.") + if not len(botcom.dict['args']): + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "You must specify a channel or nick.") return - target = spicemanip.main(trigger.sb['args'], 1) + target = spicemanip.main(botcom.dict['args'], 1) if (target not in ['allchans', 'allnicks'] and not SpiceBot.inlist(target.lower(), list(SpiceBot.channels.dict['list'].keys())) and not SpiceBot.inlist(target.lower(), bot.users)): - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "Channel/nick name {} not valid.".format(target)) + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel/nick name {} not valid.".format(target)) return - trigger.sb['args'] = spicemanip.main(trigger.sb['args'], '2+', 'list') + botcom.dict['args'] = spicemanip.main(botcom.dict['args'], '2+', 'list') if target == 'allchans': targetsendlist = list(bot.channels.keys()) @@ -56,9 +56,9 @@ def bot_command_process(bot, trigger): else: targetsendlist = [target] - botmessage = spicemanip.main(trigger.sb['args'], 0) + botmessage = spicemanip.main(botcom.dict['args'], 0) if not botmessage: - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "You must specify a message to send.") + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "You must specify a message to send.") return - bot.osd(botmessage, targetsendlist, trigger.sb['com'].upper()) + bot.osd(botmessage, targetsendlist, botcom.dict['com'].upper()) diff --git a/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py b/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py index 84b96fe..4d8b330 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py +++ b/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py @@ -14,19 +14,19 @@ import sopel_modules.SpiceBot as SpiceBot def nickname_comand_update(bot, trigger, botcom): if not SpiceBot.command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "I was unable to process this Bot Nick command due to privilege issues.") + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "I was unable to process this Bot Nick command due to privilege issues.") return - if not len(trigger.sb['args']): + if not len(botcom.dict['args']): commandused = 'nodeps' else: - commandused = spicemanip.main(trigger.sb['args'], 1).lower() + commandused = spicemanip.main(botcom.dict['args'], 1).lower() if commandused not in ['deps', 'nodeps']: - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "Please specify deps or nodeps") + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Please specify deps or nodeps") return - trigger.sb['args'] = spicemanip.main(trigger.sb['args'], '2+', 'list') + botcom.dict['args'] = spicemanip.main(botcom.dict['args'], '2+', 'list') quitmessage = "Received command from " + trigger.nick + " to update from Github and restart" SpiceBot.logs.log('SpiceBot_Update', quitmessage) @@ -46,7 +46,7 @@ def nickname_comand_update(bot, trigger, botcom): def nickname_comand_restart(bot, trigger, botcom): if not trigger.admin: - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "You are not authorized to perform this function.") + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "You are not authorized to perform this function.") quitmessage = "Received command from " + trigger.nick + " to restart. Be Back Soon!" SpiceBot.logs.log('SpiceBot_Restart', quitmessage) diff --git a/sopel_modules/SpiceBot_Core_Commands/Search.py b/sopel_modules/SpiceBot_Core_Commands/Search.py index d0375f6..8fd621b 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Search.py +++ b/sopel_modules/SpiceBot_Core_Commands/Search.py @@ -14,14 +14,14 @@ import sopel_modules.SpiceBot as SpiceBot @sopel.module.commands('search', 'find', 'google', 'lookup') def search_main(bot, trigger, botcom): - searchterm = spicemanip.main(trigger.sb['args'], 0) or None + searchterm = spicemanip.main(botcom.dict['args'], 0) or None if not searchterm: - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "Not sure what you want me to look for.") + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Not sure what you want me to look for.") return searchreturn = SpiceBot.google.search(searchterm) if not searchreturn: - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], 'I cannot find anything about that') + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], 'I cannot find anything about that') else: bot.osd(["[Information search for '" + str(searchterm) + "']", str(searchreturn)]) @@ -30,14 +30,14 @@ def search_main(bot, trigger, botcom): @sopel.module.commands("where", "whereis") def search_where(bot, trigger, botcom): - searchterm = spicemanip.main(trigger.sb['args'], 0) or None + searchterm = spicemanip.main(botcom.dict['args'], 0) or None if not searchterm: - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "Not sure what you want me to look for.") + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Not sure what you want me to look for.") return searchreturn = SpiceBot.google.search(searchterm, 'maps') if not searchreturn: - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], 'I cannot find anything about that') + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], 'I cannot find anything about that') else: bot.osd(["[Location search for " + str(searchterm) + "]", str(searchreturn)]) @@ -46,14 +46,14 @@ def search_where(bot, trigger, botcom): @sopel.module.commands("what", "whatis") def search_what(bot, trigger, botcom): - searchterm = spicemanip.main(trigger.sb['args'], 0) or None + searchterm = spicemanip.main(botcom.dict['args'], 0) or None if not searchterm: - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "Not sure what you want me to look for.") + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Not sure what you want me to look for.") return searchreturn = SpiceBot.google.search(searchterm) if not searchreturn: - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], 'I cannot find anything about that') + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], 'I cannot find anything about that') else: bot.osd(["[Information search for '" + str(searchterm) + "']", str(searchreturn)]) @@ -62,13 +62,13 @@ def search_what(bot, trigger, botcom): @sopel.module.commands("youtube", "video") def search_video(bot, trigger, botcom): - searchterm = spicemanip.main(trigger.sb['args'], 0) or None + searchterm = spicemanip.main(botcom.dict['args'], 0) or None if not searchterm: - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], "Not sure what you want me to look for.") + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Not sure what you want me to look for.") return searchreturn = SpiceBot.google.search(searchterm, 'youtube') if not searchreturn: - SpiceBot.messagelog.messagelog_error(trigger.sb["log_id"], 'I cannot find anything about that') + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], 'I cannot find anything about that') else: bot.osd(["[Youtube search for '" + str(searchterm) + "']", str(searchreturn)]) diff --git a/sopel_modules/SpiceBot_Core_Commands/Sherlock.py b/sopel_modules/SpiceBot_Core_Commands/Sherlock.py index 49b22de..cd688d3 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Sherlock.py +++ b/sopel_modules/SpiceBot_Core_Commands/Sherlock.py @@ -15,15 +15,15 @@ def bot_command_sherlock(bot, trigger, botcom): netlist = list(SpiceBot.sherlock.dict.keys()) - username = spicemanip.main(trigger.sb["args"], 1) or trigger.nick - trigger.sb["args"] = spicemanip.main(trigger.sb["args"], "2+", 'list') + username = spicemanip.main(botcom.dict["args"], 1) or trigger.nick + botcom.dict["args"] = spicemanip.main(botcom.dict["args"], "2+", 'list') checklist = netlist checklistname = 'all' if SpiceBot.inlist(username, netlist): checklistname = SpiceBot.inlist_match(username, netlist) checklist = [checklistname] - username = spicemanip.main(trigger.sb["args"], 1) or trigger.nick + username = spicemanip.main(botcom.dict["args"], 1) or trigger.nick bot.osd("Checking username " + username + " in " + checklistname + " network.") From 9ec3b6a700f87aacc4d7740e3a5b80ea80532b79 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 10:07:36 -0400 Subject: [PATCH 04/96] , botcom --- sopel_modules/SpiceBot/Prerun.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index a951b48..c1dd754 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -102,10 +102,10 @@ def prerun(t_command_type='module', t_command_subtype=None): botcom.dict["args"], botcom.dict["hyphen_arg"] = trigger_hyphen_args(botcom.dict["args"]) if not botcom.dict["hyphen_arg"]: # check if anything prohibits the nick from running the command - if trigger_runstatus(bot, trigger): + if trigger_runstatus(bot, trigger, botcom): function(bot, trigger, botcom, *args, **kwargs) else: - trigger_hyphen_arg_handler(bot, trigger) + trigger_hyphen_arg_handler(bot, trigger, botcom) botmessagelog.messagelog_exit(bot, argsdict_default["log_id"]) return internal_prerun @@ -176,7 +176,7 @@ def prerun_query(t_command_type='module', t_command_subtype=None): botcom.dict["runcount"] = 1 # check if anything prohibits the nick from running the command - if trigger_runstatus_query(bot, trigger): + if trigger_runstatus_query(bot, trigger, botcom): function(bot, trigger, botcom, *args, **kwargs) botmessagelog.messagelog_exit(bot, argsdict_default["log_id"]) @@ -260,7 +260,7 @@ def trigger_argsdict_single(argsdict_default, trigger_args_part): return argsdict_part -def trigger_runstatus_query(bot, trigger): +def trigger_runstatus_query(bot, trigger, botcom): # Bots can't run commands if Identifier(trigger.nick) == bot.nick: @@ -293,7 +293,7 @@ def trigger_runstatus_query(bot, trigger): timestamp = channel_disabled_list[botcom.dict["realcomref"]]["timestamp"] bywhom = channel_disabled_list[botcom.dict["realcomref"]]["disabledby"] message = "The " + str(botcom.dict["comtext"]) + " command was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) - return trigger_cant_run(bot, trigger, message) + return trigger_cant_run(bot, trigger, botcom, message) # don't run commands that are disabled for specific users nick_disabled_list = botcommands.get_commands_disabled(str(trigger.nick)) @@ -303,7 +303,7 @@ def trigger_runstatus_query(bot, trigger): reason = nick_disabled_list[botcom.dict["realcomref"]]["reason"] timestamp = nick_disabled_list[botcom.dict["realcomref"]]["timestamp"] message = "The " + str(botcom.dict["comtext"]) + " command was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) - return trigger_cant_run(bot, trigger, message) + return trigger_cant_run(bot, trigger, botcom, message) else: botcommands.unset_command_disabled(botcom.dict["realcomref"], trigger.nick) botmessagelog.messagelog_error(botcom.dict["log_id"], botcom.dict["comtext"] + " is now enabled for " + str(trigger.nick)) @@ -311,7 +311,7 @@ def trigger_runstatus_query(bot, trigger): return True -def trigger_runstatus(bot, trigger): +def trigger_runstatus(bot, trigger, botcom): # Bots can't run commands if Identifier(trigger.nick) == bot.nick: @@ -341,7 +341,7 @@ def trigger_runstatus(bot, trigger): timestamp = channel_disabled_list[botcom.dict["realcomref"]]["timestamp"] bywhom = channel_disabled_list[botcom.dict["realcomref"]]["disabledby"] message = "The " + str(botcom.dict["comtext"]) + " command multirun usage was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) - return trigger_cant_run(bot, trigger, message) + return trigger_cant_run(bot, trigger, botcom, message) # don't run commands that are disabled for specific users nick_disabled_list = botcommands.get_commands_disabled(str(trigger.nick), "multirun") @@ -351,7 +351,7 @@ def trigger_runstatus(bot, trigger): reason = nick_disabled_list[botcom.dict["realcomref"]]["reason"] timestamp = nick_disabled_list[botcom.dict["realcomref"]]["timestamp"] message = "The " + str(botcom.dict["comtext"]) + " command was multirun unsage disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) - return trigger_cant_run(bot, trigger, message) + return trigger_cant_run(bot, trigger, botcom, message) else: botcommands.unset_command_disabled(botcom.dict["realcomref"], trigger.nick, "multirun") botmessagelog.messagelog_error(botcom.dict["log_id"], botcom.dict["comtext"] + " multirun is now enabled for " + str(trigger.nick)) @@ -364,7 +364,7 @@ def trigger_runstatus(bot, trigger): timestamp = channel_disabled_list[botcom.dict["realcomref"]]["timestamp"] bywhom = channel_disabled_list[botcom.dict["realcomref"]]["disabledby"] message = "The " + str(botcom.dict["comtext"]) + " command was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) - return trigger_cant_run(bot, trigger, message) + return trigger_cant_run(bot, trigger, botcom, message) # don't run commands that are disabled for specific users nick_disabled_list = botcommands.get_commands_disabled(str(trigger.nick)) @@ -374,7 +374,7 @@ def trigger_runstatus(bot, trigger): reason = nick_disabled_list[botcom.dict["realcomref"]]["reason"] timestamp = nick_disabled_list[botcom.dict["realcomref"]]["timestamp"] message = "The " + str(botcom.dict["comtext"]) + " command was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) - return trigger_cant_run(bot, trigger, message) + return trigger_cant_run(bot, trigger, botcom, message) else: botcommands.unset_command_disabled(botcom.dict["realcomref"], trigger.nick) botmessagelog.messagelog_error(botcom.dict["log_id"], botcom.dict["comtext"] + " is now enabled for " + str(trigger.nick)) @@ -382,7 +382,7 @@ def trigger_runstatus(bot, trigger): return True -def trigger_cant_run(bot, trigger, message=None): +def trigger_cant_run(bot, trigger, botcom, message=None): if message: botmessagelog.messagelog_error(botcom.dict["log_id"], message) if command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): @@ -419,7 +419,7 @@ def trigger_hyphen_args(trigger_args_part): return trigger_args_unhyphend, hyphenarg -def trigger_hyphen_arg_handler(bot, trigger): +def trigger_hyphen_arg_handler(bot, trigger, botcom): # Commands that cannot run via privmsg # TODO --check should work for commands that don't exist From 1d34537e9e5acb74b850199aff29eb14df546c3b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 10:08:47 -0400 Subject: [PATCH 05/96] hmm --- sopel_modules/SpiceBot_Core_Commands/DictComs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index 4d1b529..9de6850 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -146,7 +146,7 @@ def bot_dictcom_process(bot, trigger, botcom): botcom.dict["success"] = True if botcom.dict["dict"][botcom.dict["responsekey"]]["type"] in ['simple', 'fillintheblank', "target", 'targetplusreason', 'sayings', "readfromfile", "readfromurl", "ascii_art", "translate", "responses"]: - return bot_dictcom_responses(bot, trigger) + return bot_dictcom_responses(bot, trigger, botcom) else: command_function_run = str('bot_dictcom_' + botcom.dict["dict"][botcom.dict["responsekey"]]["type"] + '(bot, trigger, botcom)') eval(command_function_run) From d3e694fae06eb68318402e2222c7ca7c07460b19 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 10:43:18 -0400 Subject: [PATCH 06/96] test --digit --- sopel_modules/SpiceBot/Prerun.py | 72 +++++++++++++++++++------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index c1dd754..6a62faa 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -100,12 +100,10 @@ def prerun(t_command_type='module', t_command_subtype=None): botcom.dict["runcount"] = runcount botcom.dict["args"], botcom.dict["hyphen_arg"] = trigger_hyphen_args(botcom.dict["args"]) - if not botcom.dict["hyphen_arg"]: - # check if anything prohibits the nick from running the command + args_pass = trigger_hyphen_arg_handler(bot, trigger, botcom) + if args_pass: if trigger_runstatus(bot, trigger, botcom): function(bot, trigger, botcom, *args, **kwargs) - else: - trigger_hyphen_arg_handler(bot, trigger, botcom) botmessagelog.messagelog_exit(bot, argsdict_default["log_id"]) return internal_prerun @@ -408,8 +406,14 @@ def trigger_hyphen_args(trigger_args_part): hyphen_args = [] trigger_args_unhyphend = [] for worditem in trigger_args_part: - if str(worditem).startswith("--") and worditem[2:] in valid_hyphen_args: - hyphen_args.append(worditem[2:]) + if str(worditem).startswith("--"): + clipped_word = worditem[2:] + if clipped_word in valid_hyphen_args: + hyphen_args.append(clipped_word) + elif str(clipped_word).isdigit(): + hyphen_args.append(int(clipped_word)) + else: + trigger_args_unhyphend.append(worditem) else: trigger_args_unhyphend.append(worditem) if len(hyphen_args): @@ -423,12 +427,20 @@ def trigger_hyphen_arg_handler(bot, trigger, botcom): # Commands that cannot run via privmsg # TODO --check should work for commands that don't exist - if botcom.dict["hyphen_arg"] in ['check']: + + if not botcom.dict["hyphen_arg"]: + return True + + # handle numbered args + if str(botcom.dict["hyphen_arg"]).isdigit(): + return True + + elif botcom.dict["hyphen_arg"] in ['check']: if botcom.dict["com"].lower() != botcom.dict["realcom"]: botmessagelog.messagelog(botcom.dict["log_id"], botcom.dict["comtext"] + " is a valid alias command for " + botcom.dict["realcomtext"]) else: botmessagelog.messagelog(botcom.dict["log_id"], botcom.dict["comtext"] + " is a valid command") - return + return False elif botcom.dict["hyphen_arg"] in [ 'enable', 'disable', @@ -443,12 +455,12 @@ def trigger_hyphen_arg_handler(bot, trigger, botcom): botmessagelog.messagelog_error(botcom.dict["log_id"], "Who/Where am I enabling " + str(botcom.dict["comtext"]) + " usage for?") else: botmessagelog.messagelog_error(botcom.dict["log_id"], "Who/Where am I disabling " + str(botcom.dict["comtext"]) + " usage for?") - return + return False botcom.dict["args"] = spicemanip.main(botcom.dict["args"], "2+", "list") if not botdb.check_nick_id(target) and not botchannels.check_channel_bot(target, True): botmessagelog.messagelog_error(botcom.dict["log_id"], "I don't know who/what " + str(target) + " is.") - return + return False if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): if target != trigger.nick: @@ -456,37 +468,37 @@ def trigger_hyphen_arg_handler(bot, trigger, botcom): botmessagelog.messagelog_error(botcom.dict["log_id"], "I was unable to enable this command for " + str(target) + " due to privilege issues.") else: botmessagelog.messagelog_error(botcom.dict["log_id"], "I was unable to disable this command for " + str(target) + " due to privilege issues.") - return + return False if botcom.dict["hyphen_arg"] in ['enable', 'unblock', "activate", "on"]: if not botcommands.check_commands_disabled(botcom.dict["realcomref"], target): botmessagelog.messagelog_error(botcom.dict["log_id"], botcom.dict["comtext"] + " is already enabled for " + str(target)) - return + return False botcommands.unset_command_disabled(botcom.dict["realcomref"], target) botmessagelog.messagelog(botcom.dict["log_id"], botcom.dict["comtext"] + " is now enabled for " + str(target)) - return + return False else: if botcommands.check_commands_disabled(botcom.dict["realcomref"], target): botmessagelog.messagelog_error(botcom.dict["log_id"], botcom.dict["comtext"] + " is already disabled for " + str(target)) - return + return False trailingmessage = spicemanip.main(botcom.dict["args"], 0) or "No reason given." timestamp = str(datetime.datetime.utcnow()) botcommands.set_command_disabled(botcom.dict["realcomref"], target, timestamp, trailingmessage, trigger.nick) botmessagelog.messagelog(botcom.dict["log_id"], botcom.dict["comtext"] + " is now disabled for " + str(target)) - return + return False if botcom.dict["hyphen_arg"] in ['multirun', 'multiruns']: onoff = spicemanip.main(botcom.dict["args"], 1) or None if not onoff or onoff not in ['enable', 'unblock', "activate", "on"]: botmessagelog.messagelog_error(botcom.dict["log_id"], "Do you want to enable or disable " + str(botcom.dict["comtext"]) + " multirun usage?") - return + return False target = spicemanip.main(botcom.dict["args"], 1) or trigger.nick if not target: @@ -494,12 +506,12 @@ def trigger_hyphen_arg_handler(bot, trigger, botcom): botmessagelog.messagelog_error(botcom.dict["log_id"], "Who/Where am I enabling " + str(botcom.dict["comtext"]) + " multirun usage for?") else: botmessagelog.messagelog_error(botcom.dict["log_id"], "Who/Where am I disabling " + str(botcom.dict["comtext"]) + " multirun usage for?") - return + return False botcom.dict["args"] = spicemanip.main(botcom.dict["args"], "2+", "list") if not botdb.check_nick_id(target) and not botchannels.check_channel_bot(target, True): botmessagelog.messagelog_error(botcom.dict["log_id"], "I don't know who/what " + str(target) + " is.") - return + return False if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): if target != trigger.nick: @@ -507,53 +519,53 @@ def trigger_hyphen_arg_handler(bot, trigger, botcom): botmessagelog.messagelog_error(botcom.dict["log_id"], "I was unable to enable multirun usage on " + str(botcom.dict["comtext"]) + " for " + str(target) + " due to privilege issues.") else: botmessagelog.messagelog_error(botcom.dict["log_id"], "I was unable to enable multirun usage on " + str(botcom.dict["comtext"]) + " for " + str(target) + " due to privilege issues.") - return + return False if onoff in ['enable', 'unblock', "activate", "on"]: if not botcommands.check_commands_disabled(botcom.dict["realcomref"], target, "multirun"): botmessagelog.messagelog_error(botcom.dict["log_id"], botcom.dict["comtext"] + " multirun is already enabled for " + str(target)) - return + return False botcommands.unset_command_disabled(botcom.dict["realcomref"], target, "multirun") botmessagelog.messagelog(botcom.dict["log_id"], botcom.dict["comtext"] + " multirun is now enabled for " + str(target)) - return + return False else: if botcommands.check_commands_disabled(botcom.dict["realcomref"], target, "multirun"): botmessagelog.messagelog_error(botcom.dict["log_id"], botcom.dict["comtext"] + " multirun is already disabled for " + str(target)) - return + return False trailingmessage = spicemanip.main(botcom.dict["args"], 0) or "No reason given." timestamp = str(datetime.datetime.utcnow()) botcommands.set_command_disabled(botcom.dict["realcomref"], target, timestamp, trailingmessage, trigger.nick, "multirun") botmessagelog.messagelog(botcom.dict["log_id"], botcom.dict["comtext"] + " multirun is now disabled for " + str(target)) - return + return False elif botcom.dict["hyphen_arg"] in ['example', 'usage']: botmessagelog.messagelog(botcom.dict["log_id"], botcom.dict["comtext"] + ": " + str(botcom.dict["dict"]["example"])) - return + return False elif botcom.dict["hyphen_arg"] in ['filename', 'filepath']: botmessagelog.messagelog(botcom.dict["log_id"], "The " + str(botcom.dict["comtext"]) + " file is located at " + str(botcom.dict["dict"][botcom.dict["hyphen_arg"]])) - return + return False elif botcom.dict["hyphen_arg"] in ['foldername', 'folderpath']: botmessagelog.messagelog(botcom.dict["log_id"], "The " + str(botcom.dict["comtext"]) + " folder is located at " + str(botcom.dict["dict"][botcom.dict["hyphen_arg"]])) - return + return False elif botcom.dict["hyphen_arg"] in ['author']: botmessagelog.messagelog(botcom.dict["log_id"], "The author of the " + str(botcom.dict["comtext"]) + " command is " + botcom.dict["dict"]["author"] + ".") - return + return False elif botcom.dict["hyphen_arg"] in ['contribs', 'contrib', "contributors"]: botmessagelog.messagelog(botcom.dict["log_id"], "The contributors of the " + str(botcom.dict["comtext"]) + " command are " + spicemanip.main(botcom.dict["dict"]["contributors"], "andlist") + ".") - return + return False elif botcom.dict["hyphen_arg"] in ['alias', 'aliases']: botmessagelog.messagelog(botcom.dict["log_id"], "The alaises of the " + str(botcom.dict["comtext"]) + " command are " + spicemanip.main(botcom.dict["dict"]["validcoms"], "andlist") + ".") - return + return False - return + return False From 5d2f3b704a25b0e6c6a0713fe75fe936326b3316 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 10:52:26 -0400 Subject: [PATCH 07/96] test --- sopel_modules/SpiceBot/Prerun.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 6a62faa..0a18a45 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -101,6 +101,7 @@ def prerun(t_command_type='module', t_command_subtype=None): botcom.dict["args"], botcom.dict["hyphen_arg"] = trigger_hyphen_args(botcom.dict["args"]) args_pass = trigger_hyphen_arg_handler(bot, trigger, botcom) + bot.say(str(args_pass)) if args_pass: if trigger_runstatus(bot, trigger, botcom): function(bot, trigger, botcom, *args, **kwargs) From 03e8abeee12881181c674153385854105327ef28 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 10:55:43 -0400 Subject: [PATCH 08/96] test --- sopel_modules/SpiceBot/Prerun.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 0a18a45..615ca15 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -324,8 +324,8 @@ def trigger_runstatus(bot, trigger, botcom): botmessagelog.messagelog_error(botcom.dict["log_id"], "The admin switch (-a) is for use by authorized nicks ONLY.") return False - if botcom.dict["hyphen_arg"]: - return False + # if botcom.dict["hyphen_arg"]: + # return False if not trigger.is_privmsg: if str(trigger.sender).lower() in [x.lower() for x in botcom.dict["dict"]["hardcoded_channel_block"]]: From 4577eb228ff3a6e4f576db87eebcf3639c9059bf Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 10:57:09 -0400 Subject: [PATCH 09/96] test --- sopel_modules/SpiceBot/Prerun.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 615ca15..9c535b2 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -46,6 +46,7 @@ def prerun(t_command_type='module', t_command_subtype=None): else: if not str(trigger.args[1]).startswith(tuple(botconfig.core.prefix_list)): return + bot.say("a") trigger_command_type = str(t_command_type) @@ -101,7 +102,6 @@ def prerun(t_command_type='module', t_command_subtype=None): botcom.dict["args"], botcom.dict["hyphen_arg"] = trigger_hyphen_args(botcom.dict["args"]) args_pass = trigger_hyphen_arg_handler(bot, trigger, botcom) - bot.say(str(args_pass)) if args_pass: if trigger_runstatus(bot, trigger, botcom): function(bot, trigger, botcom, *args, **kwargs) From 45ed35e03292cae43618ddef3fdcebdeeb5ef856 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 10:58:23 -0400 Subject: [PATCH 10/96] test --- sopel_modules/SpiceBot/Prerun.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 9c535b2..9bef191 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -46,19 +46,19 @@ def prerun(t_command_type='module', t_command_subtype=None): else: if not str(trigger.args[1]).startswith(tuple(botconfig.core.prefix_list)): return - bot.say("a") trigger_command_type = str(t_command_type) # Primary command used for trigger, and a list of all words trigger_args, trigger_command, trigger_prefix = make_trigger_args(trigger.args[1], trigger_command_type) - if trigger_prefix == botconfig.SpiceBot_Commands.query_prefix: + if trigger_prefix in [botconfig.SpiceBot_Commands.query_prefix]: return trigger_command_type = botcommands.find_command_type(trigger_command) if not trigger_command_type: return + bot.say("a") if t_command_subtype: if trigger_command_type != t_command_subtype: From 3b52059a2659690cf3ddfa62e4a53eaf9b2e5cf4 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 10:59:22 -0400 Subject: [PATCH 11/96] test --- sopel_modules/SpiceBot/Prerun.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 9bef191..cc430a5 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -46,6 +46,7 @@ def prerun(t_command_type='module', t_command_subtype=None): else: if not str(trigger.args[1]).startswith(tuple(botconfig.core.prefix_list)): return + bot.say("a") trigger_command_type = str(t_command_type) @@ -54,11 +55,11 @@ def prerun(t_command_type='module', t_command_subtype=None): if trigger_prefix in [botconfig.SpiceBot_Commands.query_prefix]: return + bot.say("b") trigger_command_type = botcommands.find_command_type(trigger_command) if not trigger_command_type: return - bot.say("a") if t_command_subtype: if trigger_command_type != t_command_subtype: From 396ff2bdfb964099ef13901fbdfe8062d502d4c6 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 11:01:51 -0400 Subject: [PATCH 12/96] test --- sopel_modules/SpiceBot/Prerun.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index cc430a5..e667908 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -60,10 +60,12 @@ def prerun(t_command_type='module', t_command_subtype=None): trigger_command_type = botcommands.find_command_type(trigger_command) if not trigger_command_type: return + bot.say("c") if t_command_subtype: if trigger_command_type != t_command_subtype: return + bot.say("d") # Argsdict Defaults argsdict_default = {} From 5cca2119889b0de8c9c364b889ff2338efdae357 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 11:11:40 -0400 Subject: [PATCH 13/96] check it --- sopel_modules/SpiceBot/Commands.py | 66 +++++++++++++----------------- 1 file changed, 29 insertions(+), 37 deletions(-) diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index 002ac5a..fa96669 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -271,13 +271,13 @@ class BotCommands(): foldername = str(folderpath).split("/")[-1] # check for json reference file - validcomdict = botread.module_json_to_dict(str(modulefile)) + comdict = botread.module_json_to_dict(str(modulefile)) # replace json defaults - validcomdict["filepath"] = str(modulefile) - validcomdict["filename"] = str(filename_base) - validcomdict["folderpath"] = str(folderpath) - validcomdict["foldername"] = str(foldername) + comdict["filepath"] = str(modulefile) + comdict["filename"] = str(filename_base) + comdict["folderpath"] = str(folderpath) + comdict["foldername"] = str(foldername) detected_lines = [] for line in module_file_lines: @@ -305,43 +305,35 @@ class BotCommands(): if len(detected_lines): filelinelist = [] - currentsuccesslines = 0 for detected_line in detected_lines: - try: + validcomdict = copy.deepcopy(comdict) - # Commands - if str(detected_line).startswith("commands"): - comtype = "module" - validcoms = eval(str(detected_line).split("commands")[-1]) - elif str(detected_line).startswith("nickname_commands"): - comtype = "nickname" - validcoms = eval(str(detected_line).split("nickname_commands")[-1]) - elif str(detected_line).startswith("rule"): - comtype = "rule" - validcoms = eval(str(detected_line).split("rule")[-1]) + # Commands + if str(detected_line).startswith("commands"): + comtype = "module" + validcoms = eval(str(detected_line).split("commands")[-1]) + elif str(detected_line).startswith("nickname_commands"): + comtype = "nickname" + validcoms = eval(str(detected_line).split("nickname_commands")[-1]) + elif str(detected_line).startswith("rule"): + comtype = "rule" + validcoms = eval(str(detected_line).split("rule")[-1]) - if isinstance(validcoms, tuple): - validcoms = list(validcoms) - else: - validcoms = [validcoms] - for regexcom in ["(.*)", '^\?(.*)']: - if regexcom in validcoms: - while regexcom in validcoms: - validcoms.remove(regexcom) + if isinstance(validcoms, tuple): + validcoms = list(validcoms) + else: + validcoms = [validcoms] + for regexcom in ["(.*)", '^\?(.*)']: + if regexcom in validcoms: + while regexcom in validcoms: + validcoms.remove(regexcom) - if len(validcoms): - validcomdict["comtype"] = comtype - validcomdict["validcoms"] = validcoms - filelinelist.append(validcomdict) - currentsuccesslines += 1 - except Exception as e: - addnothing = e - if addnothing: - currentsuccesslines += 0 + if len(validcoms): + validcomdict["comtype"] = comtype + validcomdict["validcoms"] = validcoms + filelinelist.append(validcomdict) - if len(filelinelist): - for vcomdict in filelinelist: - self.register(vcomdict) + self.register(validcomdict) commands = BotCommands() From 4b9e9f99967da3ba27eebdb60ad3acaff609cdb0 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 11:14:36 -0400 Subject: [PATCH 14/96] test --- sopel_modules/SpiceBot/Commands.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index fa96669..279d609 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -311,13 +311,25 @@ class BotCommands(): # Commands if str(detected_line).startswith("commands"): comtype = "module" - validcoms = eval(str(detected_line).split("commands")[-1]) + try: + validcoms = eval(str(detected_line).split("commands")[-1]) + except Exception as e: + validcoms = e + validcoms = [] elif str(detected_line).startswith("nickname_commands"): comtype = "nickname" - validcoms = eval(str(detected_line).split("nickname_commands")[-1]) + try: + validcoms = eval(str(detected_line).split("nickname_commands")[-1]) + except Exception as e: + validcoms = e + validcoms = [] elif str(detected_line).startswith("rule"): comtype = "rule" - validcoms = eval(str(detected_line).split("rule")[-1]) + try: + validcoms = eval(str(detected_line).split("rule")[-1]) + except Exception as e: + validcoms = e + validcoms = [] if isinstance(validcoms, tuple): validcoms = list(validcoms) From bcf835a863e80f780c265477a43fb648a0fd6cbc Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 11:15:37 -0400 Subject: [PATCH 15/96] test --- sopel_modules/SpiceBot/Commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index 279d609..099bc53 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -333,7 +333,7 @@ class BotCommands(): if isinstance(validcoms, tuple): validcoms = list(validcoms) - else: + if not isinstance(validcoms, list): validcoms = [validcoms] for regexcom in ["(.*)", '^\?(.*)']: if regexcom in validcoms: From 20f298d452603d1c7afaf1ccd5c02cd8a34680cc Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 11:17:04 -0400 Subject: [PATCH 16/96] test --- sopel_modules/SpiceBot/Prerun.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index e667908..c105212 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -46,7 +46,6 @@ def prerun(t_command_type='module', t_command_subtype=None): else: if not str(trigger.args[1]).startswith(tuple(botconfig.core.prefix_list)): return - bot.say("a") trigger_command_type = str(t_command_type) @@ -55,17 +54,14 @@ def prerun(t_command_type='module', t_command_subtype=None): if trigger_prefix in [botconfig.SpiceBot_Commands.query_prefix]: return - bot.say("b") trigger_command_type = botcommands.find_command_type(trigger_command) if not trigger_command_type: return - bot.say("c") if t_command_subtype: if trigger_command_type != t_command_subtype: return - bot.say("d") # Argsdict Defaults argsdict_default = {} From e5f21a1cdd224163aa0dd6996d7f1ccb7637cf87 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 11:20:29 -0400 Subject: [PATCH 17/96] w2n --- sopel_modules/SpiceBot/Prerun.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index c105212..f389f09 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -9,6 +9,7 @@ from sopel.tools import Identifier import functools import copy import datetime +from word2number import w2n import spicemanip @@ -413,7 +414,11 @@ def trigger_hyphen_args(trigger_args_part): elif str(clipped_word).isdigit(): hyphen_args.append(int(clipped_word)) else: - trigger_args_unhyphend.append(worditem) + try: + clipped_word = w2n.word_to_num(str(clipped_word)) + hyphen_args.append(int(clipped_word)) + except ValueError: + trigger_args_unhyphend.append(worditem) else: trigger_args_unhyphend.append(worditem) if len(hyphen_args): From b7e4bb31f32430f297b3e411abcd8ddfba2103bd Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 11:37:52 -0400 Subject: [PATCH 18/96] test last translation --- sopel_modules/SpiceBot/Prerun.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index f389f09..08d3261 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -404,27 +404,44 @@ def trigger_hyphen_args(trigger_args_part): 'contribs', 'contrib', "contributors", 'alias', 'aliases' ] + numdict = { + "last": -1 + } hyphen_args = [] trigger_args_unhyphend = [] for worditem in trigger_args_part: if str(worditem).startswith("--"): - clipped_word = worditem[2:] + clipped_word = str(worditem[2:]).lower() + + # valid arg above if clipped_word in valid_hyphen_args: hyphen_args.append(clipped_word) + + # numbered args elif str(clipped_word).isdigit(): hyphen_args.append(int(clipped_word)) + elif clipped_word in list(numdict.keys()): + hyphen_args.append(int(numdict[clipped_word])) + else: + + # check if arg word is a number try: clipped_word = w2n.word_to_num(str(clipped_word)) hyphen_args.append(int(clipped_word)) + + # word is not a valid arg or number except ValueError: trigger_args_unhyphend.append(worditem) else: trigger_args_unhyphend.append(worditem) + + # only one arg allowed per && split if len(hyphen_args): hyphenarg = hyphen_args[0] else: hyphenarg = None + return trigger_args_unhyphend, hyphenarg From b3dd0677f2a190a32cfcc464d18ccb286541266c Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 11:40:50 -0400 Subject: [PATCH 19/96] test --- sopel_modules/SpiceBot/Prerun.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 08d3261..3b83839 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -454,7 +454,7 @@ def trigger_hyphen_arg_handler(bot, trigger, botcom): return True # handle numbered args - if str(botcom.dict["hyphen_arg"]).isdigit(): + if str(botcom.dict["hyphen_arg"]).isdigit() or botcom.dict["hyphen_arg"] in [-1, 'random']: return True elif botcom.dict["hyphen_arg"] in ['check']: From 050ebda3ff177a912b3d4b04f350836f8f97c653 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 12:28:34 -0400 Subject: [PATCH 20/96] new spicemanip test --- sopel_modules/SpiceBot/Spicemanip.py | 353 +++++++++++++++++++++++++++ 1 file changed, 353 insertions(+) create mode 100644 sopel_modules/SpiceBot/Spicemanip.py diff --git a/sopel_modules/SpiceBot/Spicemanip.py b/sopel_modules/SpiceBot/Spicemanip.py new file mode 100644 index 0000000..2c1b8a0 --- /dev/null +++ b/sopel_modules/SpiceBot/Spicemanip.py @@ -0,0 +1,353 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +"""Top-level package for spicemanip.""" + +__author__ = """Sam Zick""" +__email__ = 'sam@deathbybandaid.net' +__version__ = '0.1.7' + +# import random +import collections + + +class spicemanip(): + + def __init__(self, inputs): + self.inputs = inputs + self.inputs_list = self.input_handler(self.inputs) + + def input_handler(self, inputs): + # Input needs to be a list, but don't split a word into letters + if not inputs: + inputs = [] + if isinstance(inputs, collections.abc.KeysView): + inputs = list(inputs) + elif isinstance(inputs, dict): + inputs = list(inputs.keys()) + if not isinstance(inputs, list): + inputs = list(inputs.split(" ")) + inputs = [x for x in inputs if x and x not in ['', ' ']] + inputs = [inputspart.strip() for inputspart in inputs] + return inputs + + def output_handler(self, outputs, output_type=None): + if not output_type: + output_type = "list" + return outputs + + def core(self, inputs=None, task='create', output_type=None): + if not inputs: + return self.output_handler([""], output_type=None) + + """ + # Hub + def main(self, inputs, outputtask, output_type='default'): + + # TODO 'this*that' or '1*that' replace either all strings matching, or an index value + # TODO reverse sort z.sort(reverse = True) + # list.extend adds lists to eachother + + mainoutputtask, suboutputtask = None, None + + # Input needs to be a list, but don't split a word into letters + if not inputs: + inputs = [] + if isinstance(inputs, collections.abc.KeysView): + inputs = list(inputs) + elif isinstance(inputs, dict): + inputs = list(inputs.keys()) + if not isinstance(inputs, list): + inputs = list(inputs.split(" ")) + inputs = [x for x in inputs if x and x not in ['', ' ']] + inputs = [inputspart.strip() for inputspart in inputs] + + # Create return + if outputtask == 'create': + return inputs + + # Make temparray to preserve original order + temparray = [] + for inputpart in inputs: + temparray.append(inputpart) + inputs = temparray + + # Convert outputtask to standard + if outputtask in [0, 'complete']: + outputtask = 'string' + elif outputtask == 'index': + mainoutputtask = inputs[1] + suboutputtask = inputs[2] + inputs = inputs[0] + elif str(outputtask).isdigit(): + mainoutputtask, outputtask = int(outputtask), 'number' + elif "^" in str(outputtask): + mainoutputtask = str(outputtask).split("^", 1)[0] + suboutputtask = str(outputtask).split("^", 1)[1] + outputtask = 'rangebetween' + if int(suboutputtask) < int(mainoutputtask): + mainoutputtask, suboutputtask = suboutputtask, mainoutputtask + elif str(outputtask).startswith("split_"): + mainoutputtask = str(outputtask).replace("split_", "") + outputtask = 'split' + elif str(outputtask).endswith(tuple(["!", "+", "-", "<", ">"])): + mainoutputtask = str(outputtask) + if str(outputtask).endswith("!"): + outputtask = 'exclude' + if str(outputtask).endswith("+"): + outputtask = 'incrange_plus' + if str(outputtask).endswith("-"): + outputtask = 'incrange_minus' + if str(outputtask).endswith(">"): + outputtask = 'excrange_plus' + if str(outputtask).endswith("<"): + outputtask = 'excrange_minus' + for r in (("!", ""), ("+", ""), ("-", ""), ("<", ""), (">", "")): + mainoutputtask = mainoutputtask.replace(*r) + if mainoutputtask == 'last': + mainoutputtask = len(inputs) + + if outputtask == 'string': + returnvalue = inputs + else: + returnvalue = eval('spicemanip_' + outputtask + '(inputs, outputtask, mainoutputtask, suboutputtask)') + + # default return if not specified + if output_type == 'default': + if outputtask in [ + 'string', 'number', 'rangebetween', 'exclude', 'random', + 'incrange_plus', 'incrange_minus', 'excrange_plus', 'excrange_minus' + ]: + output_type = 'string' + elif outputtask in ['count']: + output_type = 'dict' + + # verify output is correct + if output_type == 'return': + return returnvalue + if output_type == 'string': + if isinstance(returnvalue, list): + returnvalue = ' '.join(returnvalue) + elif output_type in ['list', 'array']: + if not isinstance(returnvalue, list): + returnvalue = list(returnvalue.split(" ")) + returnvalue = [x for x in returnvalue if x and x not in ['', ' ']] + returnvalue = [inputspart.strip() for inputspart in returnvalue] + return returnvalue + + # compare 2 lists, based on the location of an index item, passthrough needs to be [indexitem, arraytoindex, arraytocompare] + def spicemanip_index(self, indexitem, outputtask, arraytoindex, arraytocompare): + item = '' + for x, y in zip(arraytoindex, arraytocompare): + if x == indexitem: + item = y + return item + + # split list by string + def spicemanip_split(self, inputs, outputtask, mainoutputtask, suboutputtask): + split_array = [] + restring = ' '.join(inputs) + if mainoutputtask not in inputs: + split_array = [restring] + else: + split_array = restring.split(mainoutputtask) + split_array = [x for x in split_array if x and x not in ['', ' ']] + split_array = [inputspart.strip() for inputspart in split_array] + if split_array == []: + split_array = [[]] + return split_array + + # dedupe list + def spicemanip_dedupe(self, inputs, outputtask, mainoutputtask, suboutputtask): + newlist = [] + for inputspart in inputs: + if inputspart not in newlist: + newlist.append(inputspart) + return newlist + + # Sort list + def spicemanip_sort(self, inputs, outputtask, mainoutputtask, suboutputtask): + return sorted(inputs) + + # reverse sort list + def spicemanip_rsort(self, inputs, outputtask, mainoutputtask, suboutputtask): + return sorted(inputs)[::-1] + + # count items in list, return dictionary + def spicemanip_count(self, inputs, outputtask, mainoutputtask, suboutputtask): + returndict = dict() + if inputs == []: + return returndict + uniqueinputitems, uniquecount = [], [] + for inputspart in inputs: + if inputspart not in uniqueinputitems: + uniqueinputitems.append(inputspart) + for uniqueinputspart in uniqueinputitems: + count = 0 + for ele in inputs: + if (ele == uniqueinputspart): + count += 1 + uniquecount.append(count) + for inputsitem, unumber in zip(uniqueinputitems, uniquecount): + returndict[inputsitem] = unumber + return returndict + + # random item from list + def spicemanip_random(self, inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + randomselectlist = [] + for temppart in inputs: + randomselectlist.append(temppart) + while len(randomselectlist) > 1: + random.shuffle(randomselectlist) + randomselect = randomselectlist[random.randint(0, len(randomselectlist) - 1)] + randomselectlist.remove(randomselect) + randomselect = randomselectlist[0] + return randomselect + + # remove random item from list + def spicemanip_exrandom(self, inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return [] + randremove = self.spicemanip_random(inputs, outputtask, mainoutputtask, suboutputtask) + inputs.remove(randremove) + return inputs + + # Convert list into lowercase + def spicemanip_lower(self, inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return [inputspart.lower() for inputspart in inputs] + + # Convert list to uppercase + def spicemanip_upper(self, inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return [inputspart.upper() for inputspart in inputs] + + # Convert list to uppercase + def spicemanip_title(self, inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return [inputspart.title() for inputspart in inputs] + + # Reverse List Order + def spicemanip_reverse(self, inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return [] + return inputs[::-1] + + # comma seperated list + def spicemanip_list(self, inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return ', '.join(str(x) for x in inputs) + + def spicemanip_list_nospace(self, inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return ','.join(str(x) for x in inputs) + + # comma seperated list with and + def spicemanip_andlist(self, inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + if len(inputs) < 2: + return ' '.join(inputs) + lastentry = str("and " + str(inputs[len(inputs) - 1])) + del inputs[-1] + inputs.append(lastentry) + if len(inputs) == 2: + return ' '.join(inputs) + return ', '.join(str(x) for x in inputs) + + # comma seperated list with or + def spicemanip_orlist(self, inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + if len(inputs) < 2: + return ' '.join(inputs) + lastentry = str("or " + str(inputs[len(inputs) - 1])) + del inputs[-1] + inputs.append(lastentry) + if len(inputs) == 2: + return ' '.join(inputs) + return ', '.join(str(x) for x in inputs) + + # exclude number + def spicemanip_exclude(self, inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + del inputs[int(mainoutputtask) - 1] + return ' '.join(inputs) + + # Convert list to string + def spicemanip_string(self, inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return ' '.join(inputs) + + # Get number item from list + def spicemanip_number(self, inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + elif len(inputs) == 1: + return inputs[0] + elif int(mainoutputtask) > len(inputs) or int(mainoutputtask) < 0: + return '' + else: + return inputs[int(mainoutputtask) - 1] + + # Get Last item from list + def spicemanip_last(self, inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return inputs[len(inputs) - 1] + + # range between items in list + def spicemanip_rangebetween(self, inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + if not str(mainoutputtask).isdigit() or not str(suboutputtask).isdigit(): + return '' + mainoutputtask, suboutputtask = int(mainoutputtask), int(suboutputtask) + if suboutputtask == mainoutputtask: + return self.spicemanip_number(inputs, outputtask, mainoutputtask, suboutputtask) + if suboutputtask < mainoutputtask: + return [] + if mainoutputtask < 0: + mainoutputtask = 1 + if suboutputtask > len(inputs): + suboutputtask = len(inputs) + newlist = [] + for i in range(mainoutputtask, suboutputtask + 1): + newlist.append(str(self.spicemanip_number(inputs, outputtask, i, suboutputtask))) + if newlist == []: + return '' + return ' '.join(newlist) + + # Forward Range includes index number + def spicemanip_incrange_plus(self, inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return self.spicemanip_rangebetween(inputs, outputtask, int(mainoutputtask), len(inputs)) + + # Reverse Range includes index number + def spicemanip_incrange_minus(self, inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return self.spicemanip_rangebetween(inputs, outputtask, 1, int(mainoutputtask)) + + # Forward Range excludes index number + def spicemanip_excrange_plus(self, inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return self.spicemanip_rangebetween(inputs, outputtask, int(mainoutputtask) + 1, len(inputs)) + + # Reverse Range excludes index number + def spicemanip_excrange_minus(self, inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return self.spicemanip_rangebetween(inputs, outputtask, 1, int(mainoutputtask) - 1) +""" From e1b9a8cb6f3bc10453ea95208d54ce98dd5345e8 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 12:31:57 -0400 Subject: [PATCH 21/96] new --- sopel_modules/SpiceBot/Spicemanip.py | 2 +- sopel_modules/SpiceBot/__init__.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Spicemanip.py b/sopel_modules/SpiceBot/Spicemanip.py index 2c1b8a0..36904e0 100644 --- a/sopel_modules/SpiceBot/Spicemanip.py +++ b/sopel_modules/SpiceBot/Spicemanip.py @@ -11,7 +11,7 @@ __version__ = '0.1.7' import collections -class spicemanip(): +class spicemanipnew(): def __init__(self, inputs): self.inputs = inputs diff --git a/sopel_modules/SpiceBot/__init__.py b/sopel_modules/SpiceBot/__init__.py index e0836fa..864da66 100644 --- a/sopel_modules/SpiceBot/__init__.py +++ b/sopel_modules/SpiceBot/__init__.py @@ -11,6 +11,7 @@ from .Config import * from .Logs import * from .Database import * from .MessageLog import * +from .Spicemanip import * from .Update import * from .osd import * From da54db2c2b70874800ad6e577599880c73184d0b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 12:33:49 -0400 Subject: [PATCH 22/96] test --- sopel_modules/SpiceBot/Spicemanip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Spicemanip.py b/sopel_modules/SpiceBot/Spicemanip.py index 36904e0..b6a9c93 100644 --- a/sopel_modules/SpiceBot/Spicemanip.py +++ b/sopel_modules/SpiceBot/Spicemanip.py @@ -13,7 +13,7 @@ import collections class spicemanipnew(): - def __init__(self, inputs): + def __init__(self, inputs=None, task='create', output_type=None): self.inputs = inputs self.inputs_list = self.input_handler(self.inputs) From 6cdd43e618bc49458572dc0a412921bf8ea3ee30 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 12:36:54 -0400 Subject: [PATCH 23/96] test --- sopel_modules/SpiceBot/Spicemanip.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Spicemanip.py b/sopel_modules/SpiceBot/Spicemanip.py index b6a9c93..0ea8479 100644 --- a/sopel_modules/SpiceBot/Spicemanip.py +++ b/sopel_modules/SpiceBot/Spicemanip.py @@ -13,9 +13,11 @@ import collections class spicemanipnew(): - def __init__(self, inputs=None, task='create', output_type=None): + def __init__(self, inputs, output_type=None): + self.inputs = inputs self.inputs_list = self.input_handler(self.inputs) + return self.inputs_list def input_handler(self, inputs): # Input needs to be a list, but don't split a word into letters From 416805b0214a14f32bfad4d9fe3a05139732e71a Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 12:43:58 -0400 Subject: [PATCH 24/96] test --- sopel_modules/SpiceBot/Spicemanip.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot/Spicemanip.py b/sopel_modules/SpiceBot/Spicemanip.py index 0ea8479..8fda903 100644 --- a/sopel_modules/SpiceBot/Spicemanip.py +++ b/sopel_modules/SpiceBot/Spicemanip.py @@ -17,7 +17,8 @@ class spicemanipnew(): self.inputs = inputs self.inputs_list = self.input_handler(self.inputs) - return self.inputs_list + self.output_type = output_type + self.main = self.core() def input_handler(self, inputs): # Input needs to be a list, but don't split a word into letters @@ -39,8 +40,7 @@ class spicemanipnew(): return outputs def core(self, inputs=None, task='create', output_type=None): - if not inputs: - return self.output_handler([""], output_type=None) + return self.inputs_list """ # Hub From 35a1b2104bf5991e6206b395ba88790457884144 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 12:45:54 -0400 Subject: [PATCH 25/96] test --- sopel_modules/SpiceBot/Spicemanip.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Spicemanip.py b/sopel_modules/SpiceBot/Spicemanip.py index 8fda903..54ff79e 100644 --- a/sopel_modules/SpiceBot/Spicemanip.py +++ b/sopel_modules/SpiceBot/Spicemanip.py @@ -18,7 +18,6 @@ class spicemanipnew(): self.inputs = inputs self.inputs_list = self.input_handler(self.inputs) self.output_type = output_type - self.main = self.core() def input_handler(self, inputs): # Input needs to be a list, but don't split a word into letters @@ -39,7 +38,7 @@ class spicemanipnew(): output_type = "list" return outputs - def core(self, inputs=None, task='create', output_type=None): + def core(self): return self.inputs_list """ From 3e977ab95d846311730a4fa5ae800b722f0e5cb0 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 12:49:45 -0400 Subject: [PATCH 26/96] test --- sopel_modules/SpiceBot/Spicemanip.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sopel_modules/SpiceBot/Spicemanip.py b/sopel_modules/SpiceBot/Spicemanip.py index 54ff79e..619a39a 100644 --- a/sopel_modules/SpiceBot/Spicemanip.py +++ b/sopel_modules/SpiceBot/Spicemanip.py @@ -13,11 +13,9 @@ import collections class spicemanipnew(): - def __init__(self, inputs, output_type=None): + def __init__(self): - self.inputs = inputs - self.inputs_list = self.input_handler(self.inputs) - self.output_type = output_type + self.dict = {} def input_handler(self, inputs): # Input needs to be a list, but don't split a word into letters @@ -38,7 +36,10 @@ class spicemanipnew(): output_type = "list" return outputs - def core(self): + def core(self, inputs, output_type=None): + self.inputs = inputs + self.inputs_list = self.input_handler(self.inputs) + self.output_type = output_type return self.inputs_list """ From dcab296d7c50a080f3b237907dd4027816ea4831 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 12:51:43 -0400 Subject: [PATCH 27/96] test --- sopel_modules/SpiceBot/Spicemanip.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Spicemanip.py b/sopel_modules/SpiceBot/Spicemanip.py index 619a39a..a89d396 100644 --- a/sopel_modules/SpiceBot/Spicemanip.py +++ b/sopel_modules/SpiceBot/Spicemanip.py @@ -14,8 +14,7 @@ import collections class spicemanipnew(): def __init__(self): - - self.dict = {} + pass def input_handler(self, inputs): # Input needs to be a list, but don't split a word into letters From be7072f42a582113e642654fc10e6433473a60d7 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 12:53:15 -0400 Subject: [PATCH 28/96] test --- sopel_modules/SpiceBot/Spicemanip.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Spicemanip.py b/sopel_modules/SpiceBot/Spicemanip.py index a89d396..b6f8937 100644 --- a/sopel_modules/SpiceBot/Spicemanip.py +++ b/sopel_modules/SpiceBot/Spicemanip.py @@ -13,7 +13,7 @@ import collections class spicemanipnew(): - def __init__(self): + def __init__(self, inputs, task, output_type=None): pass def input_handler(self, inputs): @@ -35,7 +35,7 @@ class spicemanipnew(): output_type = "list" return outputs - def core(self, inputs, output_type=None): + def core(self, inputs, task, output_type=None): self.inputs = inputs self.inputs_list = self.input_handler(self.inputs) self.output_type = output_type From 34ed743ad83ab4f42f1091c678644738a038ab94 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 13:04:40 -0400 Subject: [PATCH 29/96] test --- sopel_modules/SpiceBot/Spicemanip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Spicemanip.py b/sopel_modules/SpiceBot/Spicemanip.py index b6f8937..f3f21ff 100644 --- a/sopel_modules/SpiceBot/Spicemanip.py +++ b/sopel_modules/SpiceBot/Spicemanip.py @@ -14,7 +14,7 @@ import collections class spicemanipnew(): def __init__(self, inputs, task, output_type=None): - pass + self.test = "test" def input_handler(self, inputs): # Input needs to be a list, but don't split a word into letters From 5a95c8c500e2e95058ecdba77d81533451865fc5 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 13:08:26 -0400 Subject: [PATCH 30/96] spicemanip directly in this repo --- sopel_modules/SpiceBot/AI.py | 2 +- sopel_modules/SpiceBot/Commands.py | 2 +- sopel_modules/SpiceBot/Gif.py | 2 +- sopel_modules/SpiceBot/Logs.py | 2 +- sopel_modules/SpiceBot/Prerun.py | 2 +- sopel_modules/SpiceBot/Reddit.py | 2 +- sopel_modules/SpiceBot/Spicemanip.py | 354 ---------------- sopel_modules/SpiceBot/Tools.py | 2 +- sopel_modules/SpiceBot/Translate.py | 2 +- sopel_modules/SpiceBot/Users.py | 2 +- sopel_modules/SpiceBot/__init__.py | 1 - sopel_modules/SpiceBot_Core_Commands/AI.py | 2 +- .../SpiceBot_Core_Commands/BotPrivs.py | 2 +- .../SpiceBot_Core_Commands/Channels.py | 2 +- .../SpiceBot_Core_Commands/Commands.py | 2 +- .../SpiceBot_Core_Commands/CommandsQuery.py | 2 +- .../SpiceBot_Core_Commands/DictComs.py | 2 +- sopel_modules/SpiceBot_Core_Commands/Gif.py | 2 +- sopel_modules/SpiceBot_Core_Commands/Logs.py | 2 +- .../SpiceBot_Core_Commands/Messaging.py | 2 +- .../Runtime_Controls.py | 2 +- .../SpiceBot_Core_Commands/Search.py | 2 +- .../SpiceBot_Core_Commands/Sherlock.py | 2 +- .../SpiceBot_Core_Processing/Channels.py | 2 +- sopel_modules/spicemanip/__init__.py | 378 ++++++++++++++++++ 25 files changed, 400 insertions(+), 377 deletions(-) delete mode 100644 sopel_modules/SpiceBot/Spicemanip.py create mode 100644 sopel_modules/spicemanip/__init__.py diff --git a/sopel_modules/SpiceBot/AI.py b/sopel_modules/SpiceBot/AI.py index afa7dcd..6707f40 100644 --- a/sopel_modules/SpiceBot/AI.py +++ b/sopel_modules/SpiceBot/AI.py @@ -15,7 +15,7 @@ from .Database import db as botdb from .Config import config as botconfig from .Read import read as botread -import spicemanip +import sopel_modules.spicemanip as spicemanip class SpiceBot_AI_MainSection(StaticSection): diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index 099bc53..0a5b1c2 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -13,7 +13,7 @@ import os import threading import copy -import spicemanip +import sopel_modules.spicemanip as spicemanip import sopel_modules from .Logs import logs diff --git a/sopel_modules/SpiceBot/Gif.py b/sopel_modules/SpiceBot/Gif.py index 83239d3..91ed569 100644 --- a/sopel_modules/SpiceBot/Gif.py +++ b/sopel_modules/SpiceBot/Gif.py @@ -8,7 +8,7 @@ from .Config import config as botconfig from .Read import read as botread from .Commands import commands as botcommands -import spicemanip +import sopel_modules.spicemanip as spicemanip from fake_useragent import UserAgent import urllib diff --git a/sopel_modules/SpiceBot/Logs.py b/sopel_modules/SpiceBot/Logs.py index ac6fc15..146f28c 100644 --- a/sopel_modules/SpiceBot/Logs.py +++ b/sopel_modules/SpiceBot/Logs.py @@ -9,7 +9,7 @@ This Class stores logs in an easy to access manner import threading import os import sys -import spicemanip +import sopel_modules.spicemanip as spicemanip from .Config import config as botconfig diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 3b83839..33bbd4d 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -11,7 +11,7 @@ import copy import datetime from word2number import w2n -import spicemanip +import sopel_modules.spicemanip as spicemanip from .Tools import command_permissions_check, class_create from .Commands import commands as botcommands diff --git a/sopel_modules/SpiceBot/Reddit.py b/sopel_modules/SpiceBot/Reddit.py index ee439d1..778eb25 100644 --- a/sopel_modules/SpiceBot/Reddit.py +++ b/sopel_modules/SpiceBot/Reddit.py @@ -7,7 +7,7 @@ This is the SpiceBot Reddit system. from sopel.config.types import StaticSection, ValidatedAttribute from sopel.formatting import bold, color, colors -import spicemanip +import sopel_modules.spicemanip as spicemanip import datetime as dt import praw diff --git a/sopel_modules/SpiceBot/Spicemanip.py b/sopel_modules/SpiceBot/Spicemanip.py deleted file mode 100644 index f3f21ff..0000000 --- a/sopel_modules/SpiceBot/Spicemanip.py +++ /dev/null @@ -1,354 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -"""Top-level package for spicemanip.""" - -__author__ = """Sam Zick""" -__email__ = 'sam@deathbybandaid.net' -__version__ = '0.1.7' - -# import random -import collections - - -class spicemanipnew(): - - def __init__(self, inputs, task, output_type=None): - self.test = "test" - - def input_handler(self, inputs): - # Input needs to be a list, but don't split a word into letters - if not inputs: - inputs = [] - if isinstance(inputs, collections.abc.KeysView): - inputs = list(inputs) - elif isinstance(inputs, dict): - inputs = list(inputs.keys()) - if not isinstance(inputs, list): - inputs = list(inputs.split(" ")) - inputs = [x for x in inputs if x and x not in ['', ' ']] - inputs = [inputspart.strip() for inputspart in inputs] - return inputs - - def output_handler(self, outputs, output_type=None): - if not output_type: - output_type = "list" - return outputs - - def core(self, inputs, task, output_type=None): - self.inputs = inputs - self.inputs_list = self.input_handler(self.inputs) - self.output_type = output_type - return self.inputs_list - - """ - # Hub - def main(self, inputs, outputtask, output_type='default'): - - # TODO 'this*that' or '1*that' replace either all strings matching, or an index value - # TODO reverse sort z.sort(reverse = True) - # list.extend adds lists to eachother - - mainoutputtask, suboutputtask = None, None - - # Input needs to be a list, but don't split a word into letters - if not inputs: - inputs = [] - if isinstance(inputs, collections.abc.KeysView): - inputs = list(inputs) - elif isinstance(inputs, dict): - inputs = list(inputs.keys()) - if not isinstance(inputs, list): - inputs = list(inputs.split(" ")) - inputs = [x for x in inputs if x and x not in ['', ' ']] - inputs = [inputspart.strip() for inputspart in inputs] - - # Create return - if outputtask == 'create': - return inputs - - # Make temparray to preserve original order - temparray = [] - for inputpart in inputs: - temparray.append(inputpart) - inputs = temparray - - # Convert outputtask to standard - if outputtask in [0, 'complete']: - outputtask = 'string' - elif outputtask == 'index': - mainoutputtask = inputs[1] - suboutputtask = inputs[2] - inputs = inputs[0] - elif str(outputtask).isdigit(): - mainoutputtask, outputtask = int(outputtask), 'number' - elif "^" in str(outputtask): - mainoutputtask = str(outputtask).split("^", 1)[0] - suboutputtask = str(outputtask).split("^", 1)[1] - outputtask = 'rangebetween' - if int(suboutputtask) < int(mainoutputtask): - mainoutputtask, suboutputtask = suboutputtask, mainoutputtask - elif str(outputtask).startswith("split_"): - mainoutputtask = str(outputtask).replace("split_", "") - outputtask = 'split' - elif str(outputtask).endswith(tuple(["!", "+", "-", "<", ">"])): - mainoutputtask = str(outputtask) - if str(outputtask).endswith("!"): - outputtask = 'exclude' - if str(outputtask).endswith("+"): - outputtask = 'incrange_plus' - if str(outputtask).endswith("-"): - outputtask = 'incrange_minus' - if str(outputtask).endswith(">"): - outputtask = 'excrange_plus' - if str(outputtask).endswith("<"): - outputtask = 'excrange_minus' - for r in (("!", ""), ("+", ""), ("-", ""), ("<", ""), (">", "")): - mainoutputtask = mainoutputtask.replace(*r) - if mainoutputtask == 'last': - mainoutputtask = len(inputs) - - if outputtask == 'string': - returnvalue = inputs - else: - returnvalue = eval('spicemanip_' + outputtask + '(inputs, outputtask, mainoutputtask, suboutputtask)') - - # default return if not specified - if output_type == 'default': - if outputtask in [ - 'string', 'number', 'rangebetween', 'exclude', 'random', - 'incrange_plus', 'incrange_minus', 'excrange_plus', 'excrange_minus' - ]: - output_type = 'string' - elif outputtask in ['count']: - output_type = 'dict' - - # verify output is correct - if output_type == 'return': - return returnvalue - if output_type == 'string': - if isinstance(returnvalue, list): - returnvalue = ' '.join(returnvalue) - elif output_type in ['list', 'array']: - if not isinstance(returnvalue, list): - returnvalue = list(returnvalue.split(" ")) - returnvalue = [x for x in returnvalue if x and x not in ['', ' ']] - returnvalue = [inputspart.strip() for inputspart in returnvalue] - return returnvalue - - # compare 2 lists, based on the location of an index item, passthrough needs to be [indexitem, arraytoindex, arraytocompare] - def spicemanip_index(self, indexitem, outputtask, arraytoindex, arraytocompare): - item = '' - for x, y in zip(arraytoindex, arraytocompare): - if x == indexitem: - item = y - return item - - # split list by string - def spicemanip_split(self, inputs, outputtask, mainoutputtask, suboutputtask): - split_array = [] - restring = ' '.join(inputs) - if mainoutputtask not in inputs: - split_array = [restring] - else: - split_array = restring.split(mainoutputtask) - split_array = [x for x in split_array if x and x not in ['', ' ']] - split_array = [inputspart.strip() for inputspart in split_array] - if split_array == []: - split_array = [[]] - return split_array - - # dedupe list - def spicemanip_dedupe(self, inputs, outputtask, mainoutputtask, suboutputtask): - newlist = [] - for inputspart in inputs: - if inputspart not in newlist: - newlist.append(inputspart) - return newlist - - # Sort list - def spicemanip_sort(self, inputs, outputtask, mainoutputtask, suboutputtask): - return sorted(inputs) - - # reverse sort list - def spicemanip_rsort(self, inputs, outputtask, mainoutputtask, suboutputtask): - return sorted(inputs)[::-1] - - # count items in list, return dictionary - def spicemanip_count(self, inputs, outputtask, mainoutputtask, suboutputtask): - returndict = dict() - if inputs == []: - return returndict - uniqueinputitems, uniquecount = [], [] - for inputspart in inputs: - if inputspart not in uniqueinputitems: - uniqueinputitems.append(inputspart) - for uniqueinputspart in uniqueinputitems: - count = 0 - for ele in inputs: - if (ele == uniqueinputspart): - count += 1 - uniquecount.append(count) - for inputsitem, unumber in zip(uniqueinputitems, uniquecount): - returndict[inputsitem] = unumber - return returndict - - # random item from list - def spicemanip_random(self, inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: - return '' - randomselectlist = [] - for temppart in inputs: - randomselectlist.append(temppart) - while len(randomselectlist) > 1: - random.shuffle(randomselectlist) - randomselect = randomselectlist[random.randint(0, len(randomselectlist) - 1)] - randomselectlist.remove(randomselect) - randomselect = randomselectlist[0] - return randomselect - - # remove random item from list - def spicemanip_exrandom(self, inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: - return [] - randremove = self.spicemanip_random(inputs, outputtask, mainoutputtask, suboutputtask) - inputs.remove(randremove) - return inputs - - # Convert list into lowercase - def spicemanip_lower(self, inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: - return '' - return [inputspart.lower() for inputspart in inputs] - - # Convert list to uppercase - def spicemanip_upper(self, inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: - return '' - return [inputspart.upper() for inputspart in inputs] - - # Convert list to uppercase - def spicemanip_title(self, inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: - return '' - return [inputspart.title() for inputspart in inputs] - - # Reverse List Order - def spicemanip_reverse(self, inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: - return [] - return inputs[::-1] - - # comma seperated list - def spicemanip_list(self, inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: - return '' - return ', '.join(str(x) for x in inputs) - - def spicemanip_list_nospace(self, inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: - return '' - return ','.join(str(x) for x in inputs) - - # comma seperated list with and - def spicemanip_andlist(self, inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: - return '' - if len(inputs) < 2: - return ' '.join(inputs) - lastentry = str("and " + str(inputs[len(inputs) - 1])) - del inputs[-1] - inputs.append(lastentry) - if len(inputs) == 2: - return ' '.join(inputs) - return ', '.join(str(x) for x in inputs) - - # comma seperated list with or - def spicemanip_orlist(self, inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: - return '' - if len(inputs) < 2: - return ' '.join(inputs) - lastentry = str("or " + str(inputs[len(inputs) - 1])) - del inputs[-1] - inputs.append(lastentry) - if len(inputs) == 2: - return ' '.join(inputs) - return ', '.join(str(x) for x in inputs) - - # exclude number - def spicemanip_exclude(self, inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: - return '' - del inputs[int(mainoutputtask) - 1] - return ' '.join(inputs) - - # Convert list to string - def spicemanip_string(self, inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: - return '' - return ' '.join(inputs) - - # Get number item from list - def spicemanip_number(self, inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: - return '' - elif len(inputs) == 1: - return inputs[0] - elif int(mainoutputtask) > len(inputs) or int(mainoutputtask) < 0: - return '' - else: - return inputs[int(mainoutputtask) - 1] - - # Get Last item from list - def spicemanip_last(self, inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: - return '' - return inputs[len(inputs) - 1] - - # range between items in list - def spicemanip_rangebetween(self, inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: - return '' - if not str(mainoutputtask).isdigit() or not str(suboutputtask).isdigit(): - return '' - mainoutputtask, suboutputtask = int(mainoutputtask), int(suboutputtask) - if suboutputtask == mainoutputtask: - return self.spicemanip_number(inputs, outputtask, mainoutputtask, suboutputtask) - if suboutputtask < mainoutputtask: - return [] - if mainoutputtask < 0: - mainoutputtask = 1 - if suboutputtask > len(inputs): - suboutputtask = len(inputs) - newlist = [] - for i in range(mainoutputtask, suboutputtask + 1): - newlist.append(str(self.spicemanip_number(inputs, outputtask, i, suboutputtask))) - if newlist == []: - return '' - return ' '.join(newlist) - - # Forward Range includes index number - def spicemanip_incrange_plus(self, inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: - return '' - return self.spicemanip_rangebetween(inputs, outputtask, int(mainoutputtask), len(inputs)) - - # Reverse Range includes index number - def spicemanip_incrange_minus(self, inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: - return '' - return self.spicemanip_rangebetween(inputs, outputtask, 1, int(mainoutputtask)) - - # Forward Range excludes index number - def spicemanip_excrange_plus(self, inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: - return '' - return self.spicemanip_rangebetween(inputs, outputtask, int(mainoutputtask) + 1, len(inputs)) - - # Reverse Range excludes index number - def spicemanip_excrange_minus(self, inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: - return '' - return self.spicemanip_rangebetween(inputs, outputtask, 1, int(mainoutputtask) - 1) -""" diff --git a/sopel_modules/SpiceBot/Tools.py b/sopel_modules/SpiceBot/Tools.py index 8e989a4..83b483f 100644 --- a/sopel_modules/SpiceBot/Tools.py +++ b/sopel_modules/SpiceBot/Tools.py @@ -14,7 +14,7 @@ from operator import itemgetter from collections import abc from pygit2 import clone_repository -import spicemanip +import sopel_modules.spicemanip as spicemanip from .Logs import logs from .Config import config as botconfig diff --git a/sopel_modules/SpiceBot/Translate.py b/sopel_modules/SpiceBot/Translate.py index 380e5dc..c43adf4 100644 --- a/sopel_modules/SpiceBot/Translate.py +++ b/sopel_modules/SpiceBot/Translate.py @@ -1,7 +1,7 @@ # coding=utf8 from __future__ import unicode_literals, absolute_import, division, print_function -import spicemanip +import sopel_modules.spicemanip as spicemanip import re from num2words import num2words diff --git a/sopel_modules/SpiceBot/Users.py b/sopel_modules/SpiceBot/Users.py index bd67ca7..5eb26c3 100644 --- a/sopel_modules/SpiceBot/Users.py +++ b/sopel_modules/SpiceBot/Users.py @@ -8,7 +8,7 @@ from sopel.tools import Identifier from .Database import db as botdb from .Tools import is_number, inlist, similar, array_arrangesort -import spicemanip +import sopel_modules.spicemanip as spicemanip import threading import re diff --git a/sopel_modules/SpiceBot/__init__.py b/sopel_modules/SpiceBot/__init__.py index 864da66..e0836fa 100644 --- a/sopel_modules/SpiceBot/__init__.py +++ b/sopel_modules/SpiceBot/__init__.py @@ -11,7 +11,6 @@ from .Config import * from .Logs import * from .Database import * from .MessageLog import * -from .Spicemanip import * from .Update import * from .osd import * diff --git a/sopel_modules/SpiceBot_Core_Commands/AI.py b/sopel_modules/SpiceBot_Core_Commands/AI.py index a04f7b8..fe925fa 100644 --- a/sopel_modules/SpiceBot_Core_Commands/AI.py +++ b/sopel_modules/SpiceBot_Core_Commands/AI.py @@ -6,7 +6,7 @@ import sopel.module import sopel_modules.SpiceBot as SpiceBot -import spicemanip +import sopel_modules.spicemanip as spicemanip @SpiceBot.prerun('nickname') diff --git a/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py b/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py index f67a7c8..4bd9626 100644 --- a/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py +++ b/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module -import spicemanip +import sopel_modules.spicemanip as spicemanip import sopel_modules.SpiceBot as SpiceBot diff --git a/sopel_modules/SpiceBot_Core_Commands/Channels.py b/sopel_modules/SpiceBot_Core_Commands/Channels.py index 8a5acb3..75e71e4 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Channels.py +++ b/sopel_modules/SpiceBot_Core_Commands/Channels.py @@ -5,7 +5,7 @@ This is the SpiceBot Channels system. """ import sopel -import spicemanip +import sopel_modules.spicemanip as spicemanip import sopel_modules.SpiceBot as SpiceBot diff --git a/sopel_modules/SpiceBot_Core_Commands/Commands.py b/sopel_modules/SpiceBot_Core_Commands/Commands.py index 624047d..e809343 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Commands.py +++ b/sopel_modules/SpiceBot_Core_Commands/Commands.py @@ -7,7 +7,7 @@ This Class stores commands in an easy to access manner """ import sopel -import spicemanip +import sopel_modules.spicemanip as spicemanip import sopel_modules.SpiceBot as SpiceBot diff --git a/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py b/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py index d9c9e73..9e1818b 100644 --- a/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py +++ b/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py @@ -7,7 +7,7 @@ This Class stores commands in an easy to access manner """ import sopel -import spicemanip +import sopel_modules.spicemanip as spicemanip import sopel_modules.SpiceBot as SpiceBot diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index 9de6850..46aabf7 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -9,7 +9,7 @@ import sopel.module import sopel_modules.SpiceBot as SpiceBot -import spicemanip +import sopel_modules.spicemanip as spicemanip from word2number import w2n from random import randint diff --git a/sopel_modules/SpiceBot_Core_Commands/Gif.py b/sopel_modules/SpiceBot_Core_Commands/Gif.py index 41fc1e9..fa072cd 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Gif.py +++ b/sopel_modules/SpiceBot_Core_Commands/Gif.py @@ -6,7 +6,7 @@ import sopel.module import sopel_modules.SpiceBot as SpiceBot -import spicemanip +import sopel_modules.spicemanip as spicemanip # TODO custom gif shortcut commands diff --git a/sopel_modules/SpiceBot_Core_Commands/Logs.py b/sopel_modules/SpiceBot_Core_Commands/Logs.py index 9928540..3e224ed 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Logs.py +++ b/sopel_modules/SpiceBot_Core_Commands/Logs.py @@ -7,7 +7,7 @@ This is the SpiceBot Logs System # sopel imports import sopel.module -import spicemanip +import sopel_modules.spicemanip as spicemanip import sopel_modules.SpiceBot as SpiceBot diff --git a/sopel_modules/SpiceBot_Core_Commands/Messaging.py b/sopel_modules/SpiceBot_Core_Commands/Messaging.py index 27c8385..61ace21 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Messaging.py +++ b/sopel_modules/SpiceBot_Core_Commands/Messaging.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module -import spicemanip +import sopel_modules.spicemanip as spicemanip import sopel_modules.SpiceBot as SpiceBot diff --git a/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py b/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py index 4d8b330..14cedae 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py +++ b/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module -import spicemanip +import sopel_modules.spicemanip as spicemanip import sopel_modules.SpiceBot as SpiceBot diff --git a/sopel_modules/SpiceBot_Core_Commands/Search.py b/sopel_modules/SpiceBot_Core_Commands/Search.py index 8fd621b..d8b86f3 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Search.py +++ b/sopel_modules/SpiceBot_Core_Commands/Search.py @@ -5,7 +5,7 @@ This is the SpiceBot search system. """ import sopel -import spicemanip +import sopel_modules.spicemanip as spicemanip import sopel_modules.SpiceBot as SpiceBot diff --git a/sopel_modules/SpiceBot_Core_Commands/Sherlock.py b/sopel_modules/SpiceBot_Core_Commands/Sherlock.py index cd688d3..2310682 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Sherlock.py +++ b/sopel_modules/SpiceBot_Core_Commands/Sherlock.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi # sopel imports import sopel.module -import spicemanip +import sopel_modules.spicemanip as spicemanip import sopel_modules.SpiceBot as SpiceBot diff --git a/sopel_modules/SpiceBot_Core_Processing/Channels.py b/sopel_modules/SpiceBot_Core_Processing/Channels.py index 09940fd..1fc0cf9 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Channels.py +++ b/sopel_modules/SpiceBot_Core_Processing/Channels.py @@ -7,7 +7,7 @@ import sopel import time -import spicemanip +import sopel_modules.spicemanip as spicemanip import sopel_modules.SpiceBot as SpiceBot diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py new file mode 100644 index 0000000..6efc5da --- /dev/null +++ b/sopel_modules/spicemanip/__init__.py @@ -0,0 +1,378 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +"""Top-level package for spicemanip.""" + +__author__ = """Sam Zick""" +__email__ = 'sam@deathbybandaid.net' +__version__ = '0.1.8' + +import random +import collections + + +class spicemanipnew(): + + def __init__(self, inputs, task, output_type=None): + self.test = "test" + + def input_handler(self, inputs): + # Input needs to be a list, but don't split a word into letters + if not inputs: + inputs = [] + if isinstance(inputs, collections.abc.KeysView): + inputs = list(inputs) + elif isinstance(inputs, dict): + inputs = list(inputs.keys()) + if not isinstance(inputs, list): + inputs = list(inputs.split(" ")) + inputs = [x for x in inputs if x and x not in ['', ' ']] + inputs = [inputspart.strip() for inputspart in inputs] + return inputs + + def output_handler(self, outputs, output_type=None): + if not output_type: + output_type = "list" + return outputs + + def core(self, inputs, task, output_type=None): + self.inputs = inputs + self.inputs_list = self.input_handler(self.inputs) + self.output_type = output_type + return self.inputs_list + + +# Hub +def main(inputs, outputtask, output_type='default'): + + # TODO 'this*that' or '1*that' replace either all strings matching, or an index value + # TODO reverse sort z.sort(reverse = True) + # list.extend adds lists to eachother + + mainoutputtask, suboutputtask = None, None + + # Input needs to be a list, but don't split a word into letters + if not inputs: + inputs = [] + if isinstance(inputs, collections.abc.KeysView): + inputs = list(inputs) + elif isinstance(inputs, dict): + inputs = list(inputs.keys()) + if not isinstance(inputs, list): + inputs = list(inputs.split(" ")) + inputs = [x for x in inputs if x and x not in ['', ' ']] + inputs = [inputspart.strip() for inputspart in inputs] + + # Create return + if outputtask == 'create': + return inputs + + # Make temparray to preserve original order + temparray = [] + for inputpart in inputs: + temparray.append(inputpart) + inputs = temparray + + # Convert outputtask to standard + if outputtask in [0, 'complete']: + outputtask = 'string' + elif outputtask == 'index': + mainoutputtask = inputs[1] + suboutputtask = inputs[2] + inputs = inputs[0] + elif str(outputtask).isdigit(): + mainoutputtask, outputtask = int(outputtask), 'number' + elif "^" in str(outputtask): + mainoutputtask = str(outputtask).split("^", 1)[0] + suboutputtask = str(outputtask).split("^", 1)[1] + outputtask = 'rangebetween' + if int(suboutputtask) < int(mainoutputtask): + mainoutputtask, suboutputtask = suboutputtask, mainoutputtask + elif str(outputtask).startswith("split_"): + mainoutputtask = str(outputtask).replace("split_", "") + outputtask = 'split' + elif str(outputtask).endswith(tuple(["!", "+", "-", "<", ">"])): + mainoutputtask = str(outputtask) + if str(outputtask).endswith("!"): + outputtask = 'exclude' + if str(outputtask).endswith("+"): + outputtask = 'incrange_plus' + if str(outputtask).endswith("-"): + outputtask = 'incrange_minus' + if str(outputtask).endswith(">"): + outputtask = 'excrange_plus' + if str(outputtask).endswith("<"): + outputtask = 'excrange_minus' + for r in (("!", ""), ("+", ""), ("-", ""), ("<", ""), (">", "")): + mainoutputtask = mainoutputtask.replace(*r) + if mainoutputtask == 'last': + mainoutputtask = len(inputs) + + if outputtask == 'string': + returnvalue = inputs + else: + returnvalue = eval('spicemanip_' + outputtask + '(inputs, outputtask, mainoutputtask, suboutputtask)') + + # default return if not specified + if output_type == 'default': + if outputtask in [ + 'string', 'number', 'rangebetween', 'exclude', 'random', + 'incrange_plus', 'incrange_minus', 'excrange_plus', 'excrange_minus' + ]: + output_type = 'string' + elif outputtask in ['count']: + output_type = 'dict' + + # verify output is correct + if output_type == 'return': + return returnvalue + if output_type == 'string': + if isinstance(returnvalue, list): + returnvalue = ' '.join(returnvalue) + elif output_type in ['list', 'array']: + if not isinstance(returnvalue, list): + returnvalue = list(returnvalue.split(" ")) + returnvalue = [x for x in returnvalue if x and x not in ['', ' ']] + returnvalue = [inputspart.strip() for inputspart in returnvalue] + return returnvalue + + +# compare 2 lists, based on the location of an index item, passthrough needs to be [indexitem, arraytoindex, arraytocompare] +def spicemanip_index(indexitem, outputtask, arraytoindex, arraytocompare): + item = '' + for x, y in zip(arraytoindex, arraytocompare): + if x == indexitem: + item = y + return item + + +# split list by string +def spicemanip_split(inputs, outputtask, mainoutputtask, suboutputtask): + split_array = [] + restring = ' '.join(inputs) + if mainoutputtask not in inputs: + split_array = [restring] + else: + split_array = restring.split(mainoutputtask) + split_array = [x for x in split_array if x and x not in ['', ' ']] + split_array = [inputspart.strip() for inputspart in split_array] + if split_array == []: + split_array = [[]] + return split_array + + +# dedupe list +def spicemanip_dedupe(inputs, outputtask, mainoutputtask, suboutputtask): + newlist = [] + for inputspart in inputs: + if inputspart not in newlist: + newlist.append(inputspart) + return newlist + + +# Sort list +def spicemanip_sort(inputs, outputtask, mainoutputtask, suboutputtask): + return sorted(inputs) + + +# reverse sort list +def spicemanip_rsort(inputs, outputtask, mainoutputtask, suboutputtask): + return sorted(inputs)[::-1] + + +# count items in list, return dictionary +def spicemanip_count(inputs, outputtask, mainoutputtask, suboutputtask): + returndict = dict() + if inputs == []: + return returndict + uniqueinputitems, uniquecount = [], [] + for inputspart in inputs: + if inputspart not in uniqueinputitems: + uniqueinputitems.append(inputspart) + for uniqueinputspart in uniqueinputitems: + count = 0 + for ele in inputs: + if (ele == uniqueinputspart): + count += 1 + uniquecount.append(count) + for inputsitem, unumber in zip(uniqueinputitems, uniquecount): + returndict[inputsitem] = unumber + return returndict + + +# random item from list +def spicemanip_random(inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + randomselectlist = [] + for temppart in inputs: + randomselectlist.append(temppart) + while len(randomselectlist) > 1: + random.shuffle(randomselectlist) + randomselect = randomselectlist[random.randint(0, len(randomselectlist) - 1)] + randomselectlist.remove(randomselect) + randomselect = randomselectlist[0] + return randomselect + + +# remove random item from list +def spicemanip_exrandom(inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return [] + randremove = spicemanip_random(inputs, outputtask, mainoutputtask, suboutputtask) + inputs.remove(randremove) + return inputs + + +# Convert list into lowercase +def spicemanip_lower(inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return [inputspart.lower() for inputspart in inputs] + + +# Convert list to uppercase +def spicemanip_upper(inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return [inputspart.upper() for inputspart in inputs] + + +# Convert list to uppercase +def spicemanip_title(inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return [inputspart.title() for inputspart in inputs] + + +# Reverse List Order +def spicemanip_reverse(inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return [] + return inputs[::-1] + + +# comma seperated list +def spicemanip_list(inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return ', '.join(str(x) for x in inputs) + + +def spicemanip_list_nospace(inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return ','.join(str(x) for x in inputs) + + +# comma seperated list with and +def spicemanip_andlist(inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + if len(inputs) < 2: + return ' '.join(inputs) + lastentry = str("and " + str(inputs[len(inputs) - 1])) + del inputs[-1] + inputs.append(lastentry) + if len(inputs) == 2: + return ' '.join(inputs) + return ', '.join(str(x) for x in inputs) + + +# comma seperated list with or +def spicemanip_orlist(inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + if len(inputs) < 2: + return ' '.join(inputs) + lastentry = str("or " + str(inputs[len(inputs) - 1])) + del inputs[-1] + inputs.append(lastentry) + if len(inputs) == 2: + return ' '.join(inputs) + return ', '.join(str(x) for x in inputs) + + +# exclude number +def spicemanip_exclude(inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + del inputs[int(mainoutputtask) - 1] + return ' '.join(inputs) + + +# Convert list to string +def spicemanip_string(inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return ' '.join(inputs) + + +# Get number item from list +def spicemanip_number(inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + elif len(inputs) == 1: + return inputs[0] + elif int(mainoutputtask) > len(inputs) or int(mainoutputtask) < 0: + return '' + else: + return inputs[int(mainoutputtask) - 1] + + +# Get Last item from list +def spicemanip_last(inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return inputs[len(inputs) - 1] + + +# range between items in list +def spicemanip_rangebetween(inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + if not str(mainoutputtask).isdigit() or not str(suboutputtask).isdigit(): + return '' + mainoutputtask, suboutputtask = int(mainoutputtask), int(suboutputtask) + if suboutputtask == mainoutputtask: + return spicemanip_number(inputs, outputtask, mainoutputtask, suboutputtask) + if suboutputtask < mainoutputtask: + return [] + if mainoutputtask < 0: + mainoutputtask = 1 + if suboutputtask > len(inputs): + suboutputtask = len(inputs) + newlist = [] + for i in range(mainoutputtask, suboutputtask + 1): + newlist.append(str(spicemanip_number(inputs, outputtask, i, suboutputtask))) + if newlist == []: + return '' + return ' '.join(newlist) + + +# Forward Range includes index number +def spicemanip_incrange_plus(inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return spicemanip_rangebetween(inputs, outputtask, int(mainoutputtask), len(inputs)) + + +# Reverse Range includes index number +def spicemanip_incrange_minus(inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return spicemanip_rangebetween(inputs, outputtask, 1, int(mainoutputtask)) + + +# Forward Range excludes index number +def spicemanip_excrange_plus(inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return spicemanip_rangebetween(inputs, outputtask, int(mainoutputtask) + 1, len(inputs)) + + +# Reverse Range excludes index number +def spicemanip_excrange_minus(inputs, outputtask, mainoutputtask, suboutputtask): + if inputs == []: + return '' + return spicemanip_rangebetween(inputs, outputtask, 1, int(mainoutputtask) - 1) From 7a455a9199149c3052d00a40acd288dcabdafc66 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 13:15:24 -0400 Subject: [PATCH 31/96] test --- sopel_modules/spicemanip/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 6efc5da..f1c8d0f 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -13,8 +13,8 @@ import collections class spicemanipnew(): - def __init__(self, inputs, task, output_type=None): - self.test = "test" + def __init__(self): + pass def input_handler(self, inputs): # Input needs to be a list, but don't split a word into letters @@ -42,6 +42,9 @@ class spicemanipnew(): return self.inputs_list +core = spicemanipnew() + + # Hub def main(inputs, outputtask, output_type='default'): From 3266821849cfc0d8e0b239e96140a7049b16c2a1 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 13:16:50 -0400 Subject: [PATCH 32/96] test --- sopel_modules/spicemanip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index f1c8d0f..c6ba6d0 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -14,7 +14,7 @@ import collections class spicemanipnew(): def __init__(self): - pass + self.test = "test" def input_handler(self, inputs): # Input needs to be a list, but don't split a word into letters From 5dd2f49008273f734d617f5ff228b3690049d1db Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 13:20:19 -0400 Subject: [PATCH 33/96] test --- sopel_modules/spicemanip/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index c6ba6d0..197bc8f 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -11,7 +11,7 @@ import random import collections -class spicemanipnew(): +class Spicemanip(): def __init__(self): self.test = "test" @@ -42,7 +42,7 @@ class spicemanipnew(): return self.inputs_list -core = spicemanipnew() +core = Spicemanip() # Hub From 27752191b6152b0961c67e8d169b823c5031ce65 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 13:22:16 -0400 Subject: [PATCH 34/96] test --- sopel_modules/spicemanip/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 197bc8f..601c172 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -14,7 +14,10 @@ import collections class Spicemanip(): def __init__(self): - self.test = "test" + pass + + def __call__(self): + return self def input_handler(self, inputs): # Input needs to be a list, but don't split a word into letters From 21743cda7e76dae68f17daf85779f99ea8ae5b98 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 13:23:57 -0400 Subject: [PATCH 35/96] test --- sopel_modules/spicemanip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 601c172..dea1a32 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -16,7 +16,7 @@ class Spicemanip(): def __init__(self): pass - def __call__(self): + def __call__(self, inputs, task=None, output_type=None): return self def input_handler(self, inputs): From df9b2e8f40c41ec64240bc1e01746808bc242d23 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 13:24:54 -0400 Subject: [PATCH 36/96] test --- sopel_modules/spicemanip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index dea1a32..e0427ba 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -17,7 +17,7 @@ class Spicemanip(): pass def __call__(self, inputs, task=None, output_type=None): - return self + return self.core(inputs, task, output_type) def input_handler(self, inputs): # Input needs to be a list, but don't split a word into letters From f9ac8cfaf483d37f541c960a7127fc2a6411e2ab Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 13:27:25 -0400 Subject: [PATCH 37/96] test --- sopel_modules/spicemanip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index e0427ba..1aa50c5 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -13,7 +13,7 @@ import collections class Spicemanip(): - def __init__(self): + def __init__(self, inputs, task=None, output_type=None): pass def __call__(self, inputs, task=None, output_type=None): From a672551e016a368986a748af40f543bf47e9d81c Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 13:29:08 -0400 Subject: [PATCH 38/96] test --- sopel_modules/spicemanip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 1aa50c5..c3293ff 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -45,7 +45,7 @@ class Spicemanip(): return self.inputs_list -core = Spicemanip() +# core = Spicemanip() # Hub From 2251d6d647699bb1fdf48aa24e11202774393d33 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 13:31:28 -0400 Subject: [PATCH 39/96] test --- sopel_modules/spicemanip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index c3293ff..0efaa76 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -14,7 +14,7 @@ import collections class Spicemanip(): def __init__(self, inputs, task=None, output_type=None): - pass + return self.core(inputs, task, output_type) def __call__(self, inputs, task=None, output_type=None): return self.core(inputs, task, output_type) From 7cb4546a4a12468fd834f408237db853eb8350ec Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 13:32:29 -0400 Subject: [PATCH 40/96] test --- sopel_modules/spicemanip/__init__.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 0efaa76..e139475 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -13,9 +13,6 @@ import collections class Spicemanip(): - def __init__(self, inputs, task=None, output_type=None): - return self.core(inputs, task, output_type) - def __call__(self, inputs, task=None, output_type=None): return self.core(inputs, task, output_type) From 7475fdde9bd2b9cf66af128ea61a5ac061602c7a Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 13:34:32 -0400 Subject: [PATCH 41/96] test --- sopel_modules/spicemanip/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index e139475..6e58dc5 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -13,6 +13,11 @@ import collections class Spicemanip(): + def __init__(self, inputs, task=None, output_type=None): + self.inputs = inputs + self.inputs_list = self.input_handler(self.inputs) + self.output_type = output_type + def __call__(self, inputs, task=None, output_type=None): return self.core(inputs, task, output_type) @@ -35,10 +40,7 @@ class Spicemanip(): output_type = "list" return outputs - def core(self, inputs, task, output_type=None): - self.inputs = inputs - self.inputs_list = self.input_handler(self.inputs) - self.output_type = output_type + def core(self): return self.inputs_list From 13293449cd1a9649a77a648fa51e5a3339a5e0eb Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 13:36:46 -0400 Subject: [PATCH 42/96] test --- sopel_modules/spicemanip/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 6e58dc5..c3293ff 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -14,9 +14,7 @@ import collections class Spicemanip(): def __init__(self, inputs, task=None, output_type=None): - self.inputs = inputs - self.inputs_list = self.input_handler(self.inputs) - self.output_type = output_type + pass def __call__(self, inputs, task=None, output_type=None): return self.core(inputs, task, output_type) @@ -40,7 +38,10 @@ class Spicemanip(): output_type = "list" return outputs - def core(self): + def core(self, inputs, task, output_type=None): + self.inputs = inputs + self.inputs_list = self.input_handler(self.inputs) + self.output_type = output_type return self.inputs_list From 05ac28473430d30d766e8caa85efa40731add9d9 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 13:37:35 -0400 Subject: [PATCH 43/96] test --- sopel_modules/spicemanip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index c3293ff..1aa50c5 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -45,7 +45,7 @@ class Spicemanip(): return self.inputs_list -# core = Spicemanip() +core = Spicemanip() # Hub From 7856b698d035783bca0b0b6e7ef321ca49a79b60 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 13:39:11 -0400 Subject: [PATCH 44/96] test --- sopel_modules/spicemanip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 1aa50c5..e0427ba 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -13,7 +13,7 @@ import collections class Spicemanip(): - def __init__(self, inputs, task=None, output_type=None): + def __init__(self): pass def __call__(self, inputs, task=None, output_type=None): From 9b5351e453423ef05e5ce578a3c655f7623ff951 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 13:43:12 -0400 Subject: [PATCH 45/96] test --- sopel_modules/spicemanip/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index e0427ba..f19ab61 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -17,6 +17,9 @@ class Spicemanip(): pass def __call__(self, inputs, task=None, output_type=None): + self.inputs = inputs + self.inputs_list = self.input_handler(self.inputs) + self.output_type = output_type return self.core(inputs, task, output_type) def input_handler(self, inputs): @@ -39,9 +42,6 @@ class Spicemanip(): return outputs def core(self, inputs, task, output_type=None): - self.inputs = inputs - self.inputs_list = self.input_handler(self.inputs) - self.output_type = output_type return self.inputs_list From 7fc98ef8692c2d3b986f838a525ae4ce9ede3821 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 13:44:37 -0400 Subject: [PATCH 46/96] test --- sopel_modules/spicemanip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index f19ab61..e12593c 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -42,7 +42,7 @@ class Spicemanip(): return outputs def core(self, inputs, task, output_type=None): - return self.inputs_list + return self.output_handler(inputs, output_type) core = Spicemanip() From 0b9481618c05454b807b83f67ac2d6b30345e9c9 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 13:56:33 -0400 Subject: [PATCH 47/96] test --- sopel_modules/spicemanip/__init__.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index e12593c..2418bc1 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -25,15 +25,13 @@ class Spicemanip(): def input_handler(self, inputs): # Input needs to be a list, but don't split a word into letters if not inputs: - inputs = [] + return [] if isinstance(inputs, collections.abc.KeysView): - inputs = list(inputs) - elif isinstance(inputs, dict): - inputs = list(inputs.keys()) + return list(inputs) + if isinstance(inputs, dict): + return list(inputs.keys()) if not isinstance(inputs, list): - inputs = list(inputs.split(" ")) - inputs = [x for x in inputs if x and x not in ['', ' ']] - inputs = [inputspart.strip() for inputspart in inputs] + return list(inputs.split(" ")) return inputs def output_handler(self, outputs, output_type=None): From 15395bf9361ea496013eb6450e8ec17ff822f0b9 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 13:59:50 -0400 Subject: [PATCH 48/96] test --- sopel_modules/spicemanip/__init__.py | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 2418bc1..535cf15 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -22,25 +22,25 @@ class Spicemanip(): self.output_type = output_type return self.core(inputs, task, output_type) - def input_handler(self, inputs): + def input_handler(self): # Input needs to be a list, but don't split a word into letters - if not inputs: + if not self.inputs: return [] - if isinstance(inputs, collections.abc.KeysView): - return list(inputs) - if isinstance(inputs, dict): - return list(inputs.keys()) - if not isinstance(inputs, list): - return list(inputs.split(" ")) - return inputs + if isinstance(self.inputs, collections.abc.KeysView): + return list(self.inputs) + if isinstance(self.inputs, dict): + return list(self.inputs.keys()) + if not isinstance(self.inputs, list): + return list(self.inputs.split(" ")) - def output_handler(self, outputs, output_type=None): - if not output_type: - output_type = "list" - return outputs + def output_handler(self): + if not self.output_type: + self.output_type = "list" + self.outputs = self.inputs_list + return self.outputs - def core(self, inputs, task, output_type=None): - return self.output_handler(inputs, output_type) + def core(self): + return self.output_handler() core = Spicemanip() From 6b8ef22f1b50771d5b674a99a2f578870a1762a9 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 14:00:36 -0400 Subject: [PATCH 49/96] test --- sopel_modules/spicemanip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 535cf15..df14993 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -20,7 +20,7 @@ class Spicemanip(): self.inputs = inputs self.inputs_list = self.input_handler(self.inputs) self.output_type = output_type - return self.core(inputs, task, output_type) + return self.core() def input_handler(self): # Input needs to be a list, but don't split a word into letters From d87fd058d754d1be592046be65540eb4c68b6c86 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 14:01:24 -0400 Subject: [PATCH 50/96] test --- sopel_modules/spicemanip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index df14993..3a30eba 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -18,7 +18,7 @@ class Spicemanip(): def __call__(self, inputs, task=None, output_type=None): self.inputs = inputs - self.inputs_list = self.input_handler(self.inputs) + self.inputs_list = self.input_handler() self.output_type = output_type return self.core() From 7e8abf204b1b47c280a28759dd649e5202e87f89 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 14:03:04 -0400 Subject: [PATCH 51/96] test --- sopel_modules/spicemanip/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 3a30eba..c5042b5 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -26,6 +26,8 @@ class Spicemanip(): # Input needs to be a list, but don't split a word into letters if not self.inputs: return [] + if isinstance(self.inputs, list): + return self.inputs if isinstance(self.inputs, collections.abc.KeysView): return list(self.inputs) if isinstance(self.inputs, dict): From aa712560b2ac62c17e0d2f4fc7bbd5103a11ceec Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 14:05:06 -0400 Subject: [PATCH 52/96] test --- sopel_modules/spicemanip/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index c5042b5..49a8e78 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -27,13 +27,14 @@ class Spicemanip(): if not self.inputs: return [] if isinstance(self.inputs, list): - return self.inputs + input_list = self.inputs if isinstance(self.inputs, collections.abc.KeysView): - return list(self.inputs) + input_list = list(self.inputs) if isinstance(self.inputs, dict): - return list(self.inputs.keys()) + input_list = list(self.inputs.keys()) if not isinstance(self.inputs, list): - return list(self.inputs.split(" ")) + input_list = list(self.inputs.split(" ")) + self.inputs_list = input_list def output_handler(self): if not self.output_type: From bac0feb84a72b2a66346b45a015aac6448a37238 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 14:07:03 -0400 Subject: [PATCH 53/96] test --- sopel_modules/spicemanip/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 49a8e78..639db8b 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -25,7 +25,7 @@ class Spicemanip(): def input_handler(self): # Input needs to be a list, but don't split a word into letters if not self.inputs: - return [] + input_list = [] if isinstance(self.inputs, list): input_list = self.inputs if isinstance(self.inputs, collections.abc.KeysView): @@ -34,6 +34,8 @@ class Spicemanip(): input_list = list(self.inputs.keys()) if not isinstance(self.inputs, list): input_list = list(self.inputs.split(" ")) + input_list = [x for x in input_list if x and x not in ['', ' ']] + input_list = [inputspart.strip() for inputspart in input_list] self.inputs_list = input_list def output_handler(self): From 0b4d80b0818377bec63cdb7a32533319d30b6f8e Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 5 Jul 2019 14:11:36 -0400 Subject: [PATCH 54/96] test --- sopel_modules/spicemanip/__init__.py | 37 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 639db8b..4d81097 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -18,34 +18,35 @@ class Spicemanip(): def __call__(self, inputs, task=None, output_type=None): self.inputs = inputs - self.inputs_list = self.input_handler() + self.inputs_list = self.input_handler(self.inputs) self.output_type = output_type return self.core() - def input_handler(self): + def input_handler(self, inputs): # Input needs to be a list, but don't split a word into letters - if not self.inputs: + if not inputs: input_list = [] - if isinstance(self.inputs, list): - input_list = self.inputs - if isinstance(self.inputs, collections.abc.KeysView): - input_list = list(self.inputs) - if isinstance(self.inputs, dict): - input_list = list(self.inputs.keys()) - if not isinstance(self.inputs, list): - input_list = list(self.inputs.split(" ")) + if isinstance(inputs, list): + input_list = inputs + if isinstance(inputs, collections.abc.KeysView): + input_list = list(inputs) + if isinstance(inputs, dict): + input_list = list(inputs.keys()) + if not isinstance(inputs, list): + input_list = list(inputs.split(" ")) input_list = [x for x in input_list if x and x not in ['', ' ']] input_list = [inputspart.strip() for inputspart in input_list] - self.inputs_list = input_list + return input_list - def output_handler(self): - if not self.output_type: - self.output_type = "list" - self.outputs = self.inputs_list - return self.outputs + def output_handler(self, inputs_list, output_type): + if not output_type: + output_type = "list" + outputs = inputs_list + return outputs def core(self): - return self.output_handler() + outputs = self.output_handler(self.inputs_list, self.output_type) + return outputs core = Spicemanip() From e82b75c616cdc30e153dfa2b9efcda85f4aeaffd Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 07:35:53 -0400 Subject: [PATCH 55/96] possibly new spicemanip --- sopel_modules/spicemanip/__init__.py | 343 +++++++++++++++++++++++---- 1 file changed, 299 insertions(+), 44 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 4d81097..486dbb2 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -16,37 +16,292 @@ class Spicemanip(): def __init__(self): pass - def __call__(self, inputs, task=None, output_type=None): + def __call__(self, inputs, task, output_type='default'): + + if hasattr(self, task): + raise Exception(str(self.task) + " is not a valid spicemanip function.") + + # convert input into list self.inputs = inputs - self.inputs_list = self.input_handler(self.inputs) + self.core_input_handler() + + # determine task + self.task = task + self.core_task_handler() + + # determine output of list self.output_type = output_type - return self.core() + self.core_output_handler() - def input_handler(self, inputs): + # cleanup + self.core_class_cleanup() + + # return value/s + return self.outputs + + def core_class_cleanup(self): + for classitem in ["inputs", "task", "output_type"]: + if hasattr(self, classitem): + del classitem + + def core_input_handler(self): # Input needs to be a list, but don't split a word into letters - if not inputs: - input_list = [] - if isinstance(inputs, list): - input_list = inputs - if isinstance(inputs, collections.abc.KeysView): - input_list = list(inputs) - if isinstance(inputs, dict): - input_list = list(inputs.keys()) + if not self.inputs: + self.input_list = [] + if isinstance(self.inputs, list): + self.input_list = list(self.inputs) + if isinstance(self.inputs, collections.abc.KeysView): + self.input_list = list(self.inputs) + if isinstance(self.inputs, dict): + self.input_list = list(self.inputs.keys()) + if not isinstance(self.inputs, list): + self.input_list = list(self.inputs.split(" ")) + + def core_task_handler(self): + + # Create return + if self.task in ['create']: + self.outputs = self.input_list + return + + """ + returnvalue = eval('spicemanip_' + outputtask + '(inputs, outputtask, mainoutputtask, suboutputtask)') + """ + + if len(self.input_list): + + if self.task in [0, 'complete']: + self.outputs = self.string(self.input_list) + return + + elif self.task in ['index']: + self.outputs = self.index(self.input_list[0], self.input_list[1], self.input_list[2]) + + elif self.is_digit(self.task): + self.outputs = self.number(self.input_list, int(self.task)) + + elif self.task in ['last']: + self.outputs = self.number(self.input_list, -1) + + elif "^" in str(self.task): + range_start, range_end = str(self.task).split("^", 1).sort() + self.outputs = self.rangebetween(self.input_list, range_start, range_end) + + elif str(self.task).startswith("split_"): + self.outputs = self.split(self.input_list, str(self.task).replace("split_", "")) + + elif str(self.task).endswith("!"): + self.outputs = self.exclude(self.input_list, str(self.task).replace("!", "")) + + elif str(self.task).endswith("+"): + self.outputs = self.incrange_plus(self.input_list, str(self.task).replace("+", "")) + + elif str(self.task).endswith("-"): + self.outputs = self.incrange_minus(self.input_list, str(self.task).replace("-", "")) + + elif str(self.task).endswith(">"): + self.outputs = self.excrange_plus(self.input_list, str(self.task).replace(">", "")) + + elif str(self.task).endswith("<"): + self.outputs = self.excrange_minus(self.input_list, str(self.task).replace("<", "")) + + elif hasattr(self, self.task) and not str(self.task).startswith("core_"): + self.outputs = eval('self.' + str(self.task) + '(inputs)') + + else: + raise Exception(str(self.task) + " is not a valid spicemanip function.") + + def core_output_handler(self): + if not self.output_type: + self.output_type = "list" + self.outputs = self.inputs_list + + # default return if not specified + if self.output_type == 'default': + if self.task in [ + 'string', 'number', 'rangebetween', 'exclude', 'random', + 'incrange_plus', 'incrange_minus', 'excrange_plus', 'excrange_minus' + ]: + self.output_type = 'string' + elif self.task in ['count']: + self.output_type = 'dict' + + # verify output is correct + if self.output_type == 'return': + return self.outputs + if self.output_type == 'string': + self.outputs = self.string(self.outputs) + elif self.output_type in ['list', 'array']: + self.outputs = self.list(self.outputs) + + # Convert list to string + def string(self, inputs): if not isinstance(inputs, list): - input_list = list(inputs.split(" ")) - input_list = [x for x in input_list if x and x not in ['', ' ']] - input_list = [inputspart.strip() for inputspart in input_list] - return input_list + return inputs + if not inputs or not len(inputs): + return '' + return ' '.join(inputs) - def output_handler(self, inputs_list, output_type): - if not output_type: - output_type = "list" - outputs = inputs_list - return outputs + # Convert inputs to list + def list(self, inputs): + if isinstance(inputs, list): + return inputs + if not inputs or not len(inputs): + return [] + return list(inputs.split(" ")) - def core(self): - outputs = self.output_handler(self.inputs_list, self.output_type) - return outputs + def index(self, indexitem, listtoindex, listtocompare): + for x, y in zip(listtoindex, listtocompare): + if x == indexitem: + return y + return '' + + # Get number item from list + def number(self, inputs, index_number): + if int(index_number) > 0: + index_number -= 1 + try: + return inputs[int(index_number)] + except IndexError: + return '' + + # range between items in list + def rangebetween(self, inputs, range_start, range_end): + range_start, range_end = int(range_start), int(range_end) + if range_end == range_start: + return self.number(inputs, range_start) + if range_start < 0: + range_start = 1 + if range_end > len(inputs): + range_end = len(inputs) + newlist = [] + for i in range(range_start, range_end + 1): + newlist.append(str(self.number(inputs, i))) + return ' '.join(newlist) + + # split list by string + def split(self, inputs, splitby): + split_list = [] + restring = ' '.join(inputs) + if splitby not in inputs: + split_list = [restring] + else: + split_list = restring.split(splitby) + return ' '.join(split_list) + + # exclude number + def exclude(self, inputs, excludenum): + try: + del inputs[int(excludenum) - 1] + return ' '.join(inputs) + except IndexError: + return ' '.join(inputs) + + # Forward Range includes index number + def incrange_plus(self, inputs, range_start): + return self.rangebetween(inputs, int(range_start), len(inputs)) + + # Reverse Range includes index number + def incrange_minus(self, inputs, range_end): + return self.rangebetween(inputs, 1, int(range_end)) + + # Forward Range excludes index number + def excrange_plus(self, inputs, range_start): + return self.rangebetween(inputs, int(range_start) + 1, len(inputs)) + + # Reverse Range excludes index number + def excrange_minus(self, inputs, range_end): + return self.rangebetween(inputs, 1, int(range_end) - 1) + + # dedupe list + def dedupe(self, inputs): + newlist = [] + for inputspart in inputs: + if inputspart not in newlist: + newlist.append(inputspart) + return newlist + + # Sort list + def sort(self, inputs): + return sorted(inputs) + + # reverse sort list + def rsort(self, inputs): + return sorted(inputs)[::-1] + + # count items in list, return dictionary + def count(self, inputs): + returndict = dict() + uniqueinputitems, uniquecount = [], [] + for inputspart in inputs: + if inputspart not in uniqueinputitems: + uniqueinputitems.append(inputspart) + for uniqueinputspart in uniqueinputitems: + count = 0 + for ele in inputs: + if (ele == uniqueinputspart): + count += 1 + uniquecount.append(count) + for inputsitem, unumber in zip(uniqueinputitems, uniquecount): + returndict[inputsitem] = unumber + return returndict + + # random item from list + def random(self, inputs): + randomselectlist = list(inputs) + while len(randomselectlist) > 1: + random.shuffle(randomselectlist) + randomselect = randomselectlist[random.randint(0, len(randomselectlist) - 1)] + randomselectlist.remove(randomselect) + randomselect = randomselectlist[0] + return randomselect + + # remove random item from list + def exrandom(self, inputs): + randremove = self.random(inputs) + inputs.remove(randremove) + return inputs + + # Convert list into lowercase + def lower(self, inputs): + return [inputspart.lower() for inputspart in inputs] + + # Convert list to uppercase + def upper(self, inputs): + return [inputspart.upper() for inputspart in inputs] + + # Convert list to uppercase + def title(self, inputs): + return [inputspart.title() for inputspart in inputs] + + # Reverse List Order + def reverse(self, inputs): + return inputs[::-1] + + def list_nospace(self, inputs): + return ','.join(str(x) for x in inputs) + + # comma seperated list with and + def andlist(self, inputs): + if len(inputs) < 2: + return ' '.join(inputs) + lastentry = str("and " + str(inputs[len(inputs) - 1])) + del inputs[-1] + inputs.append(lastentry) + if len(inputs) == 2: + return ' '.join(inputs) + return ', '.join(str(x) for x in inputs) + + # comma seperated list with or + def orlist(self, inputs): + if len(inputs) < 2: + return ' '.join(inputs) + lastentry = str("or " + str(inputs[len(inputs) - 1])) + del inputs[-1] + inputs.append(lastentry) + if len(inputs) == 2: + return ' '.join(inputs) + return ', '.join(str(x) for x in inputs) core = Spicemanip() @@ -193,7 +448,7 @@ def spicemanip_rsort(inputs, outputtask, mainoutputtask, suboutputtask): # count items in list, return dictionary def spicemanip_count(inputs, outputtask, mainoutputtask, suboutputtask): returndict = dict() - if inputs == []: + if not len(inputs): return returndict uniqueinputitems, uniquecount = [], [] for inputspart in inputs: @@ -212,7 +467,7 @@ def spicemanip_count(inputs, outputtask, mainoutputtask, suboutputtask): # random item from list def spicemanip_random(inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: + if not len(inputs): return '' randomselectlist = [] for temppart in inputs: @@ -227,7 +482,7 @@ def spicemanip_random(inputs, outputtask, mainoutputtask, suboutputtask): # remove random item from list def spicemanip_exrandom(inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: + if not len(inputs): return [] randremove = spicemanip_random(inputs, outputtask, mainoutputtask, suboutputtask) inputs.remove(randremove) @@ -236,48 +491,48 @@ def spicemanip_exrandom(inputs, outputtask, mainoutputtask, suboutputtask): # Convert list into lowercase def spicemanip_lower(inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: + if not len(inputs): return '' return [inputspart.lower() for inputspart in inputs] # Convert list to uppercase def spicemanip_upper(inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: + if not len(inputs): return '' return [inputspart.upper() for inputspart in inputs] # Convert list to uppercase def spicemanip_title(inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: + if not len(inputs): return '' return [inputspart.title() for inputspart in inputs] # Reverse List Order def spicemanip_reverse(inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: + if not len(inputs): return [] return inputs[::-1] # comma seperated list def spicemanip_list(inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: + if not len(inputs): return '' return ', '.join(str(x) for x in inputs) def spicemanip_list_nospace(inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: + if not len(inputs): return '' return ','.join(str(x) for x in inputs) # comma seperated list with and def spicemanip_andlist(inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: + if not len(inputs): return '' if len(inputs) < 2: return ' '.join(inputs) @@ -291,7 +546,7 @@ def spicemanip_andlist(inputs, outputtask, mainoutputtask, suboutputtask): # comma seperated list with or def spicemanip_orlist(inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: + if not len(inputs): return '' if len(inputs) < 2: return ' '.join(inputs) @@ -305,7 +560,7 @@ def spicemanip_orlist(inputs, outputtask, mainoutputtask, suboutputtask): # exclude number def spicemanip_exclude(inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: + if not len(inputs): return '' del inputs[int(mainoutputtask) - 1] return ' '.join(inputs) @@ -313,14 +568,14 @@ def spicemanip_exclude(inputs, outputtask, mainoutputtask, suboutputtask): # Convert list to string def spicemanip_string(inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: + if not len(inputs): return '' return ' '.join(inputs) # Get number item from list def spicemanip_number(inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: + if not len(inputs): return '' elif len(inputs) == 1: return inputs[0] @@ -332,14 +587,14 @@ def spicemanip_number(inputs, outputtask, mainoutputtask, suboutputtask): # Get Last item from list def spicemanip_last(inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: + if not len(inputs): return '' return inputs[len(inputs) - 1] # range between items in list def spicemanip_rangebetween(inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: + if not len(inputs): return '' if not str(mainoutputtask).isdigit() or not str(suboutputtask).isdigit(): return '' @@ -362,27 +617,27 @@ def spicemanip_rangebetween(inputs, outputtask, mainoutputtask, suboutputtask): # Forward Range includes index number def spicemanip_incrange_plus(inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: + if not len(inputs): return '' return spicemanip_rangebetween(inputs, outputtask, int(mainoutputtask), len(inputs)) # Reverse Range includes index number def spicemanip_incrange_minus(inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: + if not len(inputs): return '' return spicemanip_rangebetween(inputs, outputtask, 1, int(mainoutputtask)) # Forward Range excludes index number def spicemanip_excrange_plus(inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: + if not len(inputs): return '' return spicemanip_rangebetween(inputs, outputtask, int(mainoutputtask) + 1, len(inputs)) # Reverse Range excludes index number def spicemanip_excrange_minus(inputs, outputtask, mainoutputtask, suboutputtask): - if inputs == []: + if not len(inputs): return '' return spicemanip_rangebetween(inputs, outputtask, 1, int(mainoutputtask) - 1) From 98c1203307940d29379cfa66016d8e040d210066 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 07:40:02 -0400 Subject: [PATCH 56/96] first attempt --- sopel_modules/spicemanip/__init__.py | 112 +++++++++++++++++---------- 1 file changed, 70 insertions(+), 42 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 486dbb2..01c78bd 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -1,6 +1,5 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- - """Top-level package for spicemanip.""" __author__ = """Sam Zick""" @@ -11,15 +10,20 @@ import random import collections -class Spicemanip(): +# TODO 'this*that' or '1*that' replace either all strings matching, or an index value +# TODO reverse sort z.sort(reverse = True) +# list.extend adds lists to eachother + +class Spicemanip(): def __init__(self): pass def __call__(self, inputs, task, output_type='default'): if hasattr(self, task): - raise Exception(str(self.task) + " is not a valid spicemanip function.") + raise Exception( + str(self.task) + " is not a valid spicemanip function.") # convert input into list self.inputs = inputs @@ -64,10 +68,6 @@ class Spicemanip(): self.outputs = self.input_list return - """ - returnvalue = eval('spicemanip_' + outputtask + '(inputs, outputtask, mainoutputtask, suboutputtask)') - """ - if len(self.input_list): if self.task in [0, 'complete']: @@ -75,7 +75,8 @@ class Spicemanip(): return elif self.task in ['index']: - self.outputs = self.index(self.input_list[0], self.input_list[1], self.input_list[2]) + self.outputs = self.index( + self.input_list[0], self.input_list[1], self.input_list[2]) elif self.is_digit(self.task): self.outputs = self.number(self.input_list, int(self.task)) @@ -85,31 +86,44 @@ class Spicemanip(): elif "^" in str(self.task): range_start, range_end = str(self.task).split("^", 1).sort() - self.outputs = self.rangebetween(self.input_list, range_start, range_end) + self.outputs = self.rangebetween(self.input_list, range_start, + range_end) elif str(self.task).startswith("split_"): - self.outputs = self.split(self.input_list, str(self.task).replace("split_", "")) + self.outputs = self.split(self.input_list, + str(self.task).replace("split_", "")) elif str(self.task).endswith("!"): - self.outputs = self.exclude(self.input_list, str(self.task).replace("!", "")) + self.outputs = self.exclude(self.input_list, + str(self.task).replace("!", "")) elif str(self.task).endswith("+"): - self.outputs = self.incrange_plus(self.input_list, str(self.task).replace("+", "")) + self.outputs = self.incrange_plus( + self.input_list, + str(self.task).replace("+", "")) elif str(self.task).endswith("-"): - self.outputs = self.incrange_minus(self.input_list, str(self.task).replace("-", "")) + self.outputs = self.incrange_minus( + self.input_list, + str(self.task).replace("-", "")) elif str(self.task).endswith(">"): - self.outputs = self.excrange_plus(self.input_list, str(self.task).replace(">", "")) + self.outputs = self.excrange_plus( + self.input_list, + str(self.task).replace(">", "")) elif str(self.task).endswith("<"): - self.outputs = self.excrange_minus(self.input_list, str(self.task).replace("<", "")) + self.outputs = self.excrange_minus( + self.input_list, + str(self.task).replace("<", "")) - elif hasattr(self, self.task) and not str(self.task).startswith("core_"): + elif hasattr(self, + self.task) and not str(self.task).startswith("core_"): self.outputs = eval('self.' + str(self.task) + '(inputs)') else: - raise Exception(str(self.task) + " is not a valid spicemanip function.") + raise Exception( + str(self.task) + " is not a valid spicemanip function.") def core_output_handler(self): if not self.output_type: @@ -119,9 +133,10 @@ class Spicemanip(): # default return if not specified if self.output_type == 'default': if self.task in [ - 'string', 'number', 'rangebetween', 'exclude', 'random', - 'incrange_plus', 'incrange_minus', 'excrange_plus', 'excrange_minus' - ]: + 'string', 'number', 'rangebetween', 'exclude', 'random', + 'incrange_plus', 'incrange_minus', 'excrange_plus', + 'excrange_minus' + ]: self.output_type = 'string' elif self.task in ['count']: self.output_type = 'dict' @@ -251,7 +266,9 @@ class Spicemanip(): randomselectlist = list(inputs) while len(randomselectlist) > 1: random.shuffle(randomselectlist) - randomselect = randomselectlist[random.randint(0, len(randomselectlist) - 1)] + randomselect = randomselectlist[random.randint( + 0, + len(randomselectlist) - 1)] randomselectlist.remove(randomselect) randomselect = randomselectlist[0] return randomselect @@ -304,15 +321,11 @@ class Spicemanip(): return ', '.join(str(x) for x in inputs) -core = Spicemanip() +main = Spicemanip() # Hub -def main(inputs, outputtask, output_type='default'): - - # TODO 'this*that' or '1*that' replace either all strings matching, or an index value - # TODO reverse sort z.sort(reverse = True) - # list.extend adds lists to eachother +def core(inputs, outputtask, output_type='default'): mainoutputtask, suboutputtask = None, None @@ -376,14 +389,17 @@ def main(inputs, outputtask, output_type='default'): if outputtask == 'string': returnvalue = inputs else: - returnvalue = eval('spicemanip_' + outputtask + '(inputs, outputtask, mainoutputtask, suboutputtask)') + returnvalue = eval( + 'spicemanip_' + outputtask + + '(inputs, outputtask, mainoutputtask, suboutputtask)') # default return if not specified if output_type == 'default': if outputtask in [ - 'string', 'number', 'rangebetween', 'exclude', 'random', - 'incrange_plus', 'incrange_minus', 'excrange_plus', 'excrange_minus' - ]: + 'string', 'number', 'rangebetween', 'exclude', 'random', + 'incrange_plus', 'incrange_minus', 'excrange_plus', + 'excrange_minus' + ]: output_type = 'string' elif outputtask in ['count']: output_type = 'dict' @@ -474,7 +490,9 @@ def spicemanip_random(inputs, outputtask, mainoutputtask, suboutputtask): randomselectlist.append(temppart) while len(randomselectlist) > 1: random.shuffle(randomselectlist) - randomselect = randomselectlist[random.randint(0, len(randomselectlist) - 1)] + randomselect = randomselectlist[random.randint( + 0, + len(randomselectlist) - 1)] randomselectlist.remove(randomselect) randomselect = randomselectlist[0] return randomselect @@ -484,7 +502,8 @@ def spicemanip_random(inputs, outputtask, mainoutputtask, suboutputtask): def spicemanip_exrandom(inputs, outputtask, mainoutputtask, suboutputtask): if not len(inputs): return [] - randremove = spicemanip_random(inputs, outputtask, mainoutputtask, suboutputtask) + randremove = spicemanip_random(inputs, outputtask, mainoutputtask, + suboutputtask) inputs.remove(randremove) return inputs @@ -600,7 +619,8 @@ def spicemanip_rangebetween(inputs, outputtask, mainoutputtask, suboutputtask): return '' mainoutputtask, suboutputtask = int(mainoutputtask), int(suboutputtask) if suboutputtask == mainoutputtask: - return spicemanip_number(inputs, outputtask, mainoutputtask, suboutputtask) + return spicemanip_number(inputs, outputtask, mainoutputtask, + suboutputtask) if suboutputtask < mainoutputtask: return [] if mainoutputtask < 0: @@ -609,35 +629,43 @@ def spicemanip_rangebetween(inputs, outputtask, mainoutputtask, suboutputtask): suboutputtask = len(inputs) newlist = [] for i in range(mainoutputtask, suboutputtask + 1): - newlist.append(str(spicemanip_number(inputs, outputtask, i, suboutputtask))) + newlist.append( + str(spicemanip_number(inputs, outputtask, i, suboutputtask))) if newlist == []: return '' return ' '.join(newlist) # Forward Range includes index number -def spicemanip_incrange_plus(inputs, outputtask, mainoutputtask, suboutputtask): +def spicemanip_incrange_plus(inputs, outputtask, mainoutputtask, + suboutputtask): if not len(inputs): return '' - return spicemanip_rangebetween(inputs, outputtask, int(mainoutputtask), len(inputs)) + return spicemanip_rangebetween(inputs, outputtask, int(mainoutputtask), + len(inputs)) # Reverse Range includes index number -def spicemanip_incrange_minus(inputs, outputtask, mainoutputtask, suboutputtask): +def spicemanip_incrange_minus(inputs, outputtask, mainoutputtask, + suboutputtask): if not len(inputs): return '' return spicemanip_rangebetween(inputs, outputtask, 1, int(mainoutputtask)) # Forward Range excludes index number -def spicemanip_excrange_plus(inputs, outputtask, mainoutputtask, suboutputtask): +def spicemanip_excrange_plus(inputs, outputtask, mainoutputtask, + suboutputtask): if not len(inputs): return '' - return spicemanip_rangebetween(inputs, outputtask, int(mainoutputtask) + 1, len(inputs)) + return spicemanip_rangebetween(inputs, outputtask, + int(mainoutputtask) + 1, len(inputs)) # Reverse Range excludes index number -def spicemanip_excrange_minus(inputs, outputtask, mainoutputtask, suboutputtask): +def spicemanip_excrange_minus(inputs, outputtask, mainoutputtask, + suboutputtask): if not len(inputs): return '' - return spicemanip_rangebetween(inputs, outputtask, 1, int(mainoutputtask) - 1) + return spicemanip_rangebetween(inputs, outputtask, 1, + int(mainoutputtask) - 1) From bbab091cb038d2cf966649d541b4ad472ce40c6a Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 07:46:47 -0400 Subject: [PATCH 57/96] repair --- sopel_modules/spicemanip/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 01c78bd..3fefa48 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -320,6 +320,13 @@ class Spicemanip(): return ' '.join(inputs) return ', '.join(str(x) for x in inputs) + def is_digit(n): + try: + int(n) + return True + except ValueError: + return False + main = Spicemanip() From 8bd37324abc743f00efd37b5d75ee25a805ff179 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 07:47:48 -0400 Subject: [PATCH 58/96] self --- sopel_modules/spicemanip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 3fefa48..b507df7 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -320,7 +320,7 @@ class Spicemanip(): return ' '.join(inputs) return ', '.join(str(x) for x in inputs) - def is_digit(n): + def is_digit(self, n): try: int(n) return True From ca4f35aae50aece71b43bb62f1452704f405b221 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 07:53:43 -0400 Subject: [PATCH 59/96] test --- sopel_modules/spicemanip/__init__.py | 36 +++++++++++++++++----------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index b507df7..edac8ee 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -126,28 +126,36 @@ class Spicemanip(): str(self.task) + " is not a valid spicemanip function.") def core_output_handler(self): - if not self.output_type: - self.output_type = "list" - self.outputs = self.inputs_list + + core_defaults = { + 'string': "string", + 'number': "string", + 'rangebetween': "string", + 'exclude': "string", + 'random': "string", + 'incrange_plus': "string", + 'incrange_minus': "string", + 'excrange_plus': "string", + 'excrange_minus': "string", + 'count': "dict" + } # default return if not specified if self.output_type == 'default': - if self.task in [ - 'string', 'number', 'rangebetween', 'exclude', 'random', - 'incrange_plus', 'incrange_minus', 'excrange_plus', - 'excrange_minus' - ]: - self.output_type = 'string' - elif self.task in ['count']: - self.output_type = 'dict' + if self.task in list(core_defaults.keys()): + self.output_type = core_defaults[self.task] # verify output is correct - if self.output_type == 'return': - return self.outputs + if self.output_type in ['return', 'dict']: + return + if self.output_type == 'string': self.outputs = self.string(self.outputs) - elif self.output_type in ['list', 'array']: + return + + if self.output_type in ['list', 'array']: self.outputs = self.list(self.outputs) + return # Convert list to string def string(self, inputs): From b1501d94daf582a359883f1785ce5977d9a36507 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 07:56:43 -0400 Subject: [PATCH 60/96] test new spicemanip --- sopel_modules/SpiceBot/AI.py | 10 +- sopel_modules/SpiceBot/Commands.py | 4 +- sopel_modules/SpiceBot/Gif.py | 8 +- sopel_modules/SpiceBot/Logs.py | 6 +- sopel_modules/SpiceBot/Prerun.py | 48 +-- sopel_modules/SpiceBot/Reddit.py | 18 +- sopel_modules/SpiceBot/Tools.py | 4 +- sopel_modules/SpiceBot/Translate.py | 22 +- sopel_modules/SpiceBot/Users.py | 8 +- sopel_modules/SpiceBot_Core_Commands/AI.py | 28 +- .../SpiceBot_Core_Commands/BotPrivs.py | 4 +- .../SpiceBot_Core_Commands/Channels.py | 20 +- .../SpiceBot_Core_Commands/Commands.py | 6 +- .../SpiceBot_Core_Commands/CommandsQuery.py | 18 +- .../SpiceBot_Core_Commands/DictComs.py | 54 +-- sopel_modules/SpiceBot_Core_Commands/Gif.py | 6 +- sopel_modules/SpiceBot_Core_Commands/Logs.py | 8 +- .../SpiceBot_Core_Commands/Messaging.py | 8 +- .../Runtime_Controls.py | 6 +- .../SpiceBot_Core_Commands/Search.py | 10 +- .../SpiceBot_Core_Commands/Sherlock.py | 14 +- .../SpiceBot_Core_Processing/Channels.py | 4 +- sopel_modules/spicemanip/__init__.py | 349 +----------------- 23 files changed, 158 insertions(+), 505 deletions(-) diff --git a/sopel_modules/SpiceBot/AI.py b/sopel_modules/SpiceBot/AI.py index 6707f40..dd6da2d 100644 --- a/sopel_modules/SpiceBot/AI.py +++ b/sopel_modules/SpiceBot/AI.py @@ -15,7 +15,7 @@ from .Database import db as botdb from .Config import config as botconfig from .Read import read as botread -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip class SpiceBot_AI_MainSection(StaticSection): @@ -138,18 +138,18 @@ class SpiceBot_AI(): # bot items for botitem in ["nick"]: - messagelist = spicemanip.main(message, "create") + messagelist = spicemanip(message, "create") for i in range(len(messagelist)): if messagelist[i].upper() == str(eval("bot." + botitem)).upper(): messagelist[i] = str("bot" + botitem).upper() - message = spicemanip.main(messagelist, 0) + message = spicemanip(messagelist, 0) for triggeritem in ["nick", "sender"]: - messagelist = spicemanip.main(message, "create") + messagelist = spicemanip(message, "create") for i in range(len(messagelist)): if messagelist[i].upper() == str(eval("trigger." + botitem)).upper(): messagelist[i] = str("trigger" + botitem).upper() - message = spicemanip.main(messagelist, 0) + message = spicemanip(messagelist, 0) return message diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index 0a5b1c2..4efdca0 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -13,7 +13,7 @@ import os import threading import copy -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip import sopel_modules from .Logs import logs @@ -196,7 +196,7 @@ class BotCommands(): maincom = command_dict["validcoms"][0] if len(command_dict["validcoms"]) > 1: - comaliases = spicemanip.main(command_dict["validcoms"], '2+', 'list') + comaliases = spicemanip(command_dict["validcoms"], '2+', 'list') else: comaliases = [] diff --git a/sopel_modules/SpiceBot/Gif.py b/sopel_modules/SpiceBot/Gif.py index 91ed569..d6f6d8b 100644 --- a/sopel_modules/SpiceBot/Gif.py +++ b/sopel_modules/SpiceBot/Gif.py @@ -8,7 +8,7 @@ from .Config import config as botconfig from .Read import read as botread from .Commands import commands as botcommands -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip from fake_useragent import UserAgent import urllib @@ -134,13 +134,13 @@ class BotGif(): gifapiresults.extend(self.valid_api[currentapi]["cache"][searchdict["searchquery"].lower()]) if not len(gifapiresults): - return {"error": "No Results were found for '" + searchdict["query"] + "' in the " + str(spicemanip.main(searchdict['gifsearch'], 'orlist')) + " api(s)"} + return {"error": "No Results were found for '" + searchdict["query"] + "' in the " + str(spicemanip(searchdict['gifsearch'], 'orlist')) + " api(s)"} random.shuffle(gifapiresults) random.shuffle(gifapiresults) randombad = True while randombad: - gifdict = spicemanip.main(gifapiresults, "random") + gifdict = spicemanip(gifapiresults, "random") try: gifpage = requests.get(gifdict["returnurl"], headers=None) @@ -159,7 +159,7 @@ class BotGif(): gifapiresults = newlist if not len(gifapiresults): - return {"error": "No Results were found for '" + searchdict["query"] + "' in the " + str(spicemanip.main(searchdict['gifsearch'], 'orlist')) + " api(s)"} + return {"error": "No Results were found for '" + searchdict["query"] + "' in the " + str(spicemanip(searchdict['gifsearch'], 'orlist')) + " api(s)"} # return dict gifdict['error'] = None diff --git a/sopel_modules/SpiceBot/Logs.py b/sopel_modules/SpiceBot/Logs.py index 146f28c..1a8edad 100644 --- a/sopel_modules/SpiceBot/Logs.py +++ b/sopel_modules/SpiceBot/Logs.py @@ -9,7 +9,7 @@ This Class stores logs in an easy to access manner import threading import os import sys -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip from .Config import config as botconfig @@ -98,7 +98,7 @@ class BotLogs(): else: if not line.startswith(tuple(stdio_ignore)) and not line.isspace(): debuglines.append(str(line)) - loadedmodules = "Loaded: " + spicemanip.main(loadedmodules, 'andlist') + loadedmodules = "Loaded: " + spicemanip(loadedmodules, 'andlist') debuglines.insert(1, loadedmodules) return debuglines @@ -110,7 +110,7 @@ class BotLogs(): line = str(line).split(str(os.uname()[1] + " "))[-1] lineparts = str(line).split(": ") del lineparts[0] - line = spicemanip.main(lineparts, 0) + line = spicemanip(lineparts, 0) if not line.isspace(): debuglines.append(str(line)) return debuglines diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 33bbd4d..cc952e2 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -11,7 +11,7 @@ import copy import datetime from word2number import w2n -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip from .Tools import command_permissions_check, class_create from .Commands import commands as botcommands @@ -41,7 +41,7 @@ def prerun(t_command_type='module', t_command_subtype=None): botcom = class_create('botcom') if t_command_type == "nickname": - check_nick = spicemanip.main(trigger.args[1], 1).lower() + check_nick = spicemanip(trigger.args[1], 1).lower() if check_nick != str(bot.nick).lower(): return else: @@ -129,7 +129,7 @@ def prerun_query(t_command_type='module', t_command_subtype=None): botcom = class_create('botcom') if t_command_type == "nickname": - check_nick = spicemanip.main(trigger.args[1], 1).lower() + check_nick = spicemanip(trigger.args[1], 1).lower() if check_nick != str(bot.nick).lower(): return else: @@ -207,22 +207,22 @@ def verify_channel(trigger): def make_trigger_args(triggerargs_one, trigger_command_type='module'): - trigger_args = spicemanip.main(triggerargs_one, 'create') + trigger_args = spicemanip(triggerargs_one, 'create') if trigger_command_type in ['nickname']: - trigger_prefix = spicemanip.main(trigger_args, 2).lower()[0] + trigger_prefix = spicemanip(trigger_args, 2).lower()[0] if trigger_prefix.isupper() or trigger_prefix.islower(): trigger_prefix = None - trigger_command = spicemanip.main(trigger_args, 2).lower() - trigger_args = spicemanip.main(trigger_args, '3+', 'list') + trigger_command = spicemanip(trigger_args, 2).lower() + trigger_args = spicemanip(trigger_args, '3+', 'list') else: - trigger_prefix = spicemanip.main(trigger_args, 1).lower()[0] - trigger_command = spicemanip.main(trigger_args, 1).lower()[1:] - trigger_args = spicemanip.main(trigger_args, '2+', 'list') + trigger_prefix = spicemanip(trigger_args, 1).lower()[0] + trigger_command = spicemanip(trigger_args, 1).lower()[1:] + trigger_args = spicemanip(trigger_args, '2+', 'list') return trigger_args, trigger_command, trigger_prefix def trigger_and_split(trigger_args): - trigger_args_list_split = spicemanip.main(trigger_args, "split_&&") + trigger_args_list_split = spicemanip(trigger_args, "split_&&") if not len(trigger_args_list_split): trigger_args_list_split.append([]) return trigger_args_list_split @@ -232,11 +232,11 @@ def trigger_argsdict_list(argsdict_default, and_split): prerun_split = [] for trigger_args_part in and_split: argsdict_part = copy.deepcopy(argsdict_default) - argsdict_part["args"] = spicemanip.main(trigger_args_part, 'create') + argsdict_part["args"] = spicemanip(trigger_args_part, 'create') if len(argsdict_part["args"]) and (argsdict_part["args"][0] == "-a" or argsdict_part["args"][-1] == "-a"): argsdict_part["adminswitch"] = True if argsdict_part["args"][0] == "-a": - argsdict_part["args"] = spicemanip.main(argsdict_part["args"], '2+', 'list') + argsdict_part["args"] = spicemanip(argsdict_part["args"], '2+', 'list') elif argsdict_part["args"][-1] == "-a": del argsdict_part["args"][-1] else: @@ -247,11 +247,11 @@ def trigger_argsdict_list(argsdict_default, and_split): def trigger_argsdict_single(argsdict_default, trigger_args_part): argsdict_part = copy.deepcopy(argsdict_default) - argsdict_part["args"] = spicemanip.main(trigger_args_part, 'create') + argsdict_part["args"] = spicemanip(trigger_args_part, 'create') if len(argsdict_part["args"]) and (argsdict_part["args"][0] == "-a" or argsdict_part["args"][-1] == "-a"): argsdict_part["adminswitch"] = True if argsdict_part["args"][0] == "-a": - argsdict_part["args"] = spicemanip.main(argsdict_part["args"], '2+', 'list') + argsdict_part["args"] = spicemanip(argsdict_part["args"], '2+', 'list') elif argsdict_part["args"][-1] == "-a": del argsdict_part["args"][-1] else: @@ -471,14 +471,14 @@ def trigger_hyphen_arg_handler(bot, trigger, botcom): "on", "off" ]: - target = spicemanip.main(botcom.dict["args"], 1) or trigger.nick + target = spicemanip(botcom.dict["args"], 1) or trigger.nick if not target: if botcom.dict["hyphen_arg"] in ['enable', 'unblock', "activate", "on"]: botmessagelog.messagelog_error(botcom.dict["log_id"], "Who/Where am I enabling " + str(botcom.dict["comtext"]) + " usage for?") else: botmessagelog.messagelog_error(botcom.dict["log_id"], "Who/Where am I disabling " + str(botcom.dict["comtext"]) + " usage for?") return False - botcom.dict["args"] = spicemanip.main(botcom.dict["args"], "2+", "list") + botcom.dict["args"] = spicemanip(botcom.dict["args"], "2+", "list") if not botdb.check_nick_id(target) and not botchannels.check_channel_bot(target, True): botmessagelog.messagelog_error(botcom.dict["log_id"], "I don't know who/what " + str(target) + " is.") @@ -508,7 +508,7 @@ def trigger_hyphen_arg_handler(bot, trigger, botcom): botmessagelog.messagelog_error(botcom.dict["log_id"], botcom.dict["comtext"] + " is already disabled for " + str(target)) return False - trailingmessage = spicemanip.main(botcom.dict["args"], 0) or "No reason given." + trailingmessage = spicemanip(botcom.dict["args"], 0) or "No reason given." timestamp = str(datetime.datetime.utcnow()) botcommands.set_command_disabled(botcom.dict["realcomref"], target, timestamp, trailingmessage, trigger.nick) @@ -517,19 +517,19 @@ def trigger_hyphen_arg_handler(bot, trigger, botcom): if botcom.dict["hyphen_arg"] in ['multirun', 'multiruns']: - onoff = spicemanip.main(botcom.dict["args"], 1) or None + onoff = spicemanip(botcom.dict["args"], 1) or None if not onoff or onoff not in ['enable', 'unblock', "activate", "on"]: botmessagelog.messagelog_error(botcom.dict["log_id"], "Do you want to enable or disable " + str(botcom.dict["comtext"]) + " multirun usage?") return False - target = spicemanip.main(botcom.dict["args"], 1) or trigger.nick + target = spicemanip(botcom.dict["args"], 1) or trigger.nick if not target: if onoff in ['enable', 'unblock', "activate", "on"]: botmessagelog.messagelog_error(botcom.dict["log_id"], "Who/Where am I enabling " + str(botcom.dict["comtext"]) + " multirun usage for?") else: botmessagelog.messagelog_error(botcom.dict["log_id"], "Who/Where am I disabling " + str(botcom.dict["comtext"]) + " multirun usage for?") return False - botcom.dict["args"] = spicemanip.main(botcom.dict["args"], "2+", "list") + botcom.dict["args"] = spicemanip(botcom.dict["args"], "2+", "list") if not botdb.check_nick_id(target) and not botchannels.check_channel_bot(target, True): botmessagelog.messagelog_error(botcom.dict["log_id"], "I don't know who/what " + str(target) + " is.") @@ -559,7 +559,7 @@ def trigger_hyphen_arg_handler(bot, trigger, botcom): botmessagelog.messagelog_error(botcom.dict["log_id"], botcom.dict["comtext"] + " multirun is already disabled for " + str(target)) return False - trailingmessage = spicemanip.main(botcom.dict["args"], 0) or "No reason given." + trailingmessage = spicemanip(botcom.dict["args"], 0) or "No reason given." timestamp = str(datetime.datetime.utcnow()) botcommands.set_command_disabled(botcom.dict["realcomref"], target, timestamp, trailingmessage, trigger.nick, "multirun") @@ -583,11 +583,11 @@ def trigger_hyphen_arg_handler(bot, trigger, botcom): return False elif botcom.dict["hyphen_arg"] in ['contribs', 'contrib', "contributors"]: - botmessagelog.messagelog(botcom.dict["log_id"], "The contributors of the " + str(botcom.dict["comtext"]) + " command are " + spicemanip.main(botcom.dict["dict"]["contributors"], "andlist") + ".") + botmessagelog.messagelog(botcom.dict["log_id"], "The contributors of the " + str(botcom.dict["comtext"]) + " command are " + spicemanip(botcom.dict["dict"]["contributors"], "andlist") + ".") return False elif botcom.dict["hyphen_arg"] in ['alias', 'aliases']: - botmessagelog.messagelog(botcom.dict["log_id"], "The alaises of the " + str(botcom.dict["comtext"]) + " command are " + spicemanip.main(botcom.dict["dict"]["validcoms"], "andlist") + ".") + botmessagelog.messagelog(botcom.dict["log_id"], "The alaises of the " + str(botcom.dict["comtext"]) + " command are " + spicemanip(botcom.dict["dict"]["validcoms"], "andlist") + ".") return False return False diff --git a/sopel_modules/SpiceBot/Reddit.py b/sopel_modules/SpiceBot/Reddit.py index 778eb25..ed14533 100644 --- a/sopel_modules/SpiceBot/Reddit.py +++ b/sopel_modules/SpiceBot/Reddit.py @@ -7,7 +7,7 @@ This is the SpiceBot Reddit system. from sopel.config.types import StaticSection, ValidatedAttribute from sopel.formatting import bold, color, colors -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip import datetime as dt import praw @@ -56,7 +56,7 @@ class BotReddit(): def user_handler(self, trigger_argsdict): subcommand_valid = ['check'] - subcommand = spicemanip.main([x for x in trigger_argsdict["args"] if x in subcommand_valid], 1) or 'check' + subcommand = spicemanip([x for x in trigger_argsdict["args"] if x in subcommand_valid], 1) or 'check' userreal = self.reddit_user_exists(trigger_argsdict["command"]) if not userreal["exists"]: @@ -97,7 +97,7 @@ class BotReddit(): def subreddit_handler(self, trigger_argsdict): subcommand_valid = ['check', 'hot', 'new', 'top', 'random', 'controversial', 'gilded', 'rising', 'best'] - subcommand = spicemanip.main([x for x in trigger_argsdict["args"] if x in subcommand_valid], 1) or 'check' + subcommand = spicemanip([x for x in trigger_argsdict["args"] if x in subcommand_valid], 1) or 'check' fullrurul = str("https://www.reddit.com/" + trigger_argsdict["slashcomm"] + "/" + trigger_argsdict["command"]) @@ -116,9 +116,9 @@ class BotReddit(): return dispmsg if subcommand == 'random': - targnum = spicemanip.main([x for x in trigger_argsdict["args"] if str(x).isdigit()], 1) or 500 + targnum = spicemanip([x for x in trigger_argsdict["args"] if str(x).isdigit()], 1) or 500 else: - targnum = spicemanip.main([x for x in trigger_argsdict["args"] if str(x).isdigit()], 1) or 1 + targnum = spicemanip([x for x in trigger_argsdict["args"] if str(x).isdigit()], 1) or 1 targnum = int(targnum) if subcommand == 'new': @@ -162,11 +162,11 @@ class BotReddit(): return dispmsg def trigger_handler(self, trigger): - trigger_args = spicemanip.main(trigger.args[1], 'create') + trigger_args = spicemanip(trigger.args[1], 'create') trigger_argsdict = { - "slashcomm": spicemanip.main(trigger_args, 1).lower()[:1], - "command": spicemanip.main(trigger_args, 1).lower()[2:], - "args": spicemanip.main(trigger_args, "2+", 'list') + "slashcomm": spicemanip(trigger_args, 1).lower()[:1], + "command": spicemanip(trigger_args, 1).lower()[2:], + "args": spicemanip(trigger_args, "2+", 'list') } if trigger_argsdict["slashcomm"] == "u": trigger_argsdict["urltypetxt"] = "user" diff --git a/sopel_modules/SpiceBot/Tools.py b/sopel_modules/SpiceBot/Tools.py index 83b483f..e6fa9b7 100644 --- a/sopel_modules/SpiceBot/Tools.py +++ b/sopel_modules/SpiceBot/Tools.py @@ -14,7 +14,7 @@ from operator import itemgetter from collections import abc from pygit2 import clone_repository -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip from .Logs import logs from .Config import config as botconfig @@ -231,7 +231,7 @@ def similar_list(searchitem, searchlist, matchcount=1, searchorder='reverse'): sim_num, sim_listitems = (list(x) for x in zip(*sorted(zip(sim_num, sim_listitems), key=itemgetter(0)))) if searchorder == 'reverse': - sim_listitems = spicemanip.main(sim_listitems, 'reverse', "list") + sim_listitems = spicemanip(sim_listitems, 'reverse', "list") sim_listitems[-matchcount:] diff --git a/sopel_modules/SpiceBot/Translate.py b/sopel_modules/SpiceBot/Translate.py index c43adf4..90b7639 100644 --- a/sopel_modules/SpiceBot/Translate.py +++ b/sopel_modules/SpiceBot/Translate.py @@ -1,7 +1,7 @@ # coding=utf8 from __future__ import unicode_literals, absolute_import, division, print_function -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip import re from num2words import num2words @@ -21,10 +21,10 @@ class Translate(): for translationtype in translationtypes: if translationtype == "hyphen": - totranslate = spicemanip.main(totranslate, 0).replace(' ', '-') + totranslate = spicemanip(totranslate, 0).replace(' ', '-') elif translationtype == "underscore": - totranslate = spicemanip.main(totranslate, 0).replace(' ', '_') + totranslate = spicemanip(totranslate, 0).replace(' ', '_') elif translationtype == "ermahgerd": totranslate = self.trernslert(totranslate) @@ -42,10 +42,10 @@ class Translate(): totranslate = self.text_one_to_zero_swap(totranslate) elif translationtype == "upper": - totranslate = spicemanip.main(totranslate, 0).upper() + totranslate = spicemanip(totranslate, 0).upper() elif translationtype == "lower": - totranslate = spicemanip.main(totranslate, 0).lower() + totranslate = spicemanip(totranslate, 0).lower() return totranslate @@ -66,7 +66,7 @@ class Translate(): else: new_word = word[1:] + first + 'ay' rebuildarray.append(new_word) - words = spicemanip.main(rebuildarray, 0) + words = spicemanip(rebuildarray, 0) return words def trernslert(self, werds): @@ -143,7 +143,7 @@ class Translate(): return "No input provided" if not isinstance(words, list): words = [words] - words = spicemanip.main(words, 0).split(" ") + words = spicemanip(words, 0).split(" ") outputarray = [] for word in words: if not self.isitbinary(word): @@ -152,7 +152,7 @@ class Translate(): word = str(word).replace('0', '1') word = str(word).replace('2', '0') outputarray.append(str(word)) - outputarray = spicemanip.main(outputarray, 0) + outputarray = spicemanip(outputarray, 0) return outputarray def text_binary_swap(self, words): @@ -160,16 +160,16 @@ class Translate(): return "No input provided" if not isinstance(words, list): words = [words] - words = spicemanip.main(words, 0).split(" ") + words = spicemanip(words, 0).split(" ") outputarray = [] for word in words: if self.isitbinary(word): word = self.bits2string(word) or 'error' else: word = self.string2bits(word) or 1 - word = spicemanip.main(word, 0) + word = spicemanip(word, 0) outputarray.append(str(word)) - outputarray = spicemanip.main(outputarray, 0) + outputarray = spicemanip(outputarray, 0) return outputarray def unicode_string_cleanup(string): diff --git a/sopel_modules/SpiceBot/Users.py b/sopel_modules/SpiceBot/Users.py index 5eb26c3..e944b4f 100644 --- a/sopel_modules/SpiceBot/Users.py +++ b/sopel_modules/SpiceBot/Users.py @@ -8,7 +8,7 @@ from sopel.tools import Identifier from .Database import db as botdb from .Tools import is_number, inlist, similar, array_arrangesort -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip import threading import re @@ -393,13 +393,13 @@ class BotUsers(): sim_num.append(similarlevel) if sim_user != [] and sim_num != []: sim_num, sim_user = array_arrangesort(bot, sim_num, sim_user) - closestmatch = spicemanip.main(sim_user, 'reverse', "list") + closestmatch = spicemanip(sim_user, 'reverse', "list") listnumb, relist = 1, [] for item in closestmatch: if listnumb <= 3: relist.append(str(item)) listnumb += 1 - closestmatches = spicemanip.main(relist, "andlist") + closestmatches = spicemanip(relist, "andlist") targetgooderror = "It looks like you're trying to target someone! Did you mean: " + str(closestmatches) + "?" else: targetgooderror = "I am not sure who that is." @@ -437,7 +437,7 @@ class BotUsers(): if outputtype == 'list': return validtargs elif outputtype == 'random': - return spicemanip.main(validtargs, 'random') + return spicemanip(validtargs, 'random') users = BotUsers() diff --git a/sopel_modules/SpiceBot_Core_Commands/AI.py b/sopel_modules/SpiceBot_Core_Commands/AI.py index fe925fa..16f1f7a 100644 --- a/sopel_modules/SpiceBot_Core_Commands/AI.py +++ b/sopel_modules/SpiceBot_Core_Commands/AI.py @@ -6,7 +6,7 @@ import sopel.module import sopel_modules.SpiceBot as SpiceBot -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip @SpiceBot.prerun('nickname') @@ -59,7 +59,7 @@ def bot_command_rule_ai(bot, trigger): command_type = 'nickname' trigger_args, trigger_command, trigger_prefix = SpiceBot.make_trigger_args(message, 'nickname') trigger_args.insert(0, trigger_command) - fulltrigger = bot.nick + " " + spicemanip.main(trigger_args, 0) + fulltrigger = bot.nick + " " + spicemanip(trigger_args, 0) if str(trigger_command).startswith(bot.config.SpiceBot_Commands.query_prefix): return if fulltrigger in SpiceBot.commands.dict['nickrules']: @@ -73,7 +73,7 @@ def bot_command_rule_ai(bot, trigger): command_type = 'module' trigger_args, trigger_command, trigger_prefix = SpiceBot.make_trigger_args(message, 'module') trigger_args.insert(0, trigger_command) - fulltrigger = spicemanip.main(trigger_args, 0) + fulltrigger = spicemanip(trigger_args, 0) # patch for people typing "...", maybe other stuff, but this verifies that there is still a command here if trigger_command.startswith(tuple(bot.config.core.prefix_list)): return @@ -82,11 +82,11 @@ def bot_command_rule_ai(bot, trigger): return else: command_type = 'other' - trigger_args = spicemanip.main(message, 'create') + trigger_args = spicemanip(message, 'create') if not len(trigger_args): return trigger_command = trigger_args[0] - fulltrigger = spicemanip.main(trigger_args, 0) + fulltrigger = spicemanip(trigger_args, 0) returnmessage = SpiceBot.botai.on_message(bot, trigger, fulltrigger) if returnmessage: @@ -94,7 +94,7 @@ def bot_command_rule_ai(bot, trigger): return if command_type == 'nickname': - try_trigger = spicemanip.main(fulltrigger, "2+") + try_trigger = spicemanip(fulltrigger, "2+") returnmessage = SpiceBot.botai.on_message(bot, trigger, try_trigger) if returnmessage: bot.osd(str(returnmessage)) @@ -116,7 +116,7 @@ def bot_command_rule_ai(bot, trigger): if trigger_args[0].lower() in ["what", "where"] and trigger_args[1].lower() in ["is", "are"]: # TODO saved definitions - searchterm = spicemanip.main(trigger_args, "3+") or None + searchterm = spicemanip(trigger_args, "3+") or None if searchterm: if trigger_args[0].lower() == "where": searchreturn = SpiceBot.google.search(searchterm, 'maps') @@ -132,7 +132,7 @@ def bot_command_rule_ai(bot, trigger): return elif trigger_args[0].lower() in ["can", "have"] and trigger_args[1].lower() in ["you"] and trigger_args[2].lower() in ["see", "seen"]: - target = spicemanip.main(trigger_args, "4+") or None + target = spicemanip(trigger_args, "4+") or None if target: if SpiceBot.inlist(trigger.nick, bot.users): realtarget = SpiceBot.inlist_match(target, bot.users) @@ -141,7 +141,7 @@ def bot_command_rule_ai(bot, trigger): for channel in list(bot.channels.keys()): if SpiceBot.inlist(trigger.nick, list(bot.channels[channel].privileges.keys())): targetchannels.append(channel) - dispmsg.append(realtarget + " is in " + spicemanip.main(targetchannels, 'andlist')) + dispmsg.append(realtarget + " is in " + spicemanip(targetchannels, 'andlist')) bot.osd(dispmsg) else: bot.osd(trigger.nick + ", no. I cannot see " + target + " right now!") @@ -164,7 +164,7 @@ def bot_command_rule_ai(bot, trigger): for nonjedi in [bot.nick, trigger.nick]: if nonjedi in jedilist: jedilist.remove(nonjedi) - jedi = spicemanip.main(jedilist, 'random') + jedi = spicemanip(jedilist, 'random') if jedi: bot.osd("turns to " + jedi + " and shoots him.", trigger.sender, 'action') @@ -183,7 +183,7 @@ def bot_command_rule_ai(bot, trigger): return elif fulltrigger.lower().startswith(tuple(["make me a", "beam me a"])): - makemea = spicemanip.main(trigger_args, "4+") or None + makemea = spicemanip(trigger_args, "4+") or None if makemea: bot.osd("beams " + trigger.nick + " a " + makemea, trigger.sender, 'action') else: @@ -191,7 +191,7 @@ def bot_command_rule_ai(bot, trigger): return elif fulltrigger.lower().startswith("beam me to"): - location = spicemanip.main(trigger_args, "4+") or None + location = spicemanip(trigger_args, "4+") or None if location: bot.osd("locks onto " + trigger.nick + "s coordinates and transports them to " + location, 'action') else: @@ -209,7 +209,7 @@ def bot_command_rule_ai(bot, trigger): # TODO # elif fulltrigger.lower().startswith(tuple(["have you seen"])): - # posstarget = spicemanip.main(trigger_args, 4) or 0 + # posstarget = spicemanip(trigger_args, 4) or 0 # message = seen_search(bot, trigger, posstarget) # bot.osd(message) # return @@ -217,7 +217,7 @@ def bot_command_rule_ai(bot, trigger): closestmatches = SpiceBot.similar_list(trigger_command, list(SpiceBot.commands.dict['commands']["nickname"].keys()), 3, 'reverse') if len(closestmatches): - closestmatches = spicemanip.main(closestmatches, "andlist") + closestmatches = spicemanip(closestmatches, "andlist") bot.osd("I don't know what you are asking me to do! Did you mean: " + str(closestmatches) + "?") return else: diff --git a/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py b/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py index 4bd9626..86451ac 100644 --- a/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py +++ b/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip import sopel_modules.SpiceBot as SpiceBot @@ -26,5 +26,5 @@ def bot_command_process(bot, trigger, botcom): if not botcom.dict['com'].endswith("s"): botcom.dict['com'] = str(botcom.dict['com'] + "s") - privlist = spicemanip.main(SpiceBot.bot_privs(botcom.dict['com']), 'andlist') + privlist = spicemanip(SpiceBot.bot_privs(botcom.dict['com']), 'andlist') bot.osd(str(bot.nick) + " " + botcom.dict['com'] + ": " + privlist) diff --git a/sopel_modules/SpiceBot_Core_Commands/Channels.py b/sopel_modules/SpiceBot_Core_Commands/Channels.py index 75e71e4..83cd269 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Channels.py +++ b/sopel_modules/SpiceBot_Core_Commands/Channels.py @@ -5,7 +5,7 @@ This is the SpiceBot Channels system. """ import sopel -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip import sopel_modules.SpiceBot as SpiceBot @@ -17,15 +17,15 @@ def nickname_comand_channels(bot, trigger, botcom): if not len(botcom.dict['args']): commandused = 'list' else: - commandused = spicemanip.main(botcom.dict['args'], 1).lower() + commandused = spicemanip(botcom.dict['args'], 1).lower() - botcom.dict['args'] = spicemanip.main(botcom.dict['args'], '2+', 'list') + botcom.dict['args'] = spicemanip(botcom.dict['args'], '2+', 'list') if commandused == 'list': botcount = len(list(bot.channels.keys())) servercount = len(list(SpiceBot.channels.dict['list'].keys())) displayval = "I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server." - chanlist = spicemanip.main(list(bot.channels.keys()), 'andlist') + chanlist = spicemanip(list(bot.channels.keys()), 'andlist') bot.osd([displayval, "You can find me in " + chanlist]) return @@ -36,7 +36,7 @@ def nickname_comand_channels(bot, trigger, botcom): return elif commandused == 'random': - channel = spicemanip.main(SpiceBot.channels.dict['list'], 'random') + channel = spicemanip(SpiceBot.channels.dict['list'], 'random') topic = SpiceBot.channels.dict['list'][channel]['topic'] msg = ["Random channel for you: {}.".format(SpiceBot.channels.dict['list'][channel]['name'])] if topic and not topic.isspace(): @@ -65,7 +65,7 @@ def nickname_comand_channels(bot, trigger, botcom): if not len(botcom.dict['args']): SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel name input missing.") return - channel = spicemanip.main(botcom.dict['args'], 1) + channel = spicemanip(botcom.dict['args'], 1) if not SpiceBot.inlist(channel.lower(), list(SpiceBot.channels.dict['list'].keys())): SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel name {} not valid.".format(channel)) return @@ -82,7 +82,7 @@ def nickname_comand_channels(bot, trigger, botcom): else: channel = trigger.sender else: - channel = spicemanip.main(botcom.dict['args'], 1) + channel = spicemanip(botcom.dict['args'], 1) if not SpiceBot.inlist(channel.lower(), list(SpiceBot.channels.dict['list'].keys())): SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel name {} not valid.".format(channel)) return @@ -95,14 +95,14 @@ def nickname_comand_channels(bot, trigger, botcom): if not len(privlist): dispmsg.append("There are no Channel " + commandused.upper() + "s for " + str(channel)) else: - oplist = spicemanip.main(privlist, 'andlist') + oplist = spicemanip(privlist, 'andlist') dispmsg.append("Channel " + commandused.upper() + "s for " + str(channel) + " are: " + oplist) bot.osd(dispmsg, trigger.nick, 'notice') return # Users List if commandused == 'users': - channel = spicemanip.main(botcom.dict['args'], 1) + channel = spicemanip(botcom.dict['args'], 1) if not SpiceBot.inlist(channel.lower(), list(SpiceBot.channels.dict['list'].keys())): SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel name {} not valid.".format(channel)) return @@ -113,7 +113,7 @@ def nickname_comand_channels(bot, trigger, botcom): if not len(list(bot.channels[channel].privileges.keys())): dispmsg.append("There are no Channel users for " + str(channel)) else: - userslist = spicemanip.main(list(bot.channels[channel].privileges.keys()), 'andlist') + userslist = spicemanip(list(bot.channels[channel].privileges.keys()), 'andlist') dispmsg.append("Channel users for " + str(channel) + " are: " + userslist) bot.osd(dispmsg, trigger.nick, 'notice') return diff --git a/sopel_modules/SpiceBot_Core_Commands/Commands.py b/sopel_modules/SpiceBot_Core_Commands/Commands.py index e809343..812fc8d 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Commands.py +++ b/sopel_modules/SpiceBot_Core_Commands/Commands.py @@ -7,7 +7,7 @@ This Class stores commands in an easy to access manner """ import sopel -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip import sopel_modules.SpiceBot as SpiceBot @@ -21,7 +21,7 @@ def nickname_comand_commands(bot, trigger, botcom): if not len(botcom.dict['args']): commandused = 'list' else: - commandused = spicemanip.main(botcom.dict['args'], 1).lower() + commandused = spicemanip(botcom.dict['args'], 1).lower() if commandused == 'list': availablecomsnum, availablecomsfiles = 0, [] @@ -52,5 +52,5 @@ def nickname_comand_commands(bot, trigger, botcom): return if commandused == 'random': - bot.osd(["Here's a random command for you:", spicemanip.main(commands_list, 'random')]) + bot.osd(["Here's a random command for you:", spicemanip(commands_list, 'random')]) return diff --git a/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py b/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py index 9e1818b..537497d 100644 --- a/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py +++ b/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py @@ -7,7 +7,7 @@ This Class stores commands in an easy to access manner """ import sopel -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip import sopel_modules.SpiceBot as SpiceBot @@ -48,7 +48,7 @@ def query_detection_nick(bot, trigger, botcom): dispmsg = ["Cannot find any alias " + bot.nick + " commands: No valid commands match " + str(botcom.dict['com']) + "."] closestmatches = SpiceBot.similar_list(botcom.dict['com'], list(commands_list.keys()), 10, 'reverse') if len(closestmatches): - dispmsg.append("The following " + bot.nick + " commands match " + str(botcom.dict['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".") + dispmsg.append("The following " + bot.nick + " commands match " + str(botcom.dict['com']) + ": " + spicemanip(closestmatches, 'andlist') + ".") bot.osd(dispmsg, trigger.nick, 'notice') return @@ -56,7 +56,7 @@ def query_detection_nick(bot, trigger, botcom): if "aliasfor" in list(commands_list[botcom.dict['com']].keys()): realcom = commands_list[botcom.dict['com']]["aliasfor"] validcomlist = commands_list[realcom]["validcoms"] - bot.osd("The following " + bot.nick + " commands match " + str(botcom.dict['com']) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick, 'notice') + bot.osd("The following " + bot.nick + " commands match " + str(botcom.dict['com']) + ": " + spicemanip(validcomlist, 'andlist') + ".", trigger.nick, 'notice') return if botcom.dict['com'].endswith(bot.config.SpiceBot_Commands.query_prefix): @@ -69,7 +69,7 @@ def query_detection_nick(bot, trigger, botcom): if not len(closestmatches): bot.osd("Cannot find any similar " + bot.nick + " commands for " + str(botcom.dict['com']) + ".", trigger.nick, 'notice') else: - bot.osd("The following " + bot.nick + " commands may match " + str(botcom.dict['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick, 'notice') + bot.osd("The following " + bot.nick + " commands may match " + str(botcom.dict['com']) + ": " + spicemanip(closestmatches, 'andlist') + ".", trigger.nick, 'notice') return commandlist = [] @@ -80,7 +80,7 @@ def query_detection_nick(bot, trigger, botcom): if not len(commandlist): bot.osd("No " + bot.nick + " commands start with " + str(botcom.dict['com']) + ".", trigger.nick, 'notice') else: - bot.osd("The following " + bot.nick + " commands start with " + str(botcom.dict['com']) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick, 'notice') + bot.osd("The following " + bot.nick + " commands start with " + str(botcom.dict['com']) + ": " + spicemanip(commandlist, 'andlist') + ".", trigger.nick, 'notice') @SpiceBot.prerun_query('module', 'module') @@ -111,7 +111,7 @@ def query_detection(bot, trigger, botcom): dispmsg = ["Cannot find any alias commands: No valid commands match " + str(botcom.dict['com']) + "."] closestmatches = SpiceBot.similar_list(botcom.dict['com'], list(commands_list.keys()), 10, 'reverse') if len(closestmatches): - dispmsg.append("The following commands match " + str(botcom.dict['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".") + dispmsg.append("The following commands match " + str(botcom.dict['com']) + ": " + spicemanip(closestmatches, 'andlist') + ".") bot.osd(dispmsg, trigger.nick, 'notice') return @@ -119,7 +119,7 @@ def query_detection(bot, trigger, botcom): if "aliasfor" in list(commands_list[botcom.dict['com']].keys()): realcom = commands_list[botcom.dict['com']]["aliasfor"] validcomlist = commands_list[realcom]["validcoms"] - bot.osd("The following commands match " + str(botcom.dict['com']) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick, 'notice') + bot.osd("The following commands match " + str(botcom.dict['com']) + ": " + spicemanip(validcomlist, 'andlist') + ".", trigger.nick, 'notice') return if botcom.dict['com'][:-1] == "?": @@ -132,7 +132,7 @@ def query_detection(bot, trigger, botcom): if not len(closestmatches): bot.osd("Cannot find any similar commands for " + str(botcom.dict['com']) + ".", trigger.nick, 'notice') else: - bot.osd("The following commands may match " + str(botcom.dict['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick, 'notice') + bot.osd("The following commands may match " + str(botcom.dict['com']) + ": " + spicemanip(closestmatches, 'andlist') + ".", trigger.nick, 'notice') return commandlist = [] @@ -143,4 +143,4 @@ def query_detection(bot, trigger, botcom): if not len(commandlist): bot.osd("No commands start with " + str(botcom.dict['com']) + ".", trigger.nick, 'notice') else: - bot.osd("The following commands start with " + str(botcom.dict['com']) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick, 'notice') + bot.osd("The following commands start with " + str(botcom.dict['com']) + ": " + spicemanip(commandlist, 'andlist') + ".", trigger.nick, 'notice') diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index 46aabf7..825388b 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -9,7 +9,7 @@ import sopel.module import sopel_modules.SpiceBot as SpiceBot -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip from word2number import w2n from random import randint @@ -34,13 +34,13 @@ def bot_dictcom_process(bot, trigger, botcom): botcom.dict["responsekey"] = "?default" # handling for special cases - posscom = spicemanip.main(botcom.dict['args'], 1) + posscom = spicemanip(botcom.dict['args'], 1) if posscom.lower() in [command.lower() for command in botcom.dict["dict"].keys()]: for command in botcom.dict["dict"].keys(): if command.lower() == posscom.lower(): posscom = command botcom.dict["responsekey"] = posscom - botcom.dict['args'] = spicemanip.main(botcom.dict['args'], '2+', 'list') + botcom.dict['args'] = spicemanip(botcom.dict['args'], '2+', 'list') botcom.dict["dict"][botcom.dict["responsekey"]]["type"] = botcom.dict["dict"][botcom.dict["responsekey"]]["type"] botcom.dict["nonstockoptions"] = [] @@ -51,7 +51,7 @@ def bot_dictcom_process(bot, trigger, botcom): # This allows users to specify which reply by number by using an ! and a digit (first or last in string) validspecifides = ['last', 'random', 'count', 'view', 'add', 'del', 'remove', 'special'] botcom.dict["specified"] = None - argone = spicemanip.main(botcom.dict['args'], 1) + argone = spicemanip(botcom.dict['args'], 1) if str(argone).startswith("--") and len(str(argone)) > 2: if str(argone[2:]).isdigit(): botcom.dict["specified"] = int(argone[2:]) @@ -67,7 +67,7 @@ def bot_dictcom_process(bot, trigger, botcom): except ValueError: botcom.dict["specified"] = None if botcom.dict["specified"]: - botcom.dict['args'] = spicemanip.main(botcom.dict['args'], '2+', 'list') + botcom.dict['args'] = spicemanip(botcom.dict['args'], '2+', 'list') # commands that can be updated if botcom.dict["dict"][botcom.dict["responsekey"]]["updates_enabled"]: @@ -79,7 +79,7 @@ def bot_dictcom_process(bot, trigger, botcom): 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 [] if botcom.dict["specified"] == 'special': - nonstockoptions = spicemanip.main(botcom.dict["nonstockoptions"], "andlist") + nonstockoptions = spicemanip(botcom.dict["nonstockoptions"], "andlist") return bot.osd("The special options for " + str(botcom.dict["realcom"]) + " command include: " + str(nonstockoptions) + ".") elif botcom.dict["specified"] == 'count': @@ -106,7 +106,7 @@ def bot_dictcom_process(bot, trigger, botcom): if not botcom.dict["dict"][botcom.dict["responsekey"]]["updates_enabled"]: return bot.osd("The " + str(botcom.dict["realcom"]) + " " + str(botcom.dict["responsekey"] or '') + " entry list cannot be updated.") - fulltext = spicemanip.main(botcom.dict['args'], 0) + fulltext = spicemanip(botcom.dict['args'], 0) if not fulltext: return bot.osd("What would you like to add to the " + str(botcom.dict["realcom"]) + " " + str(botcom.dict["responsekey"] or '') + " entry list?") @@ -125,7 +125,7 @@ def bot_dictcom_process(bot, trigger, botcom): if not botcom.dict["dict"][botcom.dict["responsekey"]]["updates_enabled"]: return bot.osd("The " + str(botcom.dict["realcom"]) + " " + str(botcom.dict["responsekey"] or '') + " entry list cannot be updated.") - fulltext = spicemanip.main(botcom.dict['args'], 0) + fulltext = spicemanip(botcom.dict['args'], 0) if not fulltext: return bot.osd("What would you like to remove from the " + str(botcom.dict["realcom"]) + " " + str(botcom.dict["responsekey"] or '') + " entry list?") @@ -161,7 +161,7 @@ def bot_dictcom_responses(bot, trigger, botcom): if botcom.dict["dict"][botcom.dict["responsekey"]]["target_required"]: # try first term as a target - posstarget = spicemanip.main(botcom.dict['args'], 1) or 0 + posstarget = spicemanip(botcom.dict['args'], 1) or 0 targetbypass = botcom.dict["dict"][botcom.dict["responsekey"]]["target_bypass"] targetchecking = SpiceBot.users.target_check(bot, trigger, posstarget, targetbypass) if not targetchecking["targetgood"]: @@ -180,11 +180,11 @@ def bot_dictcom_responses(bot, trigger, botcom): if not reaction: commandrunconsensus.append([targetchecking["error"]]) else: - botcom.dict["target"] = spicemanip.main(botcom.dict['args'], 1) - botcom.dict['args'] = spicemanip.main(botcom.dict['args'], '2+', 'list') + botcom.dict["target"] = spicemanip(botcom.dict['args'], 1) + botcom.dict['args'] = spicemanip(botcom.dict['args'], '2+', 'list') # $blank input - botcom.dict["completestring"] = spicemanip.main(botcom.dict['args'], 0) or '' + botcom.dict["completestring"] = spicemanip(botcom.dict['args'], 0) or '' if botcom.dict["dict"][botcom.dict["responsekey"]]["blank_required"]: if botcom.dict["completestring"] == '' or not botcom.dict["completestring"]: @@ -196,13 +196,13 @@ def bot_dictcom_responses(bot, trigger, botcom): if botcom.dict["dict"][botcom.dict["responsekey"]]["blank_phrasehandle"]: if botcom.dict["dict"][botcom.dict["responsekey"]]["blank_phrasehandle"] != []: - if spicemanip.main(botcom.dict["completestring"], 1).lower() not in botcom.dict["dict"][botcom.dict["responsekey"]]["blank_phrasehandle"]: + if spicemanip(botcom.dict["completestring"], 1).lower() not in botcom.dict["dict"][botcom.dict["responsekey"]]["blank_phrasehandle"]: botcom.dict["completestring"] = botcom.dict["dict"][botcom.dict["responsekey"]]["blank_phrasehandle"][0] + " " + botcom.dict["completestring"] - elif spicemanip.main(botcom.dict["completestring"], 1).lower() in botcom.dict["dict"][botcom.dict["responsekey"]]["blank_phrasehandle"]: - if spicemanip.main(botcom.dict["completestring"], 1).lower() != botcom.dict["dict"][botcom.dict["responsekey"]]["blank_phrasehandle"][0]: - botcom.dict['args'] = spicemanip.main(botcom.dict['args'], '2+', 'list') + elif spicemanip(botcom.dict["completestring"], 1).lower() in botcom.dict["dict"][botcom.dict["responsekey"]]["blank_phrasehandle"]: + if spicemanip(botcom.dict["completestring"], 1).lower() != botcom.dict["dict"][botcom.dict["responsekey"]]["blank_phrasehandle"][0]: + botcom.dict['args'] = spicemanip(botcom.dict['args'], '2+', 'list') if botcom.dict['args'] != []: - botcom.dict["completestring"] = botcom.dict["dict"][botcom.dict["responsekey"]]["blank_phrasehandle"][0] + " " + spicemanip.main(botcom.dict['args'], 0) + botcom.dict["completestring"] = botcom.dict["dict"][botcom.dict["responsekey"]]["blank_phrasehandle"][0] + " " + spicemanip(botcom.dict['args'], 0) if commandrunconsensus != []: botcom.dict["success"] = False @@ -221,10 +221,10 @@ def bot_dictcom_reply_shared(bot, trigger, botcom): currentspecified = len(botcom.dict["dict"][botcom.dict["responsekey"]]["responses"]) else: currentspecified = botcom.dict["specified"] - botcom.dict["replies"] = spicemanip.main(botcom.dict["dict"][botcom.dict["responsekey"]]["responses"], currentspecified, 'return') + botcom.dict["replies"] = spicemanip(botcom.dict["dict"][botcom.dict["responsekey"]]["responses"], currentspecified, 'return') botcom.dict["replynum"] = currentspecified else: - botcom.dict["replies"] = spicemanip.main(botcom.dict["dict"][botcom.dict["responsekey"]]["responses"], 'random', 'return') + botcom.dict["replies"] = spicemanip(botcom.dict["dict"][botcom.dict["responsekey"]]["responses"], 'random', 'return') try: botcom.dict["replynum"] = botcom.dict["dict"][botcom.dict["responsekey"]]["responses"].index(botcom.dict["replies"]) except Exception as e: @@ -258,7 +258,7 @@ def bot_dictcom_reply_shared(bot, trigger, botcom): # the remaining input if "$input" in rply: - rply = rply.replace("$input", spicemanip.main(botcom.dict['args'], 0) or botcom.dict["realcom"]) + rply = rply.replace("$input", spicemanip(botcom.dict['args'], 0) or botcom.dict["realcom"]) # translation if botcom.dict["dict"][botcom.dict["responsekey"]]["translations"]: @@ -266,11 +266,11 @@ def bot_dictcom_reply_shared(bot, trigger, botcom): # text to precede the output if botcom.dict["dict"][botcom.dict["responsekey"]]["prefixtext"] and botcom.dict["success"]: - rply = spicemanip.main(botcom.dict["dict"][botcom.dict["responsekey"]]["prefixtext"], 'random') + rply + rply = spicemanip(botcom.dict["dict"][botcom.dict["responsekey"]]["prefixtext"], 'random') + rply # text to follow the output if botcom.dict["dict"][botcom.dict["responsekey"]]["suffixtext"] and botcom.dict["success"]: - rply = rply + spicemanip.main(botcom.dict["dict"][botcom.dict["responsekey"]]["suffixtext"], 'random') + rply = rply + spicemanip(botcom.dict["dict"][botcom.dict["responsekey"]]["suffixtext"], 'random') # trigger.nick if "$instigator" in rply: @@ -279,7 +279,7 @@ def bot_dictcom_reply_shared(bot, trigger, botcom): # random user if "$randuser" in rply: if not trigger.is_privmsg: - randuser = spicemanip.main(SpiceBot.users.random_valid_target(trigger, 'random')) + randuser = spicemanip(SpiceBot.users.random_valid_target(trigger, 'random')) else: randuser = trigger.nick rply = rply.replace("$randuser", randuser) @@ -310,7 +310,7 @@ def bot_dictcom_reply_shared(bot, trigger, botcom): # smaller variations for the text if "$replyvariation" in rply: if botcom.dict["dict"][botcom.dict["responsekey"]]["replyvariation"] != []: - variation = spicemanip.main(botcom.dict["dict"][botcom.dict["responsekey"]]["replyvariation"], 'random') + variation = spicemanip(botcom.dict["dict"][botcom.dict["responsekey"]]["replyvariation"], 'random') rply = rply.replace("$replyvariation", variation) else: rply = rply.replace("$replyvariation", '') @@ -328,7 +328,7 @@ def bot_dictcom_reply_shared(bot, trigger, botcom): for command in botcom.dict["dict"].keys(): if command not in ["?default", "validcoms", "contributors", "author", "type", "filepath", "filename", "hardcoded_channel_block", "description", "exampleresponse", "example", "usage", "privs"]: nonstockoptions.append(command) - nonstockoptions = spicemanip.main(nonstockoptions, "andlist") + nonstockoptions = spicemanip(nonstockoptions, "andlist") rply = rply.replace("$specialoptions", nonstockoptions) # saying, or action? @@ -360,9 +360,9 @@ def bot_dictcom_gif(bot, trigger, botcom): if botcom.dict["specified"]: if botcom.dict["specified"] > len(queries): botcom.dict["specified"] = len(queries) - query = spicemanip.main(queries, botcom.dict["specified"], 'return') + query = spicemanip(queries, botcom.dict["specified"], 'return') else: - query = spicemanip.main(queries, 'random', 'return') + query = spicemanip(queries, 'random', 'return') searchdict = {"query": query, "gifsearch": searchapis} diff --git a/sopel_modules/SpiceBot_Core_Commands/Gif.py b/sopel_modules/SpiceBot_Core_Commands/Gif.py index fa072cd..f8d07db 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Gif.py +++ b/sopel_modules/SpiceBot_Core_Commands/Gif.py @@ -6,7 +6,7 @@ import sopel.module import sopel_modules.SpiceBot as SpiceBot -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip # TODO custom gif shortcut commands @@ -18,7 +18,7 @@ def gif_trigger(bot, trigger, botcom): if not len(botcom.dict['args']): return SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Please present a query to search.") - query = spicemanip.main(botcom.dict['args'], 0) + query = spicemanip(botcom.dict['args'], 0) searchapis = list(SpiceBot.gif.valid_api.keys()) searchdict = {"query": query, "gifsearch": searchapis} @@ -40,7 +40,7 @@ def gifapi_triggers(bot, trigger, botcom): if not len(botcom.dict['args']): return SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Please present a query to search.") - query = spicemanip.main(botcom.dict['args'], 0) + query = spicemanip(botcom.dict['args'], 0) searchdict = {"query": query, "gifsearch": botcom.dict['com']} gifdict = SpiceBot.gif.get_gif(searchdict) diff --git a/sopel_modules/SpiceBot_Core_Commands/Logs.py b/sopel_modules/SpiceBot_Core_Commands/Logs.py index 3e224ed..2188961 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Logs.py +++ b/sopel_modules/SpiceBot_Core_Commands/Logs.py @@ -7,7 +7,7 @@ This is the SpiceBot Logs System # sopel imports import sopel.module -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip import sopel_modules.SpiceBot as SpiceBot @@ -20,9 +20,9 @@ def bot_command_logs(bot, trigger, botcom): SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "I was unable to process this Bot Nick command due to privilege issues.") return - logtype = spicemanip.main(botcom.dict['args'], 1) or None + logtype = spicemanip(botcom.dict['args'], 1) or None if not logtype: - bot.osd("Current valid log(s) include: " + spicemanip.main(list(SpiceBot.logs.dict["list"].keys()), 'andlist'), trigger.sender, 'action') + bot.osd("Current valid log(s) include: " + spicemanip(list(SpiceBot.logs.dict["list"].keys()), 'andlist'), trigger.sender, 'action') return if not SpiceBot.inlist(logtype, list(SpiceBot.logs.dict["list"].keys())): @@ -30,7 +30,7 @@ def bot_command_logs(bot, trigger, botcom): if not len(closestmatches): SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "No valid logs match " + str(logtype) + ".", trigger.nick, 'notice') else: - SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "The following commands may match " + str(logtype) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick, 'notice') + SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "The following commands may match " + str(logtype) + ": " + spicemanip(closestmatches, 'andlist') + ".", trigger.nick, 'notice') return diff --git a/sopel_modules/SpiceBot_Core_Commands/Messaging.py b/sopel_modules/SpiceBot_Core_Commands/Messaging.py index 61ace21..510a38d 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Messaging.py +++ b/sopel_modules/SpiceBot_Core_Commands/Messaging.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip import sopel_modules.SpiceBot as SpiceBot @@ -40,14 +40,14 @@ def bot_command_process(bot, trigger, botcom): SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "You must specify a channel or nick.") return - target = spicemanip.main(botcom.dict['args'], 1) + target = spicemanip(botcom.dict['args'], 1) if (target not in ['allchans', 'allnicks'] and not SpiceBot.inlist(target.lower(), list(SpiceBot.channels.dict['list'].keys())) and not SpiceBot.inlist(target.lower(), bot.users)): SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel/nick name {} not valid.".format(target)) return - botcom.dict['args'] = spicemanip.main(botcom.dict['args'], '2+', 'list') + botcom.dict['args'] = spicemanip(botcom.dict['args'], '2+', 'list') if target == 'allchans': targetsendlist = list(bot.channels.keys()) @@ -56,7 +56,7 @@ def bot_command_process(bot, trigger, botcom): else: targetsendlist = [target] - botmessage = spicemanip.main(botcom.dict['args'], 0) + botmessage = spicemanip(botcom.dict['args'], 0) if not botmessage: SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "You must specify a message to send.") return diff --git a/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py b/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py index 14cedae..ed7ac5b 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py +++ b/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip import sopel_modules.SpiceBot as SpiceBot @@ -20,13 +20,13 @@ def nickname_comand_update(bot, trigger, botcom): if not len(botcom.dict['args']): commandused = 'nodeps' else: - commandused = spicemanip.main(botcom.dict['args'], 1).lower() + commandused = spicemanip(botcom.dict['args'], 1).lower() if commandused not in ['deps', 'nodeps']: SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Please specify deps or nodeps") return - botcom.dict['args'] = spicemanip.main(botcom.dict['args'], '2+', 'list') + botcom.dict['args'] = spicemanip(botcom.dict['args'], '2+', 'list') quitmessage = "Received command from " + trigger.nick + " to update from Github and restart" SpiceBot.logs.log('SpiceBot_Update', quitmessage) diff --git a/sopel_modules/SpiceBot_Core_Commands/Search.py b/sopel_modules/SpiceBot_Core_Commands/Search.py index d8b86f3..15d83a4 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Search.py +++ b/sopel_modules/SpiceBot_Core_Commands/Search.py @@ -5,7 +5,7 @@ This is the SpiceBot search system. """ import sopel -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip import sopel_modules.SpiceBot as SpiceBot @@ -14,7 +14,7 @@ import sopel_modules.SpiceBot as SpiceBot @sopel.module.commands('search', 'find', 'google', 'lookup') def search_main(bot, trigger, botcom): - searchterm = spicemanip.main(botcom.dict['args'], 0) or None + searchterm = spicemanip(botcom.dict['args'], 0) or None if not searchterm: SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Not sure what you want me to look for.") return @@ -30,7 +30,7 @@ def search_main(bot, trigger, botcom): @sopel.module.commands("where", "whereis") def search_where(bot, trigger, botcom): - searchterm = spicemanip.main(botcom.dict['args'], 0) or None + searchterm = spicemanip(botcom.dict['args'], 0) or None if not searchterm: SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Not sure what you want me to look for.") return @@ -46,7 +46,7 @@ def search_where(bot, trigger, botcom): @sopel.module.commands("what", "whatis") def search_what(bot, trigger, botcom): - searchterm = spicemanip.main(botcom.dict['args'], 0) or None + searchterm = spicemanip(botcom.dict['args'], 0) or None if not searchterm: SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Not sure what you want me to look for.") return @@ -62,7 +62,7 @@ def search_what(bot, trigger, botcom): @sopel.module.commands("youtube", "video") def search_video(bot, trigger, botcom): - searchterm = spicemanip.main(botcom.dict['args'], 0) or None + searchterm = spicemanip(botcom.dict['args'], 0) or None if not searchterm: SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Not sure what you want me to look for.") return diff --git a/sopel_modules/SpiceBot_Core_Commands/Sherlock.py b/sopel_modules/SpiceBot_Core_Commands/Sherlock.py index 2310682..74a7791 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Sherlock.py +++ b/sopel_modules/SpiceBot_Core_Commands/Sherlock.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi # sopel imports import sopel.module -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip import sopel_modules.SpiceBot as SpiceBot @@ -15,15 +15,15 @@ def bot_command_sherlock(bot, trigger, botcom): netlist = list(SpiceBot.sherlock.dict.keys()) - username = spicemanip.main(botcom.dict["args"], 1) or trigger.nick - botcom.dict["args"] = spicemanip.main(botcom.dict["args"], "2+", 'list') + username = spicemanip(botcom.dict["args"], 1) or trigger.nick + botcom.dict["args"] = spicemanip(botcom.dict["args"], "2+", 'list') checklist = netlist checklistname = 'all' if SpiceBot.inlist(username, netlist): checklistname = SpiceBot.inlist_match(username, netlist) checklist = [checklistname] - username = spicemanip.main(botcom.dict["args"], 1) or trigger.nick + username = spicemanip(botcom.dict["args"], 1) or trigger.nick bot.osd("Checking username " + username + " in " + checklistname + " network.") @@ -41,9 +41,9 @@ def bot_command_sherlock(bot, trigger, botcom): if checklistname != 'all': bot.osd(["The username " + username + " is in " + checklist[0], SpiceBot.sherlock.dict.get(social_network).get("url").format(username)]) else: - bot.osd(["The username " + username + " is in the following:", spicemanip.main(inlist, "andlist")], trigger.nick, 'NOTICE') + bot.osd(["The username " + username + " is in the following:", spicemanip(inlist, "andlist")], trigger.nick, 'NOTICE') if len(notinlist): if checklistname != 'all': - bot.osd(["The username " + username + " is NOT in the following:", spicemanip.main(notinlist, "andlist")]) + bot.osd(["The username " + username + " is NOT in the following:", spicemanip(notinlist, "andlist")]) else: - bot.osd(["The username " + username + " is NOT in the following:", spicemanip.main(notinlist, "andlist")], trigger.nick, 'NOTICE') + bot.osd(["The username " + username + " is NOT in the following:", spicemanip(notinlist, "andlist")], trigger.nick, 'NOTICE') diff --git a/sopel_modules/SpiceBot_Core_Processing/Channels.py b/sopel_modules/SpiceBot_Core_Processing/Channels.py index 1fc0cf9..c82ec7e 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Channels.py +++ b/sopel_modules/SpiceBot_Core_Processing/Channels.py @@ -7,7 +7,7 @@ import sopel import time -import sopel_modules.spicemanip as spicemanip +from sopel_modules.spicemanip import spicemanip import sopel_modules.SpiceBot as SpiceBot @@ -86,7 +86,7 @@ def trigger_channel_list_recurring(bot, trigger): if "*" in newlist: newlist.remove("*") if len(newlist) and SpiceBot.config.SpiceBot_Channels.announcenew: - bot.osd(["The Following channel(s) are new:", spicemanip.main(newlist, 'andlist')], list(bot.channels.keys())) + bot.osd(["The Following channel(s) are new:", spicemanip(newlist, 'andlist')], list(bot.channels.keys())) SpiceBot.channels.join_all_channels(bot) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index edac8ee..395a307 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -336,351 +336,4 @@ class Spicemanip(): return False -main = Spicemanip() - - -# Hub -def core(inputs, outputtask, output_type='default'): - - mainoutputtask, suboutputtask = None, None - - # Input needs to be a list, but don't split a word into letters - if not inputs: - inputs = [] - if isinstance(inputs, collections.abc.KeysView): - inputs = list(inputs) - elif isinstance(inputs, dict): - inputs = list(inputs.keys()) - if not isinstance(inputs, list): - inputs = list(inputs.split(" ")) - inputs = [x for x in inputs if x and x not in ['', ' ']] - inputs = [inputspart.strip() for inputspart in inputs] - - # Create return - if outputtask == 'create': - return inputs - - # Make temparray to preserve original order - temparray = [] - for inputpart in inputs: - temparray.append(inputpart) - inputs = temparray - - # Convert outputtask to standard - if outputtask in [0, 'complete']: - outputtask = 'string' - elif outputtask == 'index': - mainoutputtask = inputs[1] - suboutputtask = inputs[2] - inputs = inputs[0] - elif str(outputtask).isdigit(): - mainoutputtask, outputtask = int(outputtask), 'number' - elif "^" in str(outputtask): - mainoutputtask = str(outputtask).split("^", 1)[0] - suboutputtask = str(outputtask).split("^", 1)[1] - outputtask = 'rangebetween' - if int(suboutputtask) < int(mainoutputtask): - mainoutputtask, suboutputtask = suboutputtask, mainoutputtask - elif str(outputtask).startswith("split_"): - mainoutputtask = str(outputtask).replace("split_", "") - outputtask = 'split' - elif str(outputtask).endswith(tuple(["!", "+", "-", "<", ">"])): - mainoutputtask = str(outputtask) - if str(outputtask).endswith("!"): - outputtask = 'exclude' - if str(outputtask).endswith("+"): - outputtask = 'incrange_plus' - if str(outputtask).endswith("-"): - outputtask = 'incrange_minus' - if str(outputtask).endswith(">"): - outputtask = 'excrange_plus' - if str(outputtask).endswith("<"): - outputtask = 'excrange_minus' - for r in (("!", ""), ("+", ""), ("-", ""), ("<", ""), (">", "")): - mainoutputtask = mainoutputtask.replace(*r) - if mainoutputtask == 'last': - mainoutputtask = len(inputs) - - if outputtask == 'string': - returnvalue = inputs - else: - returnvalue = eval( - 'spicemanip_' + outputtask + - '(inputs, outputtask, mainoutputtask, suboutputtask)') - - # default return if not specified - if output_type == 'default': - if outputtask in [ - 'string', 'number', 'rangebetween', 'exclude', 'random', - 'incrange_plus', 'incrange_minus', 'excrange_plus', - 'excrange_minus' - ]: - output_type = 'string' - elif outputtask in ['count']: - output_type = 'dict' - - # verify output is correct - if output_type == 'return': - return returnvalue - if output_type == 'string': - if isinstance(returnvalue, list): - returnvalue = ' '.join(returnvalue) - elif output_type in ['list', 'array']: - if not isinstance(returnvalue, list): - returnvalue = list(returnvalue.split(" ")) - returnvalue = [x for x in returnvalue if x and x not in ['', ' ']] - returnvalue = [inputspart.strip() for inputspart in returnvalue] - return returnvalue - - -# compare 2 lists, based on the location of an index item, passthrough needs to be [indexitem, arraytoindex, arraytocompare] -def spicemanip_index(indexitem, outputtask, arraytoindex, arraytocompare): - item = '' - for x, y in zip(arraytoindex, arraytocompare): - if x == indexitem: - item = y - return item - - -# split list by string -def spicemanip_split(inputs, outputtask, mainoutputtask, suboutputtask): - split_array = [] - restring = ' '.join(inputs) - if mainoutputtask not in inputs: - split_array = [restring] - else: - split_array = restring.split(mainoutputtask) - split_array = [x for x in split_array if x and x not in ['', ' ']] - split_array = [inputspart.strip() for inputspart in split_array] - if split_array == []: - split_array = [[]] - return split_array - - -# dedupe list -def spicemanip_dedupe(inputs, outputtask, mainoutputtask, suboutputtask): - newlist = [] - for inputspart in inputs: - if inputspart not in newlist: - newlist.append(inputspart) - return newlist - - -# Sort list -def spicemanip_sort(inputs, outputtask, mainoutputtask, suboutputtask): - return sorted(inputs) - - -# reverse sort list -def spicemanip_rsort(inputs, outputtask, mainoutputtask, suboutputtask): - return sorted(inputs)[::-1] - - -# count items in list, return dictionary -def spicemanip_count(inputs, outputtask, mainoutputtask, suboutputtask): - returndict = dict() - if not len(inputs): - return returndict - uniqueinputitems, uniquecount = [], [] - for inputspart in inputs: - if inputspart not in uniqueinputitems: - uniqueinputitems.append(inputspart) - for uniqueinputspart in uniqueinputitems: - count = 0 - for ele in inputs: - if (ele == uniqueinputspart): - count += 1 - uniquecount.append(count) - for inputsitem, unumber in zip(uniqueinputitems, uniquecount): - returndict[inputsitem] = unumber - return returndict - - -# random item from list -def spicemanip_random(inputs, outputtask, mainoutputtask, suboutputtask): - if not len(inputs): - return '' - randomselectlist = [] - for temppart in inputs: - randomselectlist.append(temppart) - while len(randomselectlist) > 1: - random.shuffle(randomselectlist) - randomselect = randomselectlist[random.randint( - 0, - len(randomselectlist) - 1)] - randomselectlist.remove(randomselect) - randomselect = randomselectlist[0] - return randomselect - - -# remove random item from list -def spicemanip_exrandom(inputs, outputtask, mainoutputtask, suboutputtask): - if not len(inputs): - return [] - randremove = spicemanip_random(inputs, outputtask, mainoutputtask, - suboutputtask) - inputs.remove(randremove) - return inputs - - -# Convert list into lowercase -def spicemanip_lower(inputs, outputtask, mainoutputtask, suboutputtask): - if not len(inputs): - return '' - return [inputspart.lower() for inputspart in inputs] - - -# Convert list to uppercase -def spicemanip_upper(inputs, outputtask, mainoutputtask, suboutputtask): - if not len(inputs): - return '' - return [inputspart.upper() for inputspart in inputs] - - -# Convert list to uppercase -def spicemanip_title(inputs, outputtask, mainoutputtask, suboutputtask): - if not len(inputs): - return '' - return [inputspart.title() for inputspart in inputs] - - -# Reverse List Order -def spicemanip_reverse(inputs, outputtask, mainoutputtask, suboutputtask): - if not len(inputs): - return [] - return inputs[::-1] - - -# comma seperated list -def spicemanip_list(inputs, outputtask, mainoutputtask, suboutputtask): - if not len(inputs): - return '' - return ', '.join(str(x) for x in inputs) - - -def spicemanip_list_nospace(inputs, outputtask, mainoutputtask, suboutputtask): - if not len(inputs): - return '' - return ','.join(str(x) for x in inputs) - - -# comma seperated list with and -def spicemanip_andlist(inputs, outputtask, mainoutputtask, suboutputtask): - if not len(inputs): - return '' - if len(inputs) < 2: - return ' '.join(inputs) - lastentry = str("and " + str(inputs[len(inputs) - 1])) - del inputs[-1] - inputs.append(lastentry) - if len(inputs) == 2: - return ' '.join(inputs) - return ', '.join(str(x) for x in inputs) - - -# comma seperated list with or -def spicemanip_orlist(inputs, outputtask, mainoutputtask, suboutputtask): - if not len(inputs): - return '' - if len(inputs) < 2: - return ' '.join(inputs) - lastentry = str("or " + str(inputs[len(inputs) - 1])) - del inputs[-1] - inputs.append(lastentry) - if len(inputs) == 2: - return ' '.join(inputs) - return ', '.join(str(x) for x in inputs) - - -# exclude number -def spicemanip_exclude(inputs, outputtask, mainoutputtask, suboutputtask): - if not len(inputs): - return '' - del inputs[int(mainoutputtask) - 1] - return ' '.join(inputs) - - -# Convert list to string -def spicemanip_string(inputs, outputtask, mainoutputtask, suboutputtask): - if not len(inputs): - return '' - return ' '.join(inputs) - - -# Get number item from list -def spicemanip_number(inputs, outputtask, mainoutputtask, suboutputtask): - if not len(inputs): - return '' - elif len(inputs) == 1: - return inputs[0] - elif int(mainoutputtask) > len(inputs) or int(mainoutputtask) < 0: - return '' - else: - return inputs[int(mainoutputtask) - 1] - - -# Get Last item from list -def spicemanip_last(inputs, outputtask, mainoutputtask, suboutputtask): - if not len(inputs): - return '' - return inputs[len(inputs) - 1] - - -# range between items in list -def spicemanip_rangebetween(inputs, outputtask, mainoutputtask, suboutputtask): - if not len(inputs): - return '' - if not str(mainoutputtask).isdigit() or not str(suboutputtask).isdigit(): - return '' - mainoutputtask, suboutputtask = int(mainoutputtask), int(suboutputtask) - if suboutputtask == mainoutputtask: - return spicemanip_number(inputs, outputtask, mainoutputtask, - suboutputtask) - if suboutputtask < mainoutputtask: - return [] - if mainoutputtask < 0: - mainoutputtask = 1 - if suboutputtask > len(inputs): - suboutputtask = len(inputs) - newlist = [] - for i in range(mainoutputtask, suboutputtask + 1): - newlist.append( - str(spicemanip_number(inputs, outputtask, i, suboutputtask))) - if newlist == []: - return '' - return ' '.join(newlist) - - -# Forward Range includes index number -def spicemanip_incrange_plus(inputs, outputtask, mainoutputtask, - suboutputtask): - if not len(inputs): - return '' - return spicemanip_rangebetween(inputs, outputtask, int(mainoutputtask), - len(inputs)) - - -# Reverse Range includes index number -def spicemanip_incrange_minus(inputs, outputtask, mainoutputtask, - suboutputtask): - if not len(inputs): - return '' - return spicemanip_rangebetween(inputs, outputtask, 1, int(mainoutputtask)) - - -# Forward Range excludes index number -def spicemanip_excrange_plus(inputs, outputtask, mainoutputtask, - suboutputtask): - if not len(inputs): - return '' - return spicemanip_rangebetween(inputs, outputtask, - int(mainoutputtask) + 1, len(inputs)) - - -# Reverse Range excludes index number -def spicemanip_excrange_minus(inputs, outputtask, mainoutputtask, - suboutputtask): - if not len(inputs): - return '' - return spicemanip_rangebetween(inputs, outputtask, 1, - int(mainoutputtask) - 1) +spicemanip = Spicemanip() From 3731f7ef7034be0ef34b247cea684ab8aed35922 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 07:58:29 -0400 Subject: [PATCH 61/96] test --- sopel_modules/spicemanip/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 395a307..9f2e5bc 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -21,7 +21,7 @@ class Spicemanip(): def __call__(self, inputs, task, output_type='default'): - if hasattr(self, task): + if hasattr(self, str(task)): raise Exception( str(self.task) + " is not a valid spicemanip function.") @@ -45,7 +45,7 @@ class Spicemanip(): def core_class_cleanup(self): for classitem in ["inputs", "task", "output_type"]: - if hasattr(self, classitem): + if hasattr(self, str(classitem)): del classitem def core_input_handler(self): @@ -118,7 +118,7 @@ class Spicemanip(): str(self.task).replace("<", "")) elif hasattr(self, - self.task) and not str(self.task).startswith("core_"): + str(self.task)) and not str(self.task).startswith("core_"): self.outputs = eval('self.' + str(self.task) + '(inputs)') else: From 252f6d8817f19955ec9edbaf5a5c254a93077122 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 08:12:03 -0400 Subject: [PATCH 62/96] test --- sopel_modules/spicemanip/__init__.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 9f2e5bc..172fa2b 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -37,17 +37,9 @@ class Spicemanip(): self.output_type = output_type self.core_output_handler() - # cleanup - self.core_class_cleanup() - # return value/s return self.outputs - def core_class_cleanup(self): - for classitem in ["inputs", "task", "output_type"]: - if hasattr(self, str(classitem)): - del classitem - def core_input_handler(self): # Input needs to be a list, but don't split a word into letters if not self.inputs: @@ -119,7 +111,7 @@ class Spicemanip(): elif hasattr(self, str(self.task)) and not str(self.task).startswith("core_"): - self.outputs = eval('self.' + str(self.task) + '(inputs)') + self.outputs = eval('self.' + str(self.task) + '(self.input_list)') else: raise Exception( From fc3411d610904e1cf4a161079f62629030012ad2 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 08:13:33 -0400 Subject: [PATCH 63/96] test --- sopel_modules/SpiceBot_Core_Commands/DictComs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index 825388b..45f7f81 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -35,7 +35,7 @@ def bot_dictcom_process(bot, trigger, botcom): # handling for special cases posscom = spicemanip(botcom.dict['args'], 1) - if posscom.lower() in [command.lower() for command in botcom.dict["dict"].keys()]: + if posscom.lower() in [command.lower() for command in list(botcom.dict["dict"].keys())]: for command in botcom.dict["dict"].keys(): if command.lower() == posscom.lower(): posscom = command From 6b6881e207d93fe2725605960c0901678c04a433 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 08:14:24 -0400 Subject: [PATCH 64/96] more --- sopel_modules/SpiceBot_Core_Commands/DictComs.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index 45f7f81..da9cd69 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -44,7 +44,7 @@ def bot_dictcom_process(bot, trigger, botcom): botcom.dict["dict"][botcom.dict["responsekey"]]["type"] = botcom.dict["dict"][botcom.dict["responsekey"]]["type"] botcom.dict["nonstockoptions"] = [] - for command in botcom.dict["dict"].keys(): + for command in list(botcom.dict["dict"].keys()): if command not in ["?default", "validcoms", "type", "hardcoded_channel_block"]: botcom.dict["nonstockoptions"].append(command) @@ -325,7 +325,7 @@ def bot_dictcom_reply_shared(bot, trigger, botcom): # display special options for this command if "$specialoptions" in rply: nonstockoptions = [] - for command in botcom.dict["dict"].keys(): + for command in list(botcom.dict["dict"].keys()): if command not in ["?default", "validcoms", "contributors", "author", "type", "filepath", "filename", "hardcoded_channel_block", "description", "exampleresponse", "example", "usage", "privs"]: nonstockoptions.append(command) nonstockoptions = spicemanip(nonstockoptions, "andlist") @@ -352,7 +352,7 @@ def bot_dictcom_gif(bot, trigger, botcom): queries = botcom.dict["dict"][botcom.dict["responsekey"]]["responses"] # which api's are we using to search - if "queryapi" in botcom.dict["dict"].keys(): + if "queryapi" in list(botcom.dict["dict"].keys()): searchapis = botcom.dict["dict"][botcom.dict["responsekey"]]["queryapi"] else: searchapis = list(SpiceBot.gif.valid_api.keys()) From 323486a8e92030c1bfb0d0e8e9faa3e694ba79e1 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 08:18:33 -0400 Subject: [PATCH 65/96] test --- sopel_modules/SpiceBot_Core_Commands/DictComs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index da9cd69..fa93f1d 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -34,6 +34,7 @@ def bot_dictcom_process(bot, trigger, botcom): botcom.dict["responsekey"] = "?default" # handling for special cases + bot.osd(str(botcom.dict["dict"])) posscom = spicemanip(botcom.dict['args'], 1) if posscom.lower() in [command.lower() for command in list(botcom.dict["dict"].keys())]: for command in botcom.dict["dict"].keys(): From 8b8c7d0b0fb35a199b3301b72b57e9f908614a9b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 08:21:54 -0400 Subject: [PATCH 66/96] test --- sopel_modules/SpiceBot_Core_Commands/DictComs.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index fa93f1d..556ee10 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -33,8 +33,10 @@ def bot_dictcom_process(bot, trigger, botcom): # use the default key, unless otherwise specified botcom.dict["responsekey"] = "?default" + for command in list(botcom.dict["dict"].keys()): + bot.osd(str(command)) + # handling for special cases - bot.osd(str(botcom.dict["dict"])) posscom = spicemanip(botcom.dict['args'], 1) if posscom.lower() in [command.lower() for command in list(botcom.dict["dict"].keys())]: for command in botcom.dict["dict"].keys(): From 30e02bf42ac6744ecb87e33acb1e0731507aa1aa Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 08:23:16 -0400 Subject: [PATCH 67/96] test --- sopel_modules/SpiceBot_Core_Commands/DictComs.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index 556ee10..8449f1c 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -33,12 +33,9 @@ def bot_dictcom_process(bot, trigger, botcom): # use the default key, unless otherwise specified botcom.dict["responsekey"] = "?default" - for command in list(botcom.dict["dict"].keys()): - bot.osd(str(command)) - # handling for special cases posscom = spicemanip(botcom.dict['args'], 1) - if posscom.lower() in [command.lower() for command in list(botcom.dict["dict"].keys())]: + if posscom.lower() in [str(command).lower() for command in list(botcom.dict["dict"].keys())]: for command in botcom.dict["dict"].keys(): if command.lower() == posscom.lower(): posscom = command From 149247aaa7169a02394c7d33a4d1bc02734951ce Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 08:26:21 -0400 Subject: [PATCH 68/96] test --- sopel_modules/spicemanip/__init__.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 172fa2b..00928ef 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -62,7 +62,7 @@ class Spicemanip(): if len(self.input_list): - if self.task in [0, 'complete']: + if self.task in ["0", 0, 'complete']: self.outputs = self.string(self.input_list) return @@ -70,10 +70,10 @@ class Spicemanip(): self.outputs = self.index( self.input_list[0], self.input_list[1], self.input_list[2]) - elif self.is_digit(self.task): + elif self.task.isdigit(): self.outputs = self.number(self.input_list, int(self.task)) - elif self.task in ['last']: + elif self.task in ['last', '-1', -1]: self.outputs = self.number(self.input_list, -1) elif "^" in str(self.task): @@ -320,12 +320,5 @@ class Spicemanip(): return ' '.join(inputs) return ', '.join(str(x) for x in inputs) - def is_digit(self, n): - try: - int(n) - return True - except ValueError: - return False - spicemanip = Spicemanip() From 7a6dc00522fb2d6039f5aff85518f565f92a6cee Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 08:27:15 -0400 Subject: [PATCH 69/96] test --- sopel_modules/spicemanip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 00928ef..6b99c23 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -70,7 +70,7 @@ class Spicemanip(): self.outputs = self.index( self.input_list[0], self.input_list[1], self.input_list[2]) - elif self.task.isdigit(): + elif str(self.task).isdigit(): self.outputs = self.number(self.input_list, int(self.task)) elif self.task in ['last', '-1', -1]: From 4d74e0a475308d68f9ea6f8c3797bee4f1e517b8 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 08:29:04 -0400 Subject: [PATCH 70/96] test --- sopel_modules/spicemanip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 6b99c23..9e3084f 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -62,7 +62,7 @@ class Spicemanip(): if len(self.input_list): - if self.task in ["0", 0, 'complete']: + if str(self.task) in ["0", 0, 'complete']: self.outputs = self.string(self.input_list) return From 930ed39320f8dc1d228bd4ad0ad96223b3069940 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 08:30:07 -0400 Subject: [PATCH 71/96] test --- sopel_modules/spicemanip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 9e3084f..4080a7c 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -73,7 +73,7 @@ class Spicemanip(): elif str(self.task).isdigit(): self.outputs = self.number(self.input_list, int(self.task)) - elif self.task in ['last', '-1', -1]: + elif str(self.task) in ['last', '-1', -1]: self.outputs = self.number(self.input_list, -1) elif "^" in str(self.task): From 8c0ff3ed759cf60dc3a3d20b3b01bc79bd3f7da2 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 08:36:38 -0400 Subject: [PATCH 72/96] test --- sopel_modules/spicemanip/__init__.py | 434 ++++++++++++++++++++++++--- 1 file changed, 391 insertions(+), 43 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 4080a7c..58acb7d 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -60,62 +60,63 @@ class Spicemanip(): self.outputs = self.input_list return - if len(self.input_list): + if not len(self.input_list): + self.outputs = [] + return - if str(self.task) in ["0", 0, 'complete']: - self.outputs = self.string(self.input_list) - return + if self.task in ["0", 0, 'complete']: + self.outputs = self.string(self.input_list) - elif self.task in ['index']: - self.outputs = self.index( - self.input_list[0], self.input_list[1], self.input_list[2]) + elif self.task in ['index']: + self.outputs = self.index( + self.input_list[0], self.input_list[1], self.input_list[2]) - elif str(self.task).isdigit(): - self.outputs = self.number(self.input_list, int(self.task)) + elif self.task in ['last', '-1', -1]: + self.outputs = self.number(self.input_list, -1) - elif str(self.task) in ['last', '-1', -1]: - self.outputs = self.number(self.input_list, -1) + elif str(self.task).isdigit(): + self.outputs = self.number(self.input_list, int(self.task)) - elif "^" in str(self.task): - range_start, range_end = str(self.task).split("^", 1).sort() - self.outputs = self.rangebetween(self.input_list, range_start, - range_end) + elif "^" in str(self.task): + range_start, range_end = str(self.task).split("^", 1).sort() + self.outputs = self.rangebetween(self.input_list, range_start, + range_end) - elif str(self.task).startswith("split_"): - self.outputs = self.split(self.input_list, - str(self.task).replace("split_", "")) + elif str(self.task).startswith("split_"): + self.outputs = self.split(self.input_list, + str(self.task).replace("split_", "")) - elif str(self.task).endswith("!"): - self.outputs = self.exclude(self.input_list, - str(self.task).replace("!", "")) + elif str(self.task).endswith("!"): + self.outputs = self.exclude(self.input_list, + str(self.task).replace("!", "")) - elif str(self.task).endswith("+"): - self.outputs = self.incrange_plus( - self.input_list, - str(self.task).replace("+", "")) + elif str(self.task).endswith("+"): + self.outputs = self.incrange_plus( + self.input_list, + str(self.task).replace("+", "")) - elif str(self.task).endswith("-"): - self.outputs = self.incrange_minus( - self.input_list, - str(self.task).replace("-", "")) + elif str(self.task).endswith("-"): + self.outputs = self.incrange_minus( + self.input_list, + str(self.task).replace("-", "")) - elif str(self.task).endswith(">"): - self.outputs = self.excrange_plus( - self.input_list, - str(self.task).replace(">", "")) + elif str(self.task).endswith(">"): + self.outputs = self.excrange_plus( + self.input_list, + str(self.task).replace(">", "")) - elif str(self.task).endswith("<"): - self.outputs = self.excrange_minus( - self.input_list, - str(self.task).replace("<", "")) + elif str(self.task).endswith("<"): + self.outputs = self.excrange_minus( + self.input_list, + str(self.task).replace("<", "")) - elif hasattr(self, - str(self.task)) and not str(self.task).startswith("core_"): - self.outputs = eval('self.' + str(self.task) + '(self.input_list)') + elif hasattr(self, + str(self.task)) and not str(self.task).startswith("core_"): + self.outputs = eval('self.' + str(self.task) + '(self.input_list)') - else: - raise Exception( - str(self.task) + " is not a valid spicemanip function.") + else: + raise Exception( + str(self.task) + " is not a valid spicemanip function.") def core_output_handler(self): @@ -322,3 +323,350 @@ class Spicemanip(): spicemanip = Spicemanip() + + +# Hub +def main(inputs, outputtask, output_type='default'): + + mainoutputtask, suboutputtask = None, None + + # Input needs to be a list, but don't split a word into letters + if not inputs: + inputs = [] + if isinstance(inputs, collections.abc.KeysView): + inputs = list(inputs) + elif isinstance(inputs, dict): + inputs = list(inputs.keys()) + if not isinstance(inputs, list): + inputs = list(inputs.split(" ")) + inputs = [x for x in inputs if x and x not in ['', ' ']] + inputs = [inputspart.strip() for inputspart in inputs] + + # Create return + if outputtask == 'create': + return inputs + + # Make temparray to preserve original order + temparray = [] + for inputpart in inputs: + temparray.append(inputpart) + inputs = temparray + + # Convert outputtask to standard + if outputtask in [0, 'complete']: + outputtask = 'string' + elif outputtask == 'index': + mainoutputtask = inputs[1] + suboutputtask = inputs[2] + inputs = inputs[0] + elif str(outputtask).isdigit(): + mainoutputtask, outputtask = int(outputtask), 'number' + elif "^" in str(outputtask): + mainoutputtask = str(outputtask).split("^", 1)[0] + suboutputtask = str(outputtask).split("^", 1)[1] + outputtask = 'rangebetween' + if int(suboutputtask) < int(mainoutputtask): + mainoutputtask, suboutputtask = suboutputtask, mainoutputtask + elif str(outputtask).startswith("split_"): + mainoutputtask = str(outputtask).replace("split_", "") + outputtask = 'split' + elif str(outputtask).endswith(tuple(["!", "+", "-", "<", ">"])): + mainoutputtask = str(outputtask) + if str(outputtask).endswith("!"): + outputtask = 'exclude' + if str(outputtask).endswith("+"): + outputtask = 'incrange_plus' + if str(outputtask).endswith("-"): + outputtask = 'incrange_minus' + if str(outputtask).endswith(">"): + outputtask = 'excrange_plus' + if str(outputtask).endswith("<"): + outputtask = 'excrange_minus' + for r in (("!", ""), ("+", ""), ("-", ""), ("<", ""), (">", "")): + mainoutputtask = mainoutputtask.replace(*r) + if mainoutputtask == 'last': + mainoutputtask = len(inputs) + + if outputtask == 'string': + returnvalue = inputs + else: + returnvalue = eval( + 'spicemanip_' + outputtask + + '(inputs, outputtask, mainoutputtask, suboutputtask)') + + # default return if not specified + if output_type == 'default': + if outputtask in [ + 'string', 'number', 'rangebetween', 'exclude', 'random', + 'incrange_plus', 'incrange_minus', 'excrange_plus', + 'excrange_minus' + ]: + output_type = 'string' + elif outputtask in ['count']: + output_type = 'dict' + + # verify output is correct + if output_type == 'return': + return returnvalue + if output_type == 'string': + if isinstance(returnvalue, list): + returnvalue = ' '.join(returnvalue) + elif output_type in ['list', 'array']: + if not isinstance(returnvalue, list): + returnvalue = list(returnvalue.split(" ")) + returnvalue = [x for x in returnvalue if x and x not in ['', ' ']] + returnvalue = [inputspart.strip() for inputspart in returnvalue] + return returnvalue + + +# compare 2 lists, based on the location of an index item, passthrough needs to be [indexitem, arraytoindex, arraytocompare] +def spicemanip_index(indexitem, outputtask, arraytoindex, arraytocompare): + item = '' + for x, y in zip(arraytoindex, arraytocompare): + if x == indexitem: + item = y + return item + + +# split list by string +def spicemanip_split(inputs, outputtask, mainoutputtask, suboutputtask): + split_array = [] + restring = ' '.join(inputs) + if mainoutputtask not in inputs: + split_array = [restring] + else: + split_array = restring.split(mainoutputtask) + split_array = [x for x in split_array if x and x not in ['', ' ']] + split_array = [inputspart.strip() for inputspart in split_array] + if split_array == []: + split_array = [[]] + return split_array + + +# dedupe list +def spicemanip_dedupe(inputs, outputtask, mainoutputtask, suboutputtask): + newlist = [] + for inputspart in inputs: + if inputspart not in newlist: + newlist.append(inputspart) + return newlist + + +# Sort list +def spicemanip_sort(inputs, outputtask, mainoutputtask, suboutputtask): + return sorted(inputs) + + +# reverse sort list +def spicemanip_rsort(inputs, outputtask, mainoutputtask, suboutputtask): + return sorted(inputs)[::-1] + + +# count items in list, return dictionary +def spicemanip_count(inputs, outputtask, mainoutputtask, suboutputtask): + returndict = dict() + if not len(inputs): + return returndict + uniqueinputitems, uniquecount = [], [] + for inputspart in inputs: + if inputspart not in uniqueinputitems: + uniqueinputitems.append(inputspart) + for uniqueinputspart in uniqueinputitems: + count = 0 + for ele in inputs: + if (ele == uniqueinputspart): + count += 1 + uniquecount.append(count) + for inputsitem, unumber in zip(uniqueinputitems, uniquecount): + returndict[inputsitem] = unumber + return returndict + + +# random item from list +def spicemanip_random(inputs, outputtask, mainoutputtask, suboutputtask): + if not len(inputs): + return '' + randomselectlist = [] + for temppart in inputs: + randomselectlist.append(temppart) + while len(randomselectlist) > 1: + random.shuffle(randomselectlist) + randomselect = randomselectlist[random.randint( + 0, + len(randomselectlist) - 1)] + randomselectlist.remove(randomselect) + randomselect = randomselectlist[0] + return randomselect + + +# remove random item from list +def spicemanip_exrandom(inputs, outputtask, mainoutputtask, suboutputtask): + if not len(inputs): + return [] + randremove = spicemanip_random(inputs, outputtask, mainoutputtask, + suboutputtask) + inputs.remove(randremove) + return inputs + + +# Convert list into lowercase +def spicemanip_lower(inputs, outputtask, mainoutputtask, suboutputtask): + if not len(inputs): + return '' + return [inputspart.lower() for inputspart in inputs] + + +# Convert list to uppercase +def spicemanip_upper(inputs, outputtask, mainoutputtask, suboutputtask): + if not len(inputs): + return '' + return [inputspart.upper() for inputspart in inputs] + + +# Convert list to uppercase +def spicemanip_title(inputs, outputtask, mainoutputtask, suboutputtask): + if not len(inputs): + return '' + return [inputspart.title() for inputspart in inputs] + + +# Reverse List Order +def spicemanip_reverse(inputs, outputtask, mainoutputtask, suboutputtask): + if not len(inputs): + return [] + return inputs[::-1] + + +# comma seperated list +def spicemanip_list(inputs, outputtask, mainoutputtask, suboutputtask): + if not len(inputs): + return '' + return ', '.join(str(x) for x in inputs) + + +def spicemanip_list_nospace(inputs, outputtask, mainoutputtask, suboutputtask): + if not len(inputs): + return '' + return ','.join(str(x) for x in inputs) + + +# comma seperated list with and +def spicemanip_andlist(inputs, outputtask, mainoutputtask, suboutputtask): + if not len(inputs): + return '' + if len(inputs) < 2: + return ' '.join(inputs) + lastentry = str("and " + str(inputs[len(inputs) - 1])) + del inputs[-1] + inputs.append(lastentry) + if len(inputs) == 2: + return ' '.join(inputs) + return ', '.join(str(x) for x in inputs) + + +# comma seperated list with or +def spicemanip_orlist(inputs, outputtask, mainoutputtask, suboutputtask): + if not len(inputs): + return '' + if len(inputs) < 2: + return ' '.join(inputs) + lastentry = str("or " + str(inputs[len(inputs) - 1])) + del inputs[-1] + inputs.append(lastentry) + if len(inputs) == 2: + return ' '.join(inputs) + return ', '.join(str(x) for x in inputs) + + +# exclude number +def spicemanip_exclude(inputs, outputtask, mainoutputtask, suboutputtask): + if not len(inputs): + return '' + del inputs[int(mainoutputtask) - 1] + return ' '.join(inputs) + + +# Convert list to string +def spicemanip_string(inputs, outputtask, mainoutputtask, suboutputtask): + if not len(inputs): + return '' + return ' '.join(inputs) + + +# Get number item from list +def spicemanip_number(inputs, outputtask, mainoutputtask, suboutputtask): + if not len(inputs): + return '' + elif len(inputs) == 1: + return inputs[0] + elif int(mainoutputtask) > len(inputs) or int(mainoutputtask) < 0: + return '' + else: + return inputs[int(mainoutputtask) - 1] + + +# Get Last item from list +def spicemanip_last(inputs, outputtask, mainoutputtask, suboutputtask): + if not len(inputs): + return '' + return inputs[len(inputs) - 1] + + +# range between items in list +def spicemanip_rangebetween(inputs, outputtask, mainoutputtask, suboutputtask): + if not len(inputs): + return '' + if not str(mainoutputtask).isdigit() or not str(suboutputtask).isdigit(): + return '' + mainoutputtask, suboutputtask = int(mainoutputtask), int(suboutputtask) + if suboutputtask == mainoutputtask: + return spicemanip_number(inputs, outputtask, mainoutputtask, + suboutputtask) + if suboutputtask < mainoutputtask: + return [] + if mainoutputtask < 0: + mainoutputtask = 1 + if suboutputtask > len(inputs): + suboutputtask = len(inputs) + newlist = [] + for i in range(mainoutputtask, suboutputtask + 1): + newlist.append( + str(spicemanip_number(inputs, outputtask, i, suboutputtask))) + if newlist == []: + return '' + return ' '.join(newlist) + + +# Forward Range includes index number +def spicemanip_incrange_plus(inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + return spicemanip_rangebetween(inputs, outputtask, int(mainoutputtask), + len(inputs)) + + +# Reverse Range includes index number +def spicemanip_incrange_minus(inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + return spicemanip_rangebetween(inputs, outputtask, 1, int(mainoutputtask)) + + +# Forward Range excludes index number +def spicemanip_excrange_plus(inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + return spicemanip_rangebetween(inputs, outputtask, + int(mainoutputtask) + 1, len(inputs)) + + +# Reverse Range excludes index number +def spicemanip_excrange_minus(inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + return spicemanip_rangebetween(inputs, outputtask, 1, + int(mainoutputtask) - 1) From 3159c42ed3434d725c79bd690da8a43a7f074c3b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 08:37:55 -0400 Subject: [PATCH 73/96] test --- sopel_modules/spicemanip/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 58acb7d..252a9fd 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -322,11 +322,11 @@ class Spicemanip(): return ', '.join(str(x) for x in inputs) -spicemanip = Spicemanip() +spicemanip_new = Spicemanip() # Hub -def main(inputs, outputtask, output_type='default'): +def spicemanip(inputs, outputtask, output_type='default'): mainoutputtask, suboutputtask = None, None From ba03adf56aabb60686595915815b3778321297e7 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 08:51:02 -0400 Subject: [PATCH 74/96] test --- sopel_modules/spicemanip/__init__.py | 39 ++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 252a9fd..c9a82c6 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -21,10 +21,6 @@ class Spicemanip(): def __call__(self, inputs, task, output_type='default'): - if hasattr(self, str(task)): - raise Exception( - str(self.task) + " is not a valid spicemanip function.") - # convert input into list self.inputs = inputs self.core_input_handler() @@ -65,6 +61,7 @@ class Spicemanip(): return if self.task in ["0", 0, 'complete']: + self.task = "string" self.outputs = self.string(self.input_list) elif self.task in ['index']: @@ -72,40 +69,49 @@ class Spicemanip(): self.input_list[0], self.input_list[1], self.input_list[2]) elif self.task in ['last', '-1', -1]: - self.outputs = self.number(self.input_list, -1) + self.task = "last" + self.outputs = self.last(self.input_list) - elif str(self.task).isdigit(): + elif self.is_digit(self.task): + self.task = "number" self.outputs = self.number(self.input_list, int(self.task)) elif "^" in str(self.task): + self.task = "rangebetween" range_start, range_end = str(self.task).split("^", 1).sort() self.outputs = self.rangebetween(self.input_list, range_start, range_end) elif str(self.task).startswith("split_"): + self.task = "split" self.outputs = self.split(self.input_list, str(self.task).replace("split_", "")) elif str(self.task).endswith("!"): + self.task = "exclude" self.outputs = self.exclude(self.input_list, str(self.task).replace("!", "")) elif str(self.task).endswith("+"): + self.task = "incrange_plus" self.outputs = self.incrange_plus( self.input_list, str(self.task).replace("+", "")) elif str(self.task).endswith("-"): + self.task = "incrange_minus" self.outputs = self.incrange_minus( self.input_list, str(self.task).replace("-", "")) elif str(self.task).endswith(">"): + self.task = "excrange_plus" self.outputs = self.excrange_plus( self.input_list, str(self.task).replace(">", "")) elif str(self.task).endswith("<"): + self.task = "excrange_minus" self.outputs = self.excrange_minus( self.input_list, str(self.task).replace("<", "")) @@ -150,6 +156,13 @@ class Spicemanip(): self.outputs = self.list(self.outputs) return + # Convert list to string + def complete(self, inputs): + return self.string(inputs) + + def last(self, inputs): + return self.number(inputs, -1) + # Convert list to string def string(self, inputs): if not isinstance(inputs, list): @@ -158,6 +171,9 @@ class Spicemanip(): return '' return ' '.join(inputs) + def create(self, inputs): + return self.list(inputs) + # Convert inputs to list def list(self, inputs): if isinstance(inputs, list): @@ -321,12 +337,19 @@ class Spicemanip(): return ' '.join(inputs) return ', '.join(str(x) for x in inputs) + def is_digit(self, n): + try: + int(n) + return True + except ValueError: + return False -spicemanip_new = Spicemanip() + +spicemanip = Spicemanip() # Hub -def spicemanip(inputs, outputtask, output_type='default'): +def spicemanip_old(inputs, outputtask, output_type='default'): mainoutputtask, suboutputtask = None, None From a04118fbac9ae77649d353801286b35d50a61a30 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 09:07:06 -0400 Subject: [PATCH 75/96] test --- sopel_modules/spicemanip/__init__.py | 31 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index c9a82c6..0419c38 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -78,43 +78,44 @@ class Spicemanip(): elif "^" in str(self.task): self.task = "rangebetween" - range_start, range_end = str(self.task).split("^", 1).sort() - self.outputs = self.rangebetween(self.input_list, range_start, - range_end) + range_nums = str(self.task).split("^", 1).sort() + range_start, range_end = range_nums[0], range_nums[1] + self.outputs = self.rangebetween(self.input_list, int(range_start), + int(range_end)) elif str(self.task).startswith("split_"): self.task = "split" - self.outputs = self.split(self.input_list, - str(self.task).replace("split_", "")) + split_mark = str(self.task).replace("split_", "") + self.outputs = self.split(self.input_list, split_mark) elif str(self.task).endswith("!"): self.task = "exclude" - self.outputs = self.exclude(self.input_list, - str(self.task).replace("!", "")) + exclude_num = str(self.task).replace("!", "") + self.outputs = self.exclude(self.input_list, int(exclude_num)) elif str(self.task).endswith("+"): self.task = "incrange_plus" + range_start = str(self.task).replace("+", "") self.outputs = self.incrange_plus( - self.input_list, - str(self.task).replace("+", "")) + self.input_list, int(range_start)) elif str(self.task).endswith("-"): self.task = "incrange_minus" + range_end = str(self.task).replace("-", "") self.outputs = self.incrange_minus( - self.input_list, - str(self.task).replace("-", "")) + self.input_list, int(range_end)) elif str(self.task).endswith(">"): self.task = "excrange_plus" + range_start = str(self.task).replace(">", "") self.outputs = self.excrange_plus( - self.input_list, - str(self.task).replace(">", "")) + self.input_list, int(range_start)) elif str(self.task).endswith("<"): self.task = "excrange_minus" + range_end = str(self.task).replace("<", "") self.outputs = self.excrange_minus( - self.input_list, - str(self.task).replace("<", "")) + self.input_list, int(range_end)) elif hasattr(self, str(self.task)) and not str(self.task).startswith("core_"): From 23b1cc1765320d7193e2e0d7d77d02b21b842f8e Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 09:22:51 -0400 Subject: [PATCH 76/96] test --- sopel_modules/spicemanip/__init__.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 0419c38..8554d75 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -61,7 +61,6 @@ class Spicemanip(): return if self.task in ["0", 0, 'complete']: - self.task = "string" self.outputs = self.string(self.input_list) elif self.task in ['index']: @@ -69,50 +68,41 @@ class Spicemanip(): self.input_list[0], self.input_list[1], self.input_list[2]) elif self.task in ['last', '-1', -1]: - self.task = "last" self.outputs = self.last(self.input_list) elif self.is_digit(self.task): - self.task = "number" self.outputs = self.number(self.input_list, int(self.task)) elif "^" in str(self.task): - self.task = "rangebetween" range_nums = str(self.task).split("^", 1).sort() range_start, range_end = range_nums[0], range_nums[1] self.outputs = self.rangebetween(self.input_list, int(range_start), int(range_end)) elif str(self.task).startswith("split_"): - self.task = "split" split_mark = str(self.task).replace("split_", "") self.outputs = self.split(self.input_list, split_mark) elif str(self.task).endswith("!"): - self.task = "exclude" exclude_num = str(self.task).replace("!", "") self.outputs = self.exclude(self.input_list, int(exclude_num)) elif str(self.task).endswith("+"): - self.task = "incrange_plus" range_start = str(self.task).replace("+", "") self.outputs = self.incrange_plus( self.input_list, int(range_start)) elif str(self.task).endswith("-"): - self.task = "incrange_minus" range_end = str(self.task).replace("-", "") self.outputs = self.incrange_minus( self.input_list, int(range_end)) elif str(self.task).endswith(">"): - self.task = "excrange_plus" range_start = str(self.task).replace(">", "") self.outputs = self.excrange_plus( self.input_list, int(range_start)) elif str(self.task).endswith("<"): - self.task = "excrange_minus" range_end = str(self.task).replace("<", "") self.outputs = self.excrange_minus( self.input_list, int(range_end)) From 7833a022c497013343580d1a336c4f3c16f5bf86 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 09:39:38 -0400 Subject: [PATCH 77/96] test --- sopel_modules/SpiceBot_Core_Commands/DictComs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index 8449f1c..c63729f 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -35,6 +35,7 @@ def bot_dictcom_process(bot, trigger, botcom): # handling for special cases posscom = spicemanip(botcom.dict['args'], 1) + bot.say(str(posscom)) if posscom.lower() in [str(command).lower() for command in list(botcom.dict["dict"].keys())]: for command in botcom.dict["dict"].keys(): if command.lower() == posscom.lower(): From 3e6609698760be7eca8c6a66b5180e3e0baedd27 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 09:44:17 -0400 Subject: [PATCH 78/96] test --- sopel_modules/SpiceBot_Core_Commands/DictComs.py | 2 +- sopel_modules/spicemanip/__init__.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index c63729f..e4e69ff 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -36,7 +36,7 @@ def bot_dictcom_process(bot, trigger, botcom): # handling for special cases posscom = spicemanip(botcom.dict['args'], 1) bot.say(str(posscom)) - if posscom.lower() in [str(command).lower() for command in list(botcom.dict["dict"].keys())]: + if posscom.lower() in [command.lower() for command in list(botcom.dict["dict"].keys())]: for command in botcom.dict["dict"].keys(): if command.lower() == posscom.lower(): posscom = command diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 8554d75..b83b313 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -38,16 +38,21 @@ class Spicemanip(): def core_input_handler(self): # Input needs to be a list, but don't split a word into letters - if not self.inputs: + if not self.inputs or not len(self.inputs): self.input_list = [] + return if isinstance(self.inputs, list): self.input_list = list(self.inputs) + return if isinstance(self.inputs, collections.abc.KeysView): self.input_list = list(self.inputs) + return if isinstance(self.inputs, dict): self.input_list = list(self.inputs.keys()) + return if not isinstance(self.inputs, list): self.input_list = list(self.inputs.split(" ")) + return def core_task_handler(self): @@ -127,7 +132,8 @@ class Spicemanip(): 'incrange_minus': "string", 'excrange_plus': "string", 'excrange_minus': "string", - 'count': "dict" + 'count': "dict", + "create": "list" } # default return if not specified From 178582e218e1d06690dcc78102f7d37473187c85 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 09:53:50 -0400 Subject: [PATCH 79/96] test --- sopel_modules/spicemanip/__init__.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index b83b313..6d2beba 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -67,50 +67,61 @@ class Spicemanip(): if self.task in ["0", 0, 'complete']: self.outputs = self.string(self.input_list) + self.task = "complete" elif self.task in ['index']: self.outputs = self.index( self.input_list[0], self.input_list[1], self.input_list[2]) + self.task = "index" elif self.task in ['last', '-1', -1]: self.outputs = self.last(self.input_list) + self.task = "last" elif self.is_digit(self.task): self.outputs = self.number(self.input_list, int(self.task)) + self.task = "number" elif "^" in str(self.task): range_nums = str(self.task).split("^", 1).sort() range_start, range_end = range_nums[0], range_nums[1] self.outputs = self.rangebetween(self.input_list, int(range_start), int(range_end)) + self.task = "rangebetween" elif str(self.task).startswith("split_"): split_mark = str(self.task).replace("split_", "") self.outputs = self.split(self.input_list, split_mark) + self.task = "split" elif str(self.task).endswith("!"): exclude_num = str(self.task).replace("!", "") self.outputs = self.exclude(self.input_list, int(exclude_num)) + self.task = "exclude" elif str(self.task).endswith("+"): range_start = str(self.task).replace("+", "") self.outputs = self.incrange_plus( self.input_list, int(range_start)) + self.task = "incrange_plus" elif str(self.task).endswith("-"): range_end = str(self.task).replace("-", "") self.outputs = self.incrange_minus( self.input_list, int(range_end)) + self.task = "incrange_minus" elif str(self.task).endswith(">"): range_start = str(self.task).replace(">", "") self.outputs = self.excrange_plus( self.input_list, int(range_start)) + self.task = "excrange_plus" elif str(self.task).endswith("<"): range_end = str(self.task).replace("<", "") self.outputs = self.excrange_minus( self.input_list, int(range_end)) + self.task = "excrange_minus" elif hasattr(self, str(self.task)) and not str(self.task).startswith("core_"): @@ -133,7 +144,8 @@ class Spicemanip(): 'excrange_plus': "string", 'excrange_minus': "string", 'count': "dict", - "create": "list" + "create": "list", + 'complete': "string", } # default return if not specified From 4c2b86488289b68f5fa3b6b6b1725dbd4add441e Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 09:57:27 -0400 Subject: [PATCH 80/96] test --- sopel_modules/spicemanip/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 6d2beba..f535338 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -42,7 +42,7 @@ class Spicemanip(): self.input_list = [] return if isinstance(self.inputs, list): - self.input_list = list(self.inputs) + self.input_list = self.inputs.copy() return if isinstance(self.inputs, collections.abc.KeysView): self.input_list = list(self.inputs) @@ -51,7 +51,7 @@ class Spicemanip(): self.input_list = list(self.inputs.keys()) return if not isinstance(self.inputs, list): - self.input_list = list(self.inputs.split(" ")) + self.input_list = self.inputs.copy().split(" ") return def core_task_handler(self): From c138324570808a51b14c0e9b3ee1f505ee973702 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 09:58:16 -0400 Subject: [PATCH 81/96] test --- sopel_modules/spicemanip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index f535338..8e7e869 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -51,7 +51,7 @@ class Spicemanip(): self.input_list = list(self.inputs.keys()) return if not isinstance(self.inputs, list): - self.input_list = self.inputs.copy().split(" ") + self.input_list = self.inputs.split(" ") return def core_task_handler(self): From 0e14406ee099098271fc69e44f5ba2411484b98c Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 10:03:51 -0400 Subject: [PATCH 82/96] test --- sopel_modules/spicemanip/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 8e7e869..0c47ccf 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -354,11 +354,11 @@ class Spicemanip(): return False -spicemanip = Spicemanip() +spicemanip_new = Spicemanip() # Hub -def spicemanip_old(inputs, outputtask, output_type='default'): +def spicemanip(inputs, outputtask, output_type='default'): mainoutputtask, suboutputtask = None, None From 62aefe01ae40534320c9becf3bfa7ef635d8cf05 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 12:24:26 -0400 Subject: [PATCH 83/96] test orig + class --- sopel_modules/spicemanip/__init__.py | 412 +++++++++++++++++++++++++-- 1 file changed, 383 insertions(+), 29 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 0c47ccf..fd4abbf 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -9,13 +9,12 @@ __version__ = '0.1.8' import random import collections - # TODO 'this*that' or '1*that' replace either all strings matching, or an index value # TODO reverse sort z.sort(reverse = True) # list.extend adds lists to eachother - -class Spicemanip(): +""" +class Spicemanip_new(): def __init__(self): pass @@ -70,8 +69,8 @@ class Spicemanip(): self.task = "complete" elif self.task in ['index']: - self.outputs = self.index( - self.input_list[0], self.input_list[1], self.input_list[2]) + self.outputs = self.index(self.input_list[0], self.input_list[1], + self.input_list[2]) self.task = "index" elif self.task in ['last', '-1', -1]: @@ -101,30 +100,28 @@ class Spicemanip(): elif str(self.task).endswith("+"): range_start = str(self.task).replace("+", "") - self.outputs = self.incrange_plus( - self.input_list, int(range_start)) + self.outputs = self.incrange_plus(self.input_list, + int(range_start)) self.task = "incrange_plus" elif str(self.task).endswith("-"): range_end = str(self.task).replace("-", "") - self.outputs = self.incrange_minus( - self.input_list, int(range_end)) + self.outputs = self.incrange_minus(self.input_list, int(range_end)) self.task = "incrange_minus" elif str(self.task).endswith(">"): range_start = str(self.task).replace(">", "") - self.outputs = self.excrange_plus( - self.input_list, int(range_start)) + self.outputs = self.excrange_plus(self.input_list, + int(range_start)) self.task = "excrange_plus" elif str(self.task).endswith("<"): range_end = str(self.task).replace("<", "") - self.outputs = self.excrange_minus( - self.input_list, int(range_end)) + self.outputs = self.excrange_minus(self.input_list, int(range_end)) self.task = "excrange_minus" - elif hasattr(self, - str(self.task)) and not str(self.task).startswith("core_"): + elif hasattr(self, str( + self.task)) and not str(self.task).startswith("core_"): self.outputs = eval('self.' + str(self.task) + '(self.input_list)') else: @@ -134,19 +131,19 @@ class Spicemanip(): def core_output_handler(self): core_defaults = { - 'string': "string", - 'number': "string", - 'rangebetween': "string", - 'exclude': "string", - 'random': "string", - 'incrange_plus': "string", - 'incrange_minus': "string", - 'excrange_plus': "string", - 'excrange_minus': "string", - 'count': "dict", - "create": "list", - 'complete': "string", - } + 'string': "string", + 'number': "string", + 'rangebetween': "string", + 'exclude': "string", + 'random': "string", + 'incrange_plus': "string", + 'incrange_minus': "string", + 'excrange_plus': "string", + 'excrange_minus': "string", + 'count': "dict", + "create": "list", + 'complete': "string", + } # default return if not specified if self.output_type == 'default': @@ -352,11 +349,367 @@ class Spicemanip(): return True except ValueError: return False +""" -spicemanip_new = Spicemanip() +class Spicemanip(): + + def __init__(self): + pass + + def __call__(self, inputs, outputtask, output_type='default'): + mainoutputtask, suboutputtask = None, None + + # Input needs to be a list, but don't split a word into letters + if not inputs: + inputs = [] + if isinstance(inputs, collections.abc.KeysView): + inputs = list(inputs) + elif isinstance(inputs, dict): + inputs = list(inputs.keys()) + if not isinstance(inputs, list): + inputs = list(inputs.split(" ")) + inputs = [x for x in inputs if x and x not in ['', ' ']] + inputs = [inputspart.strip() for inputspart in inputs] + + # Create return + if outputtask == 'create': + return inputs + + # Make temparray to preserve original order + temparray = [] + for inputpart in inputs: + temparray.append(inputpart) + inputs = temparray + + # Convert outputtask to standard + if outputtask in [0, 'complete']: + outputtask = 'string' + elif outputtask == 'index': + mainoutputtask = inputs[1] + suboutputtask = inputs[2] + inputs = inputs[0] + elif str(outputtask).isdigit(): + mainoutputtask, outputtask = int(outputtask), 'number' + elif "^" in str(outputtask): + mainoutputtask = str(outputtask).split("^", 1)[0] + suboutputtask = str(outputtask).split("^", 1)[1] + outputtask = 'rangebetween' + if int(suboutputtask) < int(mainoutputtask): + mainoutputtask, suboutputtask = suboutputtask, mainoutputtask + elif str(outputtask).startswith("split_"): + mainoutputtask = str(outputtask).replace("split_", "") + outputtask = 'split' + elif str(outputtask).endswith(tuple(["!", "+", "-", "<", ">"])): + mainoutputtask = str(outputtask) + if str(outputtask).endswith("!"): + outputtask = 'exclude' + if str(outputtask).endswith("+"): + outputtask = 'incrange_plus' + if str(outputtask).endswith("-"): + outputtask = 'incrange_minus' + if str(outputtask).endswith(">"): + outputtask = 'excrange_plus' + if str(outputtask).endswith("<"): + outputtask = 'excrange_minus' + for r in (("!", ""), ("+", ""), ("-", ""), ("<", ""), (">", "")): + mainoutputtask = mainoutputtask.replace(*r) + if mainoutputtask == 'last': + mainoutputtask = len(inputs) + + if outputtask == 'string': + returnvalue = inputs + else: + returnvalue = eval( + 'spicemanip_' + outputtask + + '(inputs, outputtask, mainoutputtask, suboutputtask)') + + # default return if not specified + if output_type == 'default': + if outputtask in [ + 'string', 'number', 'rangebetween', 'exclude', 'random', + 'incrange_plus', 'incrange_minus', 'excrange_plus', + 'excrange_minus' + ]: + output_type = 'string' + elif outputtask in ['count']: + output_type = 'dict' + + # verify output is correct + if output_type == 'return': + return returnvalue + if output_type == 'string': + if isinstance(returnvalue, list): + returnvalue = ' '.join(returnvalue) + elif output_type in ['list', 'array']: + if not isinstance(returnvalue, list): + returnvalue = list(returnvalue.split(" ")) + returnvalue = [ + x for x in returnvalue if x and x not in ['', ' '] + ] + returnvalue = [ + inputspart.strip() for inputspart in returnvalue + ] + return returnvalue + + # compare 2 lists, based on the location of an index item, passthrough needs to be [indexitem, arraytoindex, arraytocompare] + def spicemanip_index(self, indexitem, outputtask, arraytoindex, + arraytocompare): + item = '' + for x, y in zip(arraytoindex, arraytocompare): + if x == indexitem: + item = y + return item + + # split list by string + def spicemanip_split(self, inputs, outputtask, mainoutputtask, + suboutputtask): + split_array = [] + restring = ' '.join(inputs) + if mainoutputtask not in inputs: + split_array = [restring] + else: + split_array = restring.split(mainoutputtask) + split_array = [x for x in split_array if x and x not in ['', ' ']] + split_array = [inputspart.strip() for inputspart in split_array] + if split_array == []: + split_array = [[]] + return split_array + + # dedupe list + def spicemanip_dedupe(self, inputs, outputtask, mainoutputtask, + suboutputtask): + newlist = [] + for inputspart in inputs: + if inputspart not in newlist: + newlist.append(inputspart) + return newlist + + # Sort list + def spicemanip_sort(self, inputs, outputtask, mainoutputtask, + suboutputtask): + return sorted(inputs) + + # reverse sort list + def spicemanip_rsort(self, inputs, outputtask, mainoutputtask, + suboutputtask): + return sorted(inputs)[::-1] + + # count items in list, return dictionary + def spicemanip_count(self, inputs, outputtask, mainoutputtask, + suboutputtask): + returndict = dict() + if not len(inputs): + return returndict + uniqueinputitems, uniquecount = [], [] + for inputspart in inputs: + if inputspart not in uniqueinputitems: + uniqueinputitems.append(inputspart) + for uniqueinputspart in uniqueinputitems: + count = 0 + for ele in inputs: + if (ele == uniqueinputspart): + count += 1 + uniquecount.append(count) + for inputsitem, unumber in zip(uniqueinputitems, uniquecount): + returndict[inputsitem] = unumber + return returndict + + # random item from list + def spicemanip_random(self, inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + randomselectlist = [] + for temppart in inputs: + randomselectlist.append(temppart) + while len(randomselectlist) > 1: + random.shuffle(randomselectlist) + randomselect = randomselectlist[random.randint( + 0, + len(randomselectlist) - 1)] + randomselectlist.remove(randomselect) + randomselect = randomselectlist[0] + return randomselect + + # remove random item from list + def spicemanip_exrandom(self, inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return [] + randremove = self.spicemanip_random(inputs, outputtask, mainoutputtask, + suboutputtask) + inputs.remove(randremove) + return inputs + + # Convert list into lowercase + def spicemanip_lower(self, inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + return [inputspart.lower() for inputspart in inputs] + + # Convert list to uppercase + def spicemanip_upper(self, inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + return [inputspart.upper() for inputspart in inputs] + + # Convert list to uppercase + def spicemanip_title(self, inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + return [inputspart.title() for inputspart in inputs] + + # Reverse List Order + def spicemanip_reverse(self, inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return [] + return inputs[::-1] + + # comma seperated list + def spicemanip_list(self, inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + return ', '.join(str(x) for x in inputs) + + def spicemanip_list_nospace(self, inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + return ','.join(str(x) for x in inputs) + + # comma seperated list with and + def spicemanip_andlist(self, inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + if len(inputs) < 2: + return ' '.join(inputs) + lastentry = str("and " + str(inputs[len(inputs) - 1])) + del inputs[-1] + inputs.append(lastentry) + if len(inputs) == 2: + return ' '.join(inputs) + return ', '.join(str(x) for x in inputs) + + # comma seperated list with or + def spicemanip_orlist(self, inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + if len(inputs) < 2: + return ' '.join(inputs) + lastentry = str("or " + str(inputs[len(inputs) - 1])) + del inputs[-1] + inputs.append(lastentry) + if len(inputs) == 2: + return ' '.join(inputs) + return ', '.join(str(x) for x in inputs) + + # exclude number + def spicemanip_exclude(self, inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + del inputs[int(mainoutputtask) - 1] + return ' '.join(inputs) + + # Convert list to string + def spicemanip_string(self, inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + return ' '.join(inputs) + + # Get number item from list + def spicemanip_number(self, inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + elif len(inputs) == 1: + return inputs[0] + elif int(mainoutputtask) > len(inputs) or int(mainoutputtask) < 0: + return '' + else: + return inputs[int(mainoutputtask) - 1] + + # Get Last item from list + def spicemanip_last(self, inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + return inputs[len(inputs) - 1] + + # range between items in list + def spicemanip_rangebetween(self, inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + if not str(mainoutputtask).isdigit() or not str( + suboutputtask).isdigit(): + return '' + mainoutputtask, suboutputtask = int(mainoutputtask), int(suboutputtask) + if suboutputtask == mainoutputtask: + return self.spicemanip_number(inputs, outputtask, mainoutputtask, + suboutputtask) + if suboutputtask < mainoutputtask: + return [] + if mainoutputtask < 0: + mainoutputtask = 1 + if suboutputtask > len(inputs): + suboutputtask = len(inputs) + newlist = [] + for i in range(mainoutputtask, suboutputtask + 1): + newlist.append( + str( + self.spicemanip_number(inputs, outputtask, i, + suboutputtask))) + if newlist == []: + return '' + return ' '.join(newlist) + + # Forward Range includes index number + def spicemanip_incrange_plus(self, inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + return self.spicemanip_rangebetween(inputs, outputtask, + int(mainoutputtask), len(inputs)) + + # Reverse Range includes index number + def spicemanip_incrange_minus(self, inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + return self.spicemanip_rangebetween(inputs, outputtask, 1, + int(mainoutputtask)) + + # Forward Range excludes index number + def spicemanip_excrange_plus(self, inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + return self.spicemanip_rangebetween(inputs, outputtask, + int(mainoutputtask) + 1, + len(inputs)) + + # Reverse Range excludes index number + def spicemanip_excrange_minus(self, inputs, outputtask, mainoutputtask, + suboutputtask): + if not len(inputs): + return '' + return self.spicemanip_rangebetween(inputs, outputtask, 1, + int(mainoutputtask) - 1) +spicemanip = Spicemanip() + +""" # Hub def spicemanip(inputs, outputtask, output_type='default'): @@ -702,3 +1055,4 @@ def spicemanip_excrange_minus(inputs, outputtask, mainoutputtask, return '' return spicemanip_rangebetween(inputs, outputtask, 1, int(mainoutputtask) - 1) +""" From 8d1f2159c9a9decca55e3d2f5fd6e5e552bf9121 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 12:26:23 -0400 Subject: [PATCH 84/96] self. --- sopel_modules/spicemanip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index fd4abbf..c28755c 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -421,7 +421,7 @@ class Spicemanip(): returnvalue = inputs else: returnvalue = eval( - 'spicemanip_' + outputtask + + 'self.spicemanip_' + outputtask + '(inputs, outputtask, mainoutputtask, suboutputtask)') # default return if not specified From 8e3b36870759ef6f7c8d90e931f58946aa1b370f Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 12:30:13 -0400 Subject: [PATCH 85/96] start process --- sopel_modules/spicemanip/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index c28755c..0e9c62b 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -358,6 +358,9 @@ class Spicemanip(): pass def __call__(self, inputs, outputtask, output_type='default'): + self.main(inputs, outputtask, output_type) + + def main(self, inputs, outputtask, output_type='default'): mainoutputtask, suboutputtask = None, None # Input needs to be a list, but don't split a word into letters From 45806f46553043a21105ea042da0709199b238b0 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 12:30:27 -0400 Subject: [PATCH 86/96] return --- sopel_modules/spicemanip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 0e9c62b..2de4570 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -358,7 +358,7 @@ class Spicemanip(): pass def __call__(self, inputs, outputtask, output_type='default'): - self.main(inputs, outputtask, output_type) + return self.main(inputs, outputtask, output_type) def main(self, inputs, outputtask, output_type='default'): mainoutputtask, suboutputtask = None, None From e417e42f908222428bc89a177ea35c16a0e4218b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 12:31:12 -0400 Subject: [PATCH 87/96] remove debug --- sopel_modules/SpiceBot_Core_Commands/DictComs.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index e4e69ff..da9cd69 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -35,7 +35,6 @@ def bot_dictcom_process(bot, trigger, botcom): # handling for special cases posscom = spicemanip(botcom.dict['args'], 1) - bot.say(str(posscom)) if posscom.lower() in [command.lower() for command in list(botcom.dict["dict"].keys())]: for command in botcom.dict["dict"].keys(): if command.lower() == posscom.lower(): From ab6b0db5656c8aed9e76c0881c82753ae4c6f431 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 13:30:02 -0400 Subject: [PATCH 88/96] test --- sopel_modules/spicemanip/__init__.py | 113 ++++++++++++++++++++++++++- 1 file changed, 112 insertions(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 2de4570..6bb5360 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -358,9 +358,120 @@ class Spicemanip(): pass def __call__(self, inputs, outputtask, output_type='default'): - return self.main(inputs, outputtask, output_type) + # return self.main(inputs, outputtask, output_type) + + # convert any input to list + inputs = self.core_input_handler(inputs) + + # get desired output + manipulated, outputtask = self.core_task_handler(inputs, outputtask) + + # get desired output + outputs = self.core_output_handler(manipulated, outputtask, output_type) + return outputs + + def core_input_handler(self, inputs): + # Input needs to be a list, but don't split a word into letters + if not inputs: + inputs = [] + if isinstance(inputs, collections.abc.KeysView): + inputs = list(inputs) + elif isinstance(inputs, dict): + inputs = list(inputs.keys()) + if not isinstance(inputs, list): + inputs = list(inputs.split(" ")) + inputs = [x for x in inputs if x and x not in ['', ' ']] + inputs = [inputspart.strip() for inputspart in inputs] + return inputs + + def core_task_handler(self, inputs, outputtask): + + mainoutputtask, suboutputtask = None, None + + # Create return + if outputtask == 'create': + return inputs + + # Make temparray to preserve original order + temparray = [] + for inputpart in inputs: + temparray.append(inputpart) + inputs = temparray + + # Convert outputtask to standard + if outputtask in [0, 'complete']: + outputtask = 'string' + elif outputtask == 'index': + mainoutputtask = inputs[1] + suboutputtask = inputs[2] + inputs = inputs[0] + elif str(outputtask).isdigit(): + mainoutputtask, outputtask = int(outputtask), 'number' + elif "^" in str(outputtask): + mainoutputtask = str(outputtask).split("^", 1)[0] + suboutputtask = str(outputtask).split("^", 1)[1] + outputtask = 'rangebetween' + if int(suboutputtask) < int(mainoutputtask): + mainoutputtask, suboutputtask = suboutputtask, mainoutputtask + elif str(outputtask).startswith("split_"): + mainoutputtask = str(outputtask).replace("split_", "") + outputtask = 'split' + elif str(outputtask).endswith(tuple(["!", "+", "-", "<", ">"])): + mainoutputtask = str(outputtask) + if str(outputtask).endswith("!"): + outputtask = 'exclude' + if str(outputtask).endswith("+"): + outputtask = 'incrange_plus' + if str(outputtask).endswith("-"): + outputtask = 'incrange_minus' + if str(outputtask).endswith(">"): + outputtask = 'excrange_plus' + if str(outputtask).endswith("<"): + outputtask = 'excrange_minus' + for r in (("!", ""), ("+", ""), ("-", ""), ("<", ""), (">", "")): + mainoutputtask = mainoutputtask.replace(*r) + if mainoutputtask == 'last': + mainoutputtask = len(inputs) + + if outputtask == 'string': + manipulated = inputs + else: + manipulated = eval( + 'self.spicemanip_' + outputtask + + '(inputs, outputtask, mainoutputtask, suboutputtask)') + return manipulated, outputtask + + def core_output_handler(self, manipulated, outputtask, output_type): + # default return if not specified + if output_type == 'default': + if outputtask in [ + 'string', 'number', 'rangebetween', 'exclude', 'random', + 'incrange_plus', 'incrange_minus', 'excrange_plus', + 'excrange_minus' + ]: + output_type = 'string' + elif outputtask in ['count']: + output_type = 'dict' + + # verify output is correct + if output_type == 'return': + return manipulated + if output_type == 'string': + if isinstance(manipulated, list): + manipulated = ' '.join(manipulated) + elif output_type in ['list', 'array']: + if not isinstance(manipulated, list): + manipulated = list(manipulated.split(" ")) + manipulated = [ + x for x in manipulated if x and x not in ['', ' '] + ] + manipulated = [ + inputspart.strip() for inputspart in manipulated + ] + return manipulated def main(self, inputs, outputtask, output_type='default'): + mainoutputtask, suboutputtask = None, None # Input needs to be a list, but don't split a word into letters From 1d5e9dcb512198636332c91211211612edb113ed Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 13:31:40 -0400 Subject: [PATCH 89/96] test --- sopel_modules/spicemanip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 6bb5360..b8a2e35 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -390,7 +390,7 @@ class Spicemanip(): # Create return if outputtask == 'create': - return inputs + return inputs, outputtask # Make temparray to preserve original order temparray = [] From 5801b8d0f1bd915e35db66d10a31e7e3f9e3abc4 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 6 Jul 2019 13:35:30 -0400 Subject: [PATCH 90/96] test --- sopel_modules/spicemanip/__init__.py | 195 +++++---------------------- 1 file changed, 33 insertions(+), 162 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index b8a2e35..90eb5b1 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -437,7 +437,7 @@ class Spicemanip(): manipulated = inputs else: manipulated = eval( - 'self.spicemanip_' + outputtask + + 'self.' + outputtask + '(inputs, outputtask, mainoutputtask, suboutputtask)') return manipulated, outputtask @@ -470,105 +470,8 @@ class Spicemanip(): ] return manipulated - def main(self, inputs, outputtask, output_type='default'): - - mainoutputtask, suboutputtask = None, None - - # Input needs to be a list, but don't split a word into letters - if not inputs: - inputs = [] - if isinstance(inputs, collections.abc.KeysView): - inputs = list(inputs) - elif isinstance(inputs, dict): - inputs = list(inputs.keys()) - if not isinstance(inputs, list): - inputs = list(inputs.split(" ")) - inputs = [x for x in inputs if x and x not in ['', ' ']] - inputs = [inputspart.strip() for inputspart in inputs] - - # Create return - if outputtask == 'create': - return inputs - - # Make temparray to preserve original order - temparray = [] - for inputpart in inputs: - temparray.append(inputpart) - inputs = temparray - - # Convert outputtask to standard - if outputtask in [0, 'complete']: - outputtask = 'string' - elif outputtask == 'index': - mainoutputtask = inputs[1] - suboutputtask = inputs[2] - inputs = inputs[0] - elif str(outputtask).isdigit(): - mainoutputtask, outputtask = int(outputtask), 'number' - elif "^" in str(outputtask): - mainoutputtask = str(outputtask).split("^", 1)[0] - suboutputtask = str(outputtask).split("^", 1)[1] - outputtask = 'rangebetween' - if int(suboutputtask) < int(mainoutputtask): - mainoutputtask, suboutputtask = suboutputtask, mainoutputtask - elif str(outputtask).startswith("split_"): - mainoutputtask = str(outputtask).replace("split_", "") - outputtask = 'split' - elif str(outputtask).endswith(tuple(["!", "+", "-", "<", ">"])): - mainoutputtask = str(outputtask) - if str(outputtask).endswith("!"): - outputtask = 'exclude' - if str(outputtask).endswith("+"): - outputtask = 'incrange_plus' - if str(outputtask).endswith("-"): - outputtask = 'incrange_minus' - if str(outputtask).endswith(">"): - outputtask = 'excrange_plus' - if str(outputtask).endswith("<"): - outputtask = 'excrange_minus' - for r in (("!", ""), ("+", ""), ("-", ""), ("<", ""), (">", "")): - mainoutputtask = mainoutputtask.replace(*r) - if mainoutputtask == 'last': - mainoutputtask = len(inputs) - - if outputtask == 'string': - returnvalue = inputs - else: - returnvalue = eval( - 'self.spicemanip_' + outputtask + - '(inputs, outputtask, mainoutputtask, suboutputtask)') - - # default return if not specified - if output_type == 'default': - if outputtask in [ - 'string', 'number', 'rangebetween', 'exclude', 'random', - 'incrange_plus', 'incrange_minus', 'excrange_plus', - 'excrange_minus' - ]: - output_type = 'string' - elif outputtask in ['count']: - output_type = 'dict' - - # verify output is correct - if output_type == 'return': - return returnvalue - if output_type == 'string': - if isinstance(returnvalue, list): - returnvalue = ' '.join(returnvalue) - elif output_type in ['list', 'array']: - if not isinstance(returnvalue, list): - returnvalue = list(returnvalue.split(" ")) - returnvalue = [ - x for x in returnvalue if x and x not in ['', ' '] - ] - returnvalue = [ - inputspart.strip() for inputspart in returnvalue - ] - return returnvalue - # compare 2 lists, based on the location of an index item, passthrough needs to be [indexitem, arraytoindex, arraytocompare] - def spicemanip_index(self, indexitem, outputtask, arraytoindex, - arraytocompare): + def index(self, indexitem, outputtask, arraytoindex, arraytocompare): item = '' for x, y in zip(arraytoindex, arraytocompare): if x == indexitem: @@ -576,8 +479,7 @@ class Spicemanip(): return item # split list by string - def spicemanip_split(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def split(self, inputs, outputtask, mainoutputtask, suboutputtask): split_array = [] restring = ' '.join(inputs) if mainoutputtask not in inputs: @@ -591,8 +493,7 @@ class Spicemanip(): return split_array # dedupe list - def spicemanip_dedupe(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def dedupe(self, inputs, outputtask, mainoutputtask, suboutputtask): newlist = [] for inputspart in inputs: if inputspart not in newlist: @@ -600,18 +501,15 @@ class Spicemanip(): return newlist # Sort list - def spicemanip_sort(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def sort(self, inputs, outputtask, mainoutputtask, suboutputtask): return sorted(inputs) # reverse sort list - def spicemanip_rsort(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def rsort(self, inputs, outputtask, mainoutputtask, suboutputtask): return sorted(inputs)[::-1] # count items in list, return dictionary - def spicemanip_count(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def count(self, inputs, outputtask, mainoutputtask, suboutputtask): returndict = dict() if not len(inputs): return returndict @@ -630,8 +528,7 @@ class Spicemanip(): return returndict # random item from list - def spicemanip_random(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def random(self, inputs, outputtask, mainoutputtask, suboutputtask): if not len(inputs): return '' randomselectlist = [] @@ -647,59 +544,50 @@ class Spicemanip(): return randomselect # remove random item from list - def spicemanip_exrandom(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def exrandom(self, inputs, outputtask, mainoutputtask, suboutputtask): if not len(inputs): return [] - randremove = self.spicemanip_random(inputs, outputtask, mainoutputtask, - suboutputtask) + randremove = self.random(inputs, outputtask, mainoutputtask, suboutputtask) inputs.remove(randremove) return inputs # Convert list into lowercase - def spicemanip_lower(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def lower(self, inputs, outputtask, mainoutputtask, suboutputtask): if not len(inputs): return '' return [inputspart.lower() for inputspart in inputs] # Convert list to uppercase - def spicemanip_upper(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def upper(self, inputs, outputtask, mainoutputtask, suboutputtask): if not len(inputs): return '' return [inputspart.upper() for inputspart in inputs] # Convert list to uppercase - def spicemanip_title(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def title(self, inputs, outputtask, mainoutputtask, suboutputtask): if not len(inputs): return '' return [inputspart.title() for inputspart in inputs] # Reverse List Order - def spicemanip_reverse(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def reverse(self, inputs, outputtask, mainoutputtask, suboutputtask): if not len(inputs): return [] return inputs[::-1] # comma seperated list - def spicemanip_list(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def list(self, inputs, outputtask, mainoutputtask, suboutputtask): if not len(inputs): return '' return ', '.join(str(x) for x in inputs) - def spicemanip_list_nospace(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def list_nospace(self, inputs, outputtask, mainoutputtask, suboutputtask): if not len(inputs): return '' return ','.join(str(x) for x in inputs) # comma seperated list with and - def spicemanip_andlist(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def andlist(self, inputs, outputtask, mainoutputtask, suboutputtask): if not len(inputs): return '' if len(inputs) < 2: @@ -712,8 +600,7 @@ class Spicemanip(): return ', '.join(str(x) for x in inputs) # comma seperated list with or - def spicemanip_orlist(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def orlist(self, inputs, outputtask, mainoutputtask, suboutputtask): if not len(inputs): return '' if len(inputs) < 2: @@ -726,23 +613,20 @@ class Spicemanip(): return ', '.join(str(x) for x in inputs) # exclude number - def spicemanip_exclude(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def exclude(self, inputs, outputtask, mainoutputtask, suboutputtask): if not len(inputs): return '' del inputs[int(mainoutputtask) - 1] return ' '.join(inputs) # Convert list to string - def spicemanip_string(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def string(self, inputs, outputtask, mainoutputtask, suboutputtask): if not len(inputs): return '' return ' '.join(inputs) # Get number item from list - def spicemanip_number(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def number(self, inputs, outputtask, mainoutputtask, suboutputtask): if not len(inputs): return '' elif len(inputs) == 1: @@ -753,15 +637,13 @@ class Spicemanip(): return inputs[int(mainoutputtask) - 1] # Get Last item from list - def spicemanip_last(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def last(self, inputs, outputtask, mainoutputtask, suboutputtask): if not len(inputs): return '' return inputs[len(inputs) - 1] # range between items in list - def spicemanip_rangebetween(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def rangebetween(self, inputs, outputtask, mainoutputtask, suboutputtask): if not len(inputs): return '' if not str(mainoutputtask).isdigit() or not str( @@ -769,8 +651,7 @@ class Spicemanip(): return '' mainoutputtask, suboutputtask = int(mainoutputtask), int(suboutputtask) if suboutputtask == mainoutputtask: - return self.spicemanip_number(inputs, outputtask, mainoutputtask, - suboutputtask) + return self.number(inputs, outputtask, mainoutputtask, suboutputtask) if suboutputtask < mainoutputtask: return [] if mainoutputtask < 0: @@ -781,44 +662,34 @@ class Spicemanip(): for i in range(mainoutputtask, suboutputtask + 1): newlist.append( str( - self.spicemanip_number(inputs, outputtask, i, - suboutputtask))) + self.number(inputs, outputtask, i, suboutputtask))) if newlist == []: return '' return ' '.join(newlist) # Forward Range includes index number - def spicemanip_incrange_plus(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def incrange_plus(self, inputs, outputtask, mainoutputtask, suboutputtask): if not len(inputs): return '' - return self.spicemanip_rangebetween(inputs, outputtask, - int(mainoutputtask), len(inputs)) + return self.rangebetween(inputs, outputtask, int(mainoutputtask), len(inputs)) # Reverse Range includes index number - def spicemanip_incrange_minus(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def incrange_minus(self, inputs, outputtask, mainoutputtask, suboutputtask): if not len(inputs): return '' - return self.spicemanip_rangebetween(inputs, outputtask, 1, - int(mainoutputtask)) + return self.rangebetween(inputs, outputtask, 1, int(mainoutputtask)) # Forward Range excludes index number - def spicemanip_excrange_plus(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def excrange_plus(self, inputs, outputtask, mainoutputtask, suboutputtask): if not len(inputs): return '' - return self.spicemanip_rangebetween(inputs, outputtask, - int(mainoutputtask) + 1, - len(inputs)) + return self.rangebetween(inputs, outputtask, int(mainoutputtask) + 1, len(inputs)) # Reverse Range excludes index number - def spicemanip_excrange_minus(self, inputs, outputtask, mainoutputtask, - suboutputtask): + def excrange_minus(self, inputs, outputtask, mainoutputtask, suboutputtask): if not len(inputs): return '' - return self.spicemanip_rangebetween(inputs, outputtask, 1, - int(mainoutputtask) - 1) + return self.rangebetween(inputs, outputtask, 1, int(mainoutputtask) - 1) spicemanip = Spicemanip() From e01c53ae1f026e901ae5efda174225f5f7c019f7 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 8 Jul 2019 08:03:31 -0400 Subject: [PATCH 91/96] attempt --- sopel_modules/spicemanip/__init__.py | 383 +-------------------------- 1 file changed, 12 insertions(+), 371 deletions(-) diff --git a/sopel_modules/spicemanip/__init__.py b/sopel_modules/spicemanip/__init__.py index 90eb5b1..b189fd8 100644 --- a/sopel_modules/spicemanip/__init__.py +++ b/sopel_modules/spicemanip/__init__.py @@ -13,344 +13,6 @@ import collections # TODO reverse sort z.sort(reverse = True) # list.extend adds lists to eachother -""" -class Spicemanip_new(): - def __init__(self): - pass - - def __call__(self, inputs, task, output_type='default'): - - # convert input into list - self.inputs = inputs - self.core_input_handler() - - # determine task - self.task = task - self.core_task_handler() - - # determine output of list - self.output_type = output_type - self.core_output_handler() - - # return value/s - return self.outputs - - def core_input_handler(self): - # Input needs to be a list, but don't split a word into letters - if not self.inputs or not len(self.inputs): - self.input_list = [] - return - if isinstance(self.inputs, list): - self.input_list = self.inputs.copy() - return - if isinstance(self.inputs, collections.abc.KeysView): - self.input_list = list(self.inputs) - return - if isinstance(self.inputs, dict): - self.input_list = list(self.inputs.keys()) - return - if not isinstance(self.inputs, list): - self.input_list = self.inputs.split(" ") - return - - def core_task_handler(self): - - # Create return - if self.task in ['create']: - self.outputs = self.input_list - return - - if not len(self.input_list): - self.outputs = [] - return - - if self.task in ["0", 0, 'complete']: - self.outputs = self.string(self.input_list) - self.task = "complete" - - elif self.task in ['index']: - self.outputs = self.index(self.input_list[0], self.input_list[1], - self.input_list[2]) - self.task = "index" - - elif self.task in ['last', '-1', -1]: - self.outputs = self.last(self.input_list) - self.task = "last" - - elif self.is_digit(self.task): - self.outputs = self.number(self.input_list, int(self.task)) - self.task = "number" - - elif "^" in str(self.task): - range_nums = str(self.task).split("^", 1).sort() - range_start, range_end = range_nums[0], range_nums[1] - self.outputs = self.rangebetween(self.input_list, int(range_start), - int(range_end)) - self.task = "rangebetween" - - elif str(self.task).startswith("split_"): - split_mark = str(self.task).replace("split_", "") - self.outputs = self.split(self.input_list, split_mark) - self.task = "split" - - elif str(self.task).endswith("!"): - exclude_num = str(self.task).replace("!", "") - self.outputs = self.exclude(self.input_list, int(exclude_num)) - self.task = "exclude" - - elif str(self.task).endswith("+"): - range_start = str(self.task).replace("+", "") - self.outputs = self.incrange_plus(self.input_list, - int(range_start)) - self.task = "incrange_plus" - - elif str(self.task).endswith("-"): - range_end = str(self.task).replace("-", "") - self.outputs = self.incrange_minus(self.input_list, int(range_end)) - self.task = "incrange_minus" - - elif str(self.task).endswith(">"): - range_start = str(self.task).replace(">", "") - self.outputs = self.excrange_plus(self.input_list, - int(range_start)) - self.task = "excrange_plus" - - elif str(self.task).endswith("<"): - range_end = str(self.task).replace("<", "") - self.outputs = self.excrange_minus(self.input_list, int(range_end)) - self.task = "excrange_minus" - - elif hasattr(self, str( - self.task)) and not str(self.task).startswith("core_"): - self.outputs = eval('self.' + str(self.task) + '(self.input_list)') - - else: - raise Exception( - str(self.task) + " is not a valid spicemanip function.") - - def core_output_handler(self): - - core_defaults = { - 'string': "string", - 'number': "string", - 'rangebetween': "string", - 'exclude': "string", - 'random': "string", - 'incrange_plus': "string", - 'incrange_minus': "string", - 'excrange_plus': "string", - 'excrange_minus': "string", - 'count': "dict", - "create": "list", - 'complete': "string", - } - - # default return if not specified - if self.output_type == 'default': - if self.task in list(core_defaults.keys()): - self.output_type = core_defaults[self.task] - - # verify output is correct - if self.output_type in ['return', 'dict']: - return - - if self.output_type == 'string': - self.outputs = self.string(self.outputs) - return - - if self.output_type in ['list', 'array']: - self.outputs = self.list(self.outputs) - return - - # Convert list to string - def complete(self, inputs): - return self.string(inputs) - - def last(self, inputs): - return self.number(inputs, -1) - - # Convert list to string - def string(self, inputs): - if not isinstance(inputs, list): - return inputs - if not inputs or not len(inputs): - return '' - return ' '.join(inputs) - - def create(self, inputs): - return self.list(inputs) - - # Convert inputs to list - def list(self, inputs): - if isinstance(inputs, list): - return inputs - if not inputs or not len(inputs): - return [] - return list(inputs.split(" ")) - - def index(self, indexitem, listtoindex, listtocompare): - for x, y in zip(listtoindex, listtocompare): - if x == indexitem: - return y - return '' - - # Get number item from list - def number(self, inputs, index_number): - if int(index_number) > 0: - index_number -= 1 - try: - return inputs[int(index_number)] - except IndexError: - return '' - - # range between items in list - def rangebetween(self, inputs, range_start, range_end): - range_start, range_end = int(range_start), int(range_end) - if range_end == range_start: - return self.number(inputs, range_start) - if range_start < 0: - range_start = 1 - if range_end > len(inputs): - range_end = len(inputs) - newlist = [] - for i in range(range_start, range_end + 1): - newlist.append(str(self.number(inputs, i))) - return ' '.join(newlist) - - # split list by string - def split(self, inputs, splitby): - split_list = [] - restring = ' '.join(inputs) - if splitby not in inputs: - split_list = [restring] - else: - split_list = restring.split(splitby) - return ' '.join(split_list) - - # exclude number - def exclude(self, inputs, excludenum): - try: - del inputs[int(excludenum) - 1] - return ' '.join(inputs) - except IndexError: - return ' '.join(inputs) - - # Forward Range includes index number - def incrange_plus(self, inputs, range_start): - return self.rangebetween(inputs, int(range_start), len(inputs)) - - # Reverse Range includes index number - def incrange_minus(self, inputs, range_end): - return self.rangebetween(inputs, 1, int(range_end)) - - # Forward Range excludes index number - def excrange_plus(self, inputs, range_start): - return self.rangebetween(inputs, int(range_start) + 1, len(inputs)) - - # Reverse Range excludes index number - def excrange_minus(self, inputs, range_end): - return self.rangebetween(inputs, 1, int(range_end) - 1) - - # dedupe list - def dedupe(self, inputs): - newlist = [] - for inputspart in inputs: - if inputspart not in newlist: - newlist.append(inputspart) - return newlist - - # Sort list - def sort(self, inputs): - return sorted(inputs) - - # reverse sort list - def rsort(self, inputs): - return sorted(inputs)[::-1] - - # count items in list, return dictionary - def count(self, inputs): - returndict = dict() - uniqueinputitems, uniquecount = [], [] - for inputspart in inputs: - if inputspart not in uniqueinputitems: - uniqueinputitems.append(inputspart) - for uniqueinputspart in uniqueinputitems: - count = 0 - for ele in inputs: - if (ele == uniqueinputspart): - count += 1 - uniquecount.append(count) - for inputsitem, unumber in zip(uniqueinputitems, uniquecount): - returndict[inputsitem] = unumber - return returndict - - # random item from list - def random(self, inputs): - randomselectlist = list(inputs) - while len(randomselectlist) > 1: - random.shuffle(randomselectlist) - randomselect = randomselectlist[random.randint( - 0, - len(randomselectlist) - 1)] - randomselectlist.remove(randomselect) - randomselect = randomselectlist[0] - return randomselect - - # remove random item from list - def exrandom(self, inputs): - randremove = self.random(inputs) - inputs.remove(randremove) - return inputs - - # Convert list into lowercase - def lower(self, inputs): - return [inputspart.lower() for inputspart in inputs] - - # Convert list to uppercase - def upper(self, inputs): - return [inputspart.upper() for inputspart in inputs] - - # Convert list to uppercase - def title(self, inputs): - return [inputspart.title() for inputspart in inputs] - - # Reverse List Order - def reverse(self, inputs): - return inputs[::-1] - - def list_nospace(self, inputs): - return ','.join(str(x) for x in inputs) - - # comma seperated list with and - def andlist(self, inputs): - if len(inputs) < 2: - return ' '.join(inputs) - lastentry = str("and " + str(inputs[len(inputs) - 1])) - del inputs[-1] - inputs.append(lastentry) - if len(inputs) == 2: - return ' '.join(inputs) - return ', '.join(str(x) for x in inputs) - - # comma seperated list with or - def orlist(self, inputs): - if len(inputs) < 2: - return ' '.join(inputs) - lastentry = str("or " + str(inputs[len(inputs) - 1])) - del inputs[-1] - inputs.append(lastentry) - if len(inputs) == 2: - return ' '.join(inputs) - return ', '.join(str(x) for x in inputs) - - def is_digit(self, n): - try: - int(n) - return True - except ValueError: - return False -""" - class Spicemanip(): @@ -358,19 +20,9 @@ class Spicemanip(): pass def __call__(self, inputs, outputtask, output_type='default'): - # return self.main(inputs, outputtask, output_type) - # convert any input to list - inputs = self.core_input_handler(inputs) + mainoutputtask, suboutputtask = None, None - # get desired output - manipulated, outputtask = self.core_task_handler(inputs, outputtask) - - # get desired output - outputs = self.core_output_handler(manipulated, outputtask, output_type) - return outputs - - def core_input_handler(self, inputs): # Input needs to be a list, but don't split a word into letters if not inputs: inputs = [] @@ -382,15 +34,10 @@ class Spicemanip(): inputs = list(inputs.split(" ")) inputs = [x for x in inputs if x and x not in ['', ' ']] inputs = [inputspart.strip() for inputspart in inputs] - return inputs - - def core_task_handler(self, inputs, outputtask): - - mainoutputtask, suboutputtask = None, None # Create return if outputtask == 'create': - return inputs, outputtask + return inputs # Make temparray to preserve original order temparray = [] @@ -434,14 +81,12 @@ class Spicemanip(): mainoutputtask = len(inputs) if outputtask == 'string': - manipulated = inputs + returnvalue = inputs else: - manipulated = eval( + returnvalue = eval( 'self.' + outputtask + '(inputs, outputtask, mainoutputtask, suboutputtask)') - return manipulated, outputtask - def core_output_handler(self, manipulated, outputtask, output_type): # default return if not specified if output_type == 'default': if outputtask in [ @@ -455,20 +100,16 @@ class Spicemanip(): # verify output is correct if output_type == 'return': - return manipulated + return returnvalue if output_type == 'string': - if isinstance(manipulated, list): - manipulated = ' '.join(manipulated) + if isinstance(returnvalue, list): + returnvalue = ' '.join(returnvalue) elif output_type in ['list', 'array']: - if not isinstance(manipulated, list): - manipulated = list(manipulated.split(" ")) - manipulated = [ - x for x in manipulated if x and x not in ['', ' '] - ] - manipulated = [ - inputspart.strip() for inputspart in manipulated - ] - return manipulated + if not isinstance(returnvalue, list): + returnvalue = list(returnvalue.split(" ")) + returnvalue = [x for x in returnvalue if x and x not in ['', ' ']] + returnvalue = [inputspart.strip() for inputspart in returnvalue] + return returnvalue # compare 2 lists, based on the location of an index item, passthrough needs to be [indexitem, arraytoindex, arraytocompare] def index(self, indexitem, outputtask, arraytoindex, arraytocompare): From 32ebbc83d3c7858fe204ea1e7be0e0156650de07 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 8 Jul 2019 16:01:55 -0400 Subject: [PATCH 92/96] remove --- sopel_modules/SpiceBot_Core_Commands/AI.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/AI.py b/sopel_modules/SpiceBot_Core_Commands/AI.py index 16f1f7a..4a01b13 100644 --- a/sopel_modules/SpiceBot_Core_Commands/AI.py +++ b/sopel_modules/SpiceBot_Core_Commands/AI.py @@ -8,6 +8,8 @@ import sopel_modules.SpiceBot as SpiceBot from sopel_modules.spicemanip import spicemanip +# TODO split functionality for "no command" + @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('ai') @@ -101,7 +103,6 @@ def bot_command_rule_ai(bot, trigger): return if command_type == 'module': - return # TODO if trigger_command not in commands_list: if not SpiceBot.letters_in_string(trigger_command): return From 45e9399374b4300f66e389bf9124ba2d464f2726 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 10 Jul 2019 08:03:31 -0400 Subject: [PATCH 93/96] TODO command --- sopel_modules/SpiceBot/Commands.py | 9 +++++++++ sopel_modules/SpiceBot_Core_Commands/TODO.py | 16 ++++++++++++++++ sopel_modules/SpiceBot_Core_Commands/__init__.py | 1 + 3 files changed, 26 insertions(+) create mode 100644 sopel_modules/SpiceBot_Core_Commands/TODO.py diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index 4efdca0..ac328c8 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -43,6 +43,7 @@ class BotCommands(): }, 'disabled': {}, } + self.todo_list = [] self.module_files_parse() self.nickrules() for comtype in ['module', 'nickname', 'rule']: @@ -280,6 +281,7 @@ class BotCommands(): comdict["foldername"] = str(foldername) detected_lines = [] + todo_list = [] for line in module_file_lines: if str(line).startswith("@"): @@ -296,18 +298,25 @@ class BotCommands(): elif str(line).startswith(tuple(["rule", "module.rule", "sopel.module.rule"])): line = str(line).split("rule")[-1] line = "rule" + line + elif "TODO" in str(line): + todo_list.append(str(line)) else: line = None if line: detected_lines.append(line) + if len(todo_list): + self.todo_list.append(todo_list) + if len(detected_lines): filelinelist = [] for detected_line in detected_lines: validcomdict = copy.deepcopy(comdict) + validcomdict["TODO"] = todo_list + # Commands if str(detected_line).startswith("commands"): comtype = "module" diff --git a/sopel_modules/SpiceBot_Core_Commands/TODO.py b/sopel_modules/SpiceBot_Core_Commands/TODO.py new file mode 100644 index 0000000..e42face --- /dev/null +++ b/sopel_modules/SpiceBot_Core_Commands/TODO.py @@ -0,0 +1,16 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +""" +This is the SpiceBot Users system. +""" +import sopel + +import sopel_modules.SpiceBot as SpiceBot +from sopel_modules.spicemanip import spicemanip + + +@SpiceBot.prerun('nickname') +@sopel.module.nickname_commands('todo') +def nickname_comand_users(bot, trigger, botcom): + todo_task = spicemanip(SpiceBot.commands.todo_list, 'random') + bot.osd(["Random TODO task for you: {}.".format(todo_task)]) diff --git a/sopel_modules/SpiceBot_Core_Commands/__init__.py b/sopel_modules/SpiceBot_Core_Commands/__init__.py index bcdf439..0136317 100644 --- a/sopel_modules/SpiceBot_Core_Commands/__init__.py +++ b/sopel_modules/SpiceBot_Core_Commands/__init__.py @@ -25,6 +25,7 @@ from .Gif import * from .Sherlock import * from .Reddit import * from .DictComs import * +from .TODO import * __author__ = 'Sam Zick' __email__ = 'sam@deathbybandaid.net' From 2b882216df094eb9052e1369b81a8b55921e6158 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 10 Jul 2019 08:07:12 -0400 Subject: [PATCH 94/96] better logic --- sopel_modules/SpiceBot/Commands.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index ac328c8..1563262 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -298,16 +298,17 @@ class BotCommands(): elif str(line).startswith(tuple(["rule", "module.rule", "sopel.module.rule"])): line = str(line).split("rule")[-1] line = "rule" + line - elif "TODO" in str(line): - todo_list.append(str(line)) else: line = None if line: detected_lines.append(line) + elif "TODO" in str(line): + todo_list.append(str(line)) + if len(todo_list): - self.todo_list.append(todo_list) + self.todo_list.extend(todo_list) if len(detected_lines): From 2febf396cb1e9f9e7de15837fab05d741d9adc45 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 10 Jul 2019 08:21:12 -0400 Subject: [PATCH 95/96] split tools commands from core commands, introduce flip for testing --- .../SpiceBot_Core_Commands/__init__.py | 4 --- sopel_modules/SpiceBot_Core_Extra/__init__.py | 9 +++++ sopel_modules/SpiceBot_Core_Extra/flip.py | 34 +++++++++++++++++++ .../Gif.py | 0 .../Reddit.py | 0 .../Search.py | 0 .../Sherlock.py | 0 sopel_modules/SpiceBot_Core_Tools/__init__.py | 12 +++++++ 8 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 sopel_modules/SpiceBot_Core_Extra/__init__.py create mode 100644 sopel_modules/SpiceBot_Core_Extra/flip.py rename sopel_modules/{SpiceBot_Core_Commands => SpiceBot_Core_Tools}/Gif.py (100%) rename sopel_modules/{SpiceBot_Core_Commands => SpiceBot_Core_Tools}/Reddit.py (100%) rename sopel_modules/{SpiceBot_Core_Commands => SpiceBot_Core_Tools}/Search.py (100%) rename sopel_modules/{SpiceBot_Core_Commands => SpiceBot_Core_Tools}/Sherlock.py (100%) create mode 100644 sopel_modules/SpiceBot_Core_Tools/__init__.py diff --git a/sopel_modules/SpiceBot_Core_Commands/__init__.py b/sopel_modules/SpiceBot_Core_Commands/__init__.py index 0136317..83d0712 100644 --- a/sopel_modules/SpiceBot_Core_Commands/__init__.py +++ b/sopel_modules/SpiceBot_Core_Commands/__init__.py @@ -19,11 +19,7 @@ from .Runtime_Controls import * from .Messaging import * from .Docs import * from .BotPrivs import * -from .Search import * from .AI import * -from .Gif import * -from .Sherlock import * -from .Reddit import * from .DictComs import * from .TODO import * diff --git a/sopel_modules/SpiceBot_Core_Extra/__init__.py b/sopel_modules/SpiceBot_Core_Extra/__init__.py new file mode 100644 index 0000000..cfa65c7 --- /dev/null +++ b/sopel_modules/SpiceBot_Core_Extra/__init__.py @@ -0,0 +1,9 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +# pylama:ignore=W0401,W0611 + +from .flip import * + +__author__ = 'Sam Zick' +__email__ = 'sam@deathbybandaid.net' +__version__ = '0.1.1' diff --git a/sopel_modules/SpiceBot_Core_Extra/flip.py b/sopel_modules/SpiceBot_Core_Extra/flip.py new file mode 100644 index 0000000..de10546 --- /dev/null +++ b/sopel_modules/SpiceBot_Core_Extra/flip.py @@ -0,0 +1,34 @@ +# coding=utf-8 + +from __future__ import unicode_literals, absolute_import, division, print_function + +import sopel.module + +import sopel_modules.SpiceBot as SpiceBot + +from sopel_modules.spicemanip import spicemanip + +from upsidedown import transform +# TODO add upsidedown to spicemanip + + +@sopel.module.rule('^flips (.+)') +@sopel.module.intent('ACTION') +def flips(bot, trigger): + target = trigger.group(1).strip() + if target == 'a table': + bot.say("(╯°□°)╯︵ ┻━┻") + else: + bot.say("(╯°□°)╯︵ %s" % transform(target)) + + +@sopel.module.rule('^rolls (.+)') +@sopel.module.intent('ACTION') +def roll(bot, trigger): + target = trigger.group(1).strip() + if target.endswith(' down a hill'): + target = target[:-12] + tegrat = transform(target) + bot.say("(╮°-°)╯︵ %s %s %s %s %s (@_@;)" % (tegrat, target, tegrat, target, tegrat)) + else: + bot.say("(╮°-°)╯︵ %s" % transform(target)) diff --git a/sopel_modules/SpiceBot_Core_Commands/Gif.py b/sopel_modules/SpiceBot_Core_Tools/Gif.py similarity index 100% rename from sopel_modules/SpiceBot_Core_Commands/Gif.py rename to sopel_modules/SpiceBot_Core_Tools/Gif.py diff --git a/sopel_modules/SpiceBot_Core_Commands/Reddit.py b/sopel_modules/SpiceBot_Core_Tools/Reddit.py similarity index 100% rename from sopel_modules/SpiceBot_Core_Commands/Reddit.py rename to sopel_modules/SpiceBot_Core_Tools/Reddit.py diff --git a/sopel_modules/SpiceBot_Core_Commands/Search.py b/sopel_modules/SpiceBot_Core_Tools/Search.py similarity index 100% rename from sopel_modules/SpiceBot_Core_Commands/Search.py rename to sopel_modules/SpiceBot_Core_Tools/Search.py diff --git a/sopel_modules/SpiceBot_Core_Commands/Sherlock.py b/sopel_modules/SpiceBot_Core_Tools/Sherlock.py similarity index 100% rename from sopel_modules/SpiceBot_Core_Commands/Sherlock.py rename to sopel_modules/SpiceBot_Core_Tools/Sherlock.py diff --git a/sopel_modules/SpiceBot_Core_Tools/__init__.py b/sopel_modules/SpiceBot_Core_Tools/__init__.py new file mode 100644 index 0000000..4a70f4b --- /dev/null +++ b/sopel_modules/SpiceBot_Core_Tools/__init__.py @@ -0,0 +1,12 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +# pylama:ignore=W0401,W0611 + +from .Gif import * +from .Sherlock import * +from .Reddit import * +from .Search import * + +__author__ = 'Sam Zick' +__email__ = 'sam@deathbybandaid.net' +__version__ = '0.1.1' From 5ce4af702aeceb166558897b64d676845488e44d Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 10 Jul 2019 08:22:19 -0400 Subject: [PATCH 96/96] remove imports --- sopel_modules/SpiceBot_Core_Extra/flip.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Extra/flip.py b/sopel_modules/SpiceBot_Core_Extra/flip.py index de10546..577a97b 100644 --- a/sopel_modules/SpiceBot_Core_Extra/flip.py +++ b/sopel_modules/SpiceBot_Core_Extra/flip.py @@ -4,9 +4,9 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module -import sopel_modules.SpiceBot as SpiceBot +# import sopel_modules.SpiceBot as SpiceBot -from sopel_modules.spicemanip import spicemanip +# from sopel_modules.spicemanip import spicemanip from upsidedown import transform # TODO add upsidedown to spicemanip