diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index 58bae25..002ac5a 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -122,12 +122,14 @@ class BotCommands(): raise Exception(str(target.lower()) + " appears to not be a valid user/channel") def check_commands_disabled(self, command, target, disabletype="fully"): + command = str(command).lower() if command in list(self.get_commands_disabled(target, disabletype).keys()): return True else: return False def set_command_disabled(self, command, target, timestamp, reason, bywhom, disabletype="fully"): + command = str(command).lower() disabletype = str(disabletype) target_type = self.chan_or_nick(target) if disabletype not in list(self.dict['disabled'].keys()): @@ -140,17 +142,18 @@ class BotCommands(): if nick_id not in list(self.dict['disabled'][disabletype]["nick"].keys()): self.dict['disabled'][disabletype]["nick"][nick_id] = botdb.get_nick_value(target, 'commands_' + disabletype + 'disabled') or {} self.dict['disabled'][disabletype]["nick"][nick_id][command] = {"reason": reason, "timestamp": timestamp, "disabledby": bywhom} - botdb.set_nick_value(target, 'commands_' + disabletype + 'disabled', self.dict['disabled'][disabletype]["nick"][target]) + botdb.set_nick_value(target, 'commands_' + disabletype + 'disabled', self.dict['disabled'][disabletype]["nick"][nick_id]) elif target_type == "channel": target = str(target).lower() if target not in list(self.dict['disabled'][disabletype]["channel"].keys()): self.dict['disabled'][disabletype]["channel"][target] = botdb.get_channel_value(target, 'commands_' + disabletype + 'disabled') or {} self.dict['disabled'][disabletype]["channel"][target][command] = {"reason": reason, "timestamp": timestamp, "disabledby": bywhom} - botdb.set_channel_value(target, 'commands_' + disabletype + 'disabled', self.dict['disabled'][disabletype]["channel"][nick_id]) + botdb.set_channel_value(target, 'commands_' + disabletype + 'disabled', self.dict['disabled'][disabletype]["channel"][target]) else: raise Exception(str(target.lower()) + " appears to not be a valid user/channel") def unset_command_disabled(self, command, target, disabletype="fully"): + command = str(command).lower() disabletype = str(disabletype) target_type = self.chan_or_nick(target) if disabletype not in list(self.dict['disabled'].keys()): @@ -162,14 +165,14 @@ class BotCommands(): nick_id = botusers.ID(target) if nick_id not in list(self.dict['disabled'][disabletype]["nick"].keys()): self.dict['disabled'][disabletype]["nick"][nick_id] = botdb.get_nick_value(target, 'commands_' + disabletype + 'disabled') or {} - if command in list(self.dict['disabled'][disabletype]["nick"].keys()): + if command in list(self.dict['disabled'][disabletype]["nick"][nick_id].keys()): del self.dict['disabled'][disabletype]["nick"][nick_id][command] botdb.set_nick_value(target, 'commands_' + disabletype + 'disabled', self.dict['disabled'][disabletype]["nick"][nick_id]) elif target_type == "channel": target = str(target).lower() if target not in list(self.dict['disabled'][disabletype]["channel"].keys()): self.dict['disabled'][disabletype]["nick"][target] = botdb.get_channel_value(target, 'commands_' + disabletype + 'disabled') or {} - if command in list(self.dict['disabled'][disabletype]["channel"][target]): + if command in list(self.dict['disabled'][disabletype]["channel"][target].keys()): del self.dict['disabled'][disabletype]["channel"][target][command] botdb.set_channel_value(target, 'commands_' + disabletype + 'disabled', self.dict['disabled'][disabletype]["channel"][target]) else: diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 7ce64f3..29f96a4 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -236,12 +236,12 @@ 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), "fully") + channel_disabled_list = botcommands.get_commands_disabled(str(trigger.sender)) if "nickname_query" in list(channel_disabled_list.keys()): return False # don't run commands that are disabled for specific users - nick_disabled_list = botcommands.get_commands_disabled(str(trigger.nick), "fully") + nick_disabled_list = botcommands.get_commands_disabled(str(trigger.nick)) if "nickname_query" in list(nick_disabled_list.keys()): return False @@ -314,7 +314,7 @@ def trigger_runstatus(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), "fully") + 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"] @@ -323,7 +323,7 @@ def trigger_runstatus(bot, trigger): 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), "fully") + 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 botusers.ID(bywhom) != botusers.ID(trigger.nick): @@ -332,7 +332,7 @@ def trigger_runstatus(bot, trigger): message = "The " + str(trigger.sb["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, "fully") + 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)) return True @@ -415,24 +415,24 @@ def trigger_hyphen_arg_handler(bot, trigger): if trigger.sb["hyphen_arg"] in ['enable', 'unblock', "activate", "on"]: - if not botcommands.check_commands_disabled(trigger.sb["realcomref"], target, "fully"): + 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)) return - botcommands.unset_command_disabled(trigger.sb["realcomref"], target, "fully") + botcommands.unset_command_disabled(trigger.sb["realcomref"], target) botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["comtext"] + " is now enabled for " + str(target)) return else: - if botcommands.check_commands_disabled(trigger.sb["realcomref"], target, "fully"): + 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)) return trailingmessage = spicemanip.main(trigger.sb["args"], 0) or "No reason given." timestamp = str(datetime.datetime.utcnow()) - botcommands.set_command_disabled(trigger.sb["realcomref"], target, timestamp, trailingmessage, trigger.nick, "fully") + 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)) return