From 1b14d96b713d82d4b70d2351dd7ead58428cbe4c Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 08:48:26 -0400 Subject: [PATCH 01/23] revert change --- sopel_modules/SpiceBot_Core_Commands/{DictComs => DictComs.py} | 0 sopel_modules/SpiceBot_Core_Commands/__init__.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename sopel_modules/SpiceBot_Core_Commands/{DictComs => DictComs.py} (100%) diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs b/sopel_modules/SpiceBot_Core_Commands/DictComs.py similarity index 100% rename from sopel_modules/SpiceBot_Core_Commands/DictComs rename to sopel_modules/SpiceBot_Core_Commands/DictComs.py diff --git a/sopel_modules/SpiceBot_Core_Commands/__init__.py b/sopel_modules/SpiceBot_Core_Commands/__init__.py index 97c416c..e4b9d44 100644 --- a/sopel_modules/SpiceBot_Core_Commands/__init__.py +++ b/sopel_modules/SpiceBot_Core_Commands/__init__.py @@ -21,7 +21,7 @@ from .AI import * from .Gif import * from .Sherlock import * from .Reddit import * -# from .DictComs import * +from .DictComs import * __author__ = 'Sam Zick' __email__ = 'sam@deathbybandaid.net' From 8a24ca71e74f1794aa3ed66c2217b66043922b2c Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 10:59:53 -0400 Subject: [PATCH 02/23] test multirun disabling --- sopel_modules/SpiceBot/Channels.py | 25 ++++- sopel_modules/SpiceBot/Commands.py | 92 +++++++++++++----- sopel_modules/SpiceBot/Prerun.py | 149 +++++++++++++++++++++++------ sopel_modules/SpiceBot/Users.py | 4 + 4 files changed, 217 insertions(+), 53 deletions(-) diff --git a/sopel_modules/SpiceBot/Channels.py b/sopel_modules/SpiceBot/Channels.py index 22dcc6e..e0b34e3 100644 --- a/sopel_modules/SpiceBot/Channels.py +++ b/sopel_modules/SpiceBot/Channels.py @@ -29,6 +29,7 @@ class BotChannels(): self.lock = threading.Lock() self.channel_lock = False + self.channels = [] self.dict = { "list": {}, "InitialProcess": False @@ -46,7 +47,7 @@ class BotChannels(): if channel.lower() not in list(self.dict["list"].keys()): raise Exception('Channel ' + str(channel.lower()) + " does not seem to be on this server") - if 'users' not in list(self.dict["list"][channel.lower()].keys()): + if 'users' not in list(self.dict["list"][channel.lower()].keys()) or not self.check_channel_bot(channel): raise Exception('Channel ' + str(channel.lower()) + " does not seem to be a channel the bot is in") nick_ids = self.dict["list"][channel.lower()]['users'] @@ -102,6 +103,8 @@ class BotChannels(): self.lock.acquire() del self.dict['list'][channel.lower()] self.lock.release() + if channel.lower() in self.channels: + self.channels.remove(channel.lower()) def join_all_channels(self, bot): if botconfig.SpiceBot_Channels.joinall: @@ -112,6 +115,10 @@ class BotChannels(): if channel not in list(bot.channels.keys()) and botconfig.SpiceBot_Channels.operadmin: bot.write(('SAJOIN', bot.nick, self.dict['list'][channel]['name'])) + if channel in list(bot.channels.keys()): + if channel.lower() not in self.channels: + self.channels.append(channel.lower()) + def chanadmin_all_channels(self, bot): # Chan ADMIN +a for channel in list(bot.channels.keys()): @@ -123,6 +130,10 @@ class BotChannels(): else: bot.part(channel) + if channel not in list(bot.channels.keys()): + if channel.lower() in self.channels: + self.channels.remove(channel.lower()) + def whois_ident(self, nick): nick = Identifier(nick) nick_id = botdb.db.get_nick_id(nick, create=True) @@ -138,6 +149,8 @@ class BotChannels(): self.dict['list'][channel.lower()]['users'] = [] if nick_id not in self.dict['list'][channel.lower()]['users']: self.dict['list'][channel.lower()]['users'].append(int(nick_id)) + if channel.lower() not in self.channels: + self.channels.append(channel.lower()) def remove_from_channel(self, channel, nick, nick_id=None): channel = str(channel) @@ -157,6 +170,8 @@ class BotChannels(): if 'users' not in self.dict['list'][channel.lower()]: self.dict['list'][channel.lower()]['users'] = [] self.dict['list'][channel.lower()]['users'] = [] + if channel.lower() in self.channels: + self.channels.remove(channel.lower()) def channel_scan(self, bot): for channel in list(bot.channels.keys()): @@ -221,5 +236,13 @@ class BotChannels(): def mode(self, bot, trigger): return + def check_channel_bot(self, channel, allchan=False): + if str(channel).lower() in self.channels: + return True + elif allchan and str(channel).lower() in list(self.dict['list'].keys()): + return True + else: + return False + channels = BotChannels() diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index 3271c45..dcb8388 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -19,6 +19,7 @@ from .Logs import logs from .Config import config as botconfig from .Database import db as botdb from .Read import read as botread +from .Channels import channels as botchannels class SpiceBot_Commands_MainSection(StaticSection): @@ -38,7 +39,7 @@ class BotCommands(): 'nickname': {}, 'rule': {} }, - 'disabled': {} + 'disabled': {}, } self.module_files_parse() self.nickrules() @@ -67,17 +68,6 @@ class BotCommands(): return commandstype return None - def get_commands_disabled(self, channel): - if not len(list(self.dict['disabled'])): - self.dict['disabled'] = botdb.get_channel_value(channel, 'commands_disabled') or {} - return self.dict['disabled'] - - def check_commands_disabled(self, command, channel): - if command in list(self.get_commands_disabled(channel).keys()): - return True - else: - return False - def get_realcom(self, command, trigger_command_type): realcom = command @@ -92,18 +82,74 @@ class BotCommands(): return realcom - def set_command_disabled(self, command, channel, timestamp, reason, bywhom): - if not len(list(self.dict['disabled'])): - self.dict['disabled'] = botdb.get_channel_value(channel, 'commands_disabled') or {} - self.dict['disabled'][command] = {"reason": reason, "timestamp": timestamp, "disabledby": bywhom} - botdb.set_channel_value(channel, 'commands_disabled', self.dict['disabled']) + def get_commands_disabled(self, target, disabletype="fully"): + disabletype = str(disabletype) + if disabletype not in list(self.dict['disabled'].keys()): + self.dict['disabled'][disabletype] = { + "users": {}, + "channels": {} + } + if botdb.check_nick_id(target): + if not len(list(self.dict['disabled'][disabletype]["users"])): + self.dict['disabled'][disabletype]["users"] = botdb.get_nick_value(target, 'commands_' + disabletype + 'disabled') or {} + return self.dict['disabled'][disabletype]["users"] + elif botchannels.check_channel_bot(target, True): + if not len(list(self.dict['disabled'][disabletype]["channels"])): + self.dict['disabled'][disabletype]["channels"] = botdb.get_channel_value(target, 'commands_disabled') or {} + return self.dict['disabled'][disabletype]["channels"] + else: + raise Exception(str(target.lower()) + " appears to not be a valid user/channel") - def unset_command_disabled(self, command, channel): - if not len(list(self.dict['disabled'])): - self.dict['disabled'] = botdb.get_channel_value(channel, 'commands_disabled') or {} - if command in list(self.dict['disabled'].keys()): - del self.dict['disabled'][command] - botdb.set_channel_value(channel, 'commands_disabled', self.dict['disabled']) + def check_commands_disabled(self, command, target, disabletype="fully"): + if disabletype not in list(self.dict['disabled'].keys()): + self.dict['disabled'][disabletype] = { + "users": {}, + "channels": {} + } + 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"): + if disabletype not in list(self.dict['disabled'].keys()): + self.dict['disabled'][disabletype] = { + "users": {}, + "channels": {} + } + if botdb.check_nick_id(target): + if not len(list(self.dict['disabled'][disabletype]["users"])): + self.dict['disabled'][disabletype]["users"] = botdb.get_nick_value(target, 'commands_disabled') or {} + self.dict['disabled'][disabletype]["users"][command] = {"reason": reason, "timestamp": timestamp, "disabledby": bywhom} + botdb.set_nick_value(target, 'commands_disabled', self.dict['disabled'][disabletype]["users"]) + elif botchannels.check_channel_bot(target, True): + if not len(list(self.dict['disabled'][disabletype]["channels"])): + self.dict['disabled'][disabletype]["channels"] = botdb.get_channel_value(target, 'commands_disabled') or {} + self.dict['disabled'][disabletype]["channels"][command] = {"reason": reason, "timestamp": timestamp, "disabledby": bywhom} + botdb.set_channel_value(target, 'commands_disabled', self.dict['disabled'][disabletype]["channels"]) + else: + raise Exception(str(target.lower()) + " appears to not be a valid user/channel") + + def unset_command_disabled(self, command, target, timestamp, reason, bywhom, disabletype="fully"): + if disabletype not in list(self.dict['disabled'].keys()): + self.dict['disabled'][disabletype] = { + "users": {}, + "channels": {} + } + if botdb.check_nick_id(target): + if not len(list(self.dict['disabled'][disabletype]["users"])): + self.dict['disabled'][disabletype]["users"] = botdb.get_nick_value(target, 'commands_disabled') or {} + if command in list(self.dict['disabled'][disabletype]["users"].keys()): + del self.dict['disabled'][disabletype]["users"][command] + botdb.set_nick_value(target, 'commands_disabled', self.dict['disabled'][disabletype]["users"]) + elif botchannels.check_channel_bot(target, True): + if not len(list(self.dict['disabled'][disabletype]["channels"])): + self.dict['disabled'][disabletype]["channels"] = botdb.get_channel_value(target, 'commands_disabled') or {} + if command in list(self.dict['disabled'][disabletype]["channels"].keys()): + del self.dict['disabled'][disabletype]["channels"][command] + botdb.set_channel_value(target, 'commands_disabled', self.dict['disabled'][disabletype]["channels"]) + else: + raise Exception(str(target.lower()) + " appears to not be a valid user/channel") def register(self, command_dict): diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index cacccd1..1a4d775 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -15,6 +15,7 @@ import spicemanip from .Tools import command_permissions_check from .Commands import commands as botcommands from .Database import db as botdb +from .Channels import channels as botchannels def prerun(t_command_type='module', t_command_subtype=None): @@ -52,9 +53,13 @@ def prerun(t_command_type='module', t_command_subtype=None): argsdict_list = trigger_argsdict_list(argsdict_default, and_split) # Run the function for all splits + runcount = 0 for argsdict in argsdict_list: + runcount += 1 trigger.sb = copy.deepcopy(argsdict) + trigger.sb["runcount"] = runcount + trigger.sb["args"], trigger.sb["hyphen_arg"] = trigger_hyphen_args(trigger.sb["args"]) if not trigger.sb["hyphen_arg"]: # check if anything prohibits the nick from running the command @@ -127,17 +132,45 @@ def trigger_runstatus(bot, trigger): if trigger.sb["hyphen_arg"]: return False + if trigger.sb["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["realcom"] in list(channel_disabled_list.keys()): + reason = channel_disabled_list[trigger.sb["realcom"]]["reason"] + timestamp = channel_disabled_list[trigger.sb["realcom"]]["timestamp"] + bywhom = channel_disabled_list[trigger.sb["realcom"]]["disabledby"] + message = "The " + str(trigger.sb["com"]) + " 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["realcom"] in list(nick_disabled_list.keys()): + reason = nick_disabled_list[trigger.sb["realcom"]]["reason"] + timestamp = nick_disabled_list[trigger.sb["realcom"]]["timestamp"] + bywhom = nick_disabled_list[trigger.sb["realcom"]]["disabledby"] + message = "The " + str(trigger.sb["com"]) + " 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) + # don't run commands that are disabled in channels if not trigger.is_privmsg: - commandused = trigger.sb["realcom"] - disabled_list = botdb.get_channel_value(trigger.sender, 'commands_disabled') or {} - if commandused in list(disabled_list.keys()): - reason = disabled_list[trigger.sb["realcom"]]["reason"] - timestamp = disabled_list[trigger.sb["realcom"]]["timestamp"] - bywhom = disabled_list[trigger.sb["realcom"]]["disabledby"] - message = "The " + str(trigger.sb["com"]) + " command was disabled by " + bywhom + " in " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) + channel_disabled_list = botcommands.get_commands_disabled(str(trigger.sender), "fully") + if trigger.sb["realcom"] in list(channel_disabled_list.keys()): + reason = channel_disabled_list[trigger.sb["realcom"]]["reason"] + timestamp = channel_disabled_list[trigger.sb["realcom"]]["timestamp"] + bywhom = channel_disabled_list[trigger.sb["realcom"]]["disabledby"] + message = "The " + str(trigger.sb["com"]) + " 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), "fully") + if trigger.sb["realcom"] in list(nick_disabled_list.keys()): + reason = nick_disabled_list[trigger.sb["realcom"]]["reason"] + timestamp = nick_disabled_list[trigger.sb["realcom"]]["timestamp"] + bywhom = nick_disabled_list[trigger.sb["realcom"]]["disabledby"] + message = "The " + str(trigger.sb["com"]) + " 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 True @@ -177,44 +210,102 @@ def trigger_hyphen_arg_handler(bot, trigger): else: bot.osd(trigger.sb["com"] + " is a valid command") return + elif trigger.sb["hyphen_arg"] in [ + 'enable', 'disable', + 'block', 'unblock', + "activate", "deactivate", + "on", "off" + ]: - elif trigger.sb["hyphen_arg"] in ['enable']: + target = spicemanip.main(trigger.sb["args"], 1) or None + if not target: + if trigger.sb["hyphen_arg"] in ['enable', 'unblock', "activate", "on"]: + bot.osd("Who/Where am I enabling " + str(trigger.sb["realcom"]) + " usage for?", trigger.sender) + else: + bot.osd("Who/Where am I disabling " + str(trigger.sb["realcom"]) + " usage for?", trigger.sender) + return + + if not botdb.check_nick_id(target) and not botchannels.check_channel_bot(target, True): + bot.osd("I don't know who/what " + str(target) + " is.", trigger.sender) + return if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): - bot.osd("I was unable to disable this command due to privilege issues.") + if trigger.sb["hyphen_arg"] in ['enable', 'unblock', "activate", "on"]: + bot.osd("I was unable to enable this command for " + str(target) + " due to privilege issues.") + else: + bot.osd("I was unable to disable this command for " + str(target) + " due to privilege issues.") return - if trigger.is_privmsg: - bot.osd("This command must be run in a channel you which to enable it in.", trigger.nick, 'notice') + if trigger.sb["hyphen_arg"] in ['enable', 'unblock', "activate", "on"]: + + if not botcommands.check_commands_disabled(trigger.sb["realcom"], target, "fully"): + bot.osd(trigger.sb["com"] + " is already enabled for " + str(target), trigger.nick, 'notice') + return + + botcommands.unset_command_disabled(trigger.sb["realcom"], target, "fully") + bot.osd(trigger.sb["com"] + " is now enabled for " + str(target)) return - if not botcommands.check_commands_disabled(trigger.sb["realcom"], trigger.sender): - bot.osd(trigger.sb["com"] + " is already enabled in " + str(trigger.sender), trigger.nick, 'notice') + else: + + if botcommands.check_commands_disabled(trigger.sb["realcom"], target, "fully"): + bot.osd(trigger.sb["com"] + " is already disabled for " + str(target), trigger.nick, 'notice') + return + + trailingmessage = spicemanip.main(trigger.sb["args"], 0) or "No reason given." + timestamp = str(datetime.datetime.utcnow()) + + botcommands.set_command_disabled(trigger.sb["realcom"], target, timestamp, trailingmessage, trigger.nick, "fully") + bot.osd(trigger.sb["com"] + " is now disabled for " + str(target)) return - botcommands.unset_command_disabled(trigger.sb["realcom"], trigger.sender) - bot.osd(trigger.sb["com"] + " is now enabled in " + str(trigger.sender)) - return + if trigger.sb["hyphen_arg"] in ['multirun', 'multiruns']: - elif trigger.sb["hyphen_arg"] in ['disable']: + onoff = spicemanip.main(trigger.sb["args"], 1) or None + if not onoff or onoff not in ['enable', 'unblock', "activate", "on"]: + bot.osd("Do you want to enable or disable " + str(trigger.sb["realcom"]) + " multirun usage?", trigger.sender) + return + + target = spicemanip.main(trigger.sb["args"], 1) or None + if not target: + if onoff in ['enable', 'unblock', "activate", "on"]: + bot.osd("Who/Where am I enabling " + str(trigger.sb["realcom"]) + " multirun usage for?", trigger.sender) + else: + bot.osd("Who/Where am I disabling " + str(trigger.sb["realcom"]) + " multirun usage for?", trigger.sender) + return + + if not botdb.check_nick_id(target) and not botchannels.check_channel_bot(target, True): + bot.osd("I don't know who/what " + str(target) + " is.", trigger.sender) + return if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): - bot.osd("I was unable to disable this command due to privilege issues.") + if onoff in ['enable', 'unblock', "activate", "on"]: + bot.osd("I was unable to enable multirun usage on " + str(trigger.sb["realcom"]) + " for " + str(target) + " due to privilege issues.") + else: + bot.osd("I was unable to enable multirun usage on " + str(trigger.sb["realcom"]) + " for " + str(target) + " due to privilege issues.") return - if trigger.is_privmsg: - bot.osd("This command must be run in a channel you which to disable it in.", trigger.nick, 'notice') + if onoff in ['enable', 'unblock', "activate", "on"]: + + if not botcommands.check_commands_disabled(trigger.sb["realcom"], target, "multirun"): + bot.osd(trigger.sb["com"] + " multirun is already enabled for " + str(target), trigger.nick, 'notice') + return + + botcommands.unset_command_disabled(trigger.sb["realcom"], target, "multirun") + bot.osd(trigger.sb["com"] + " multirun is now enabled for " + str(target)) return - if botcommands.check_commands_disabled(trigger.sb["realcom"], trigger.sender): - bot.osd(trigger.sb["com"] + " is already disabled in " + str(trigger.sender), trigger.nick, 'notice') + else: + + if botcommands.check_commands_disabled(trigger.sb["realcom"], target, "multirun"): + bot.osd(trigger.sb["com"] + " multirun is already disabled for " + str(target), trigger.nick, 'notice') + return + + trailingmessage = spicemanip.main(trigger.sb["args"], 0) or "No reason given." + timestamp = str(datetime.datetime.utcnow()) + + botcommands.set_command_disabled(trigger.sb["realcom"], target, timestamp, trailingmessage, trigger.nick, "multirun") + bot.osd(trigger.sb["com"] + " multirun is now 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["realcom"], trigger.sender, timestamp, trailingmessage, trigger.nick) - bot.osd(trigger.sb["com"] + " is now disabled in " + str(trigger.sender)) - return - return diff --git a/sopel_modules/SpiceBot/Users.py b/sopel_modules/SpiceBot/Users.py index 6a54912..6fe13f4 100644 --- a/sopel_modules/SpiceBot/Users.py +++ b/sopel_modules/SpiceBot/Users.py @@ -231,5 +231,9 @@ class BotUsers(): def targetcheck(self): return True + # idk whois + if not botdb.check_nick_id(posstarget): + return + users = BotUsers() From 9a52fe983b753468ae60aeea7ded90a34cb39c3a Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 11:03:19 -0400 Subject: [PATCH 03/23] fix --- 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 dcb8388..68120d8 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -130,7 +130,7 @@ class BotCommands(): else: raise Exception(str(target.lower()) + " appears to not be a valid user/channel") - def unset_command_disabled(self, command, target, timestamp, reason, bywhom, disabletype="fully"): + def unset_command_disabled(self, command, disabletype="fully"): if disabletype not in list(self.dict['disabled'].keys()): self.dict['disabled'][disabletype] = { "users": {}, From 8bbfbf4bd60ff575ab2f24ce04bd3d93e262b4cd Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 11:03:36 -0400 Subject: [PATCH 04/23] really fix --- 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 68120d8..9a2ff27 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -130,7 +130,7 @@ class BotCommands(): else: raise Exception(str(target.lower()) + " appears to not be a valid user/channel") - def unset_command_disabled(self, command, disabletype="fully"): + def unset_command_disabled(self, command, target, disabletype="fully"): if disabletype not in list(self.dict['disabled'].keys()): self.dict['disabled'][disabletype] = { "users": {}, From fca8bb4fb5b2b80c104d1bd2c128a9020010628e Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 13:00:21 -0400 Subject: [PATCH 05/23] first messagelog test --- sopel_modules/SpiceBot/MessageLog.py | 138 +++++++++++++++++++++++++++ sopel_modules/SpiceBot/Prerun.py | 78 ++++++++++----- sopel_modules/SpiceBot/__init__.py | 1 + 3 files changed, 193 insertions(+), 24 deletions(-) create mode 100644 sopel_modules/SpiceBot/MessageLog.py diff --git a/sopel_modules/SpiceBot/MessageLog.py b/sopel_modules/SpiceBot/MessageLog.py new file mode 100644 index 0000000..6ec25ad --- /dev/null +++ b/sopel_modules/SpiceBot/MessageLog.py @@ -0,0 +1,138 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +""" +This is the SpiceBot Message Log system. +""" + +import uuid + + +class MessageLog(): + + def __init__(self): + self.dict = {} + self.message_display = dict() + self.used_ids = [0] + self.error_message_dict = { + "command_inchan_only": "$command must be run in channel.", + "admin_switch_unauth": "The admin switch (-a) is for use by authorized nicks ONLY.", + } + + def messagelog_assign(self): + unique_id = 0 + while unique_id in self.used_ids: + unique_id = uuid.uuid4() + self.used_ids.append(unique_id) + return unique_id + + def messagelog_start(self, bot, trigger, log_id): + + if not trigger.is_privmsg: + channelname = None + else: + channelname = trigger.sender + + self.message_display[log_id] = { + "trigger": { + "nick": trigger.nick, + "sender": channelname, + }, + "bot": { + "nick": bot.nick + }, + "messages": [], + } + + def messagelog_error(self, log_id, error_id): + + newloglist = [] + error_exists_prior = False + + for existing_messagedict in self.message_display[log_id]["messages"]: + if existing_messagedict["type"] == "error": + if existing_messagedict["error_id"] == error_id: + error_exists_prior = True + existing_messagedict["count"] += 1 + newloglist.append(existing_messagedict) + + if not error_exists_prior: + newmessagedict = {"type": "error", "error_id": error_id, "count": 1} + newloglist.append(newmessagedict) + + self.message_display[log_id]["messages"] = newloglist + + def messagelog(self, log_id, message, recipients=None): + + if not recipients: + if self.message_display[log_id]["trigger"]["sender"]: + recipients = self.message_display[log_id]["trigger"]["sender"] + else: + recipients = self.message_display[log_id]["trigger"]["nick"] + + messagedict = {"type": "normal", "message": message, "recipients": recipients} + + self.message_display[log_id]["messages"].append(messagedict) + + def messagelog_exit(self, bot, log_id): + + current_messages = [] + current_errors = [] + + for messagedict in self.message_display[log_id]["messages"]: + + if messagedict["type"] == "error": + if messagedict["error_id"] not in self.error_message_dict.keys(): + message = "Error missing for ID '" + str(messagedict["error_id"]) + "'" + else: + message = self.error_message_dict[messagedict["error_id"]] + message += " (" + str(messagedict["count"]) + ")" + message = self.messagelog_fillin(bot, message, log_id) + current_errors.append(message) + else: + if len(current_errors): + currenterrordict = {"type": "error", "message": current_errors} + current_messages.append(currenterrordict) + current_errors = [] + message = messagedict["message"] + current_messages.append(messagedict) + if len(current_errors): + currenterrordict = {"type": "error", "message": current_errors} + current_messages.append(currenterrordict) + current_errors = [] + + for messagedict in current_messages: + if messagedict["type"] == 'error': + bot.osd(messagedict['message'], self.message_display[log_id]["trigger"]["nick"], 'notice') + else: + bot.osd(messagedict['message'], messagedict["recipients"], 'say') + + self.messagelog_kill(log_id) + + def messagelog_fillin(self, message, log_id): + + for botval in ["nick"]: + fullbotval = str("$bot." + botval) + fullbotvaleval = self.message_display[log_id]["bot"][botval] + if fullbotval in message: + message = str(message.replace(fullbotval, fullbotvaleval)) + + for triggerval in ["nick", "sender"]: + fulltriggerval = str("$trigger." + triggerval) + fulltriggervaleval = self.message_display[log_id]["trigger"][triggerval] + if fulltriggerval in message: + if fulltriggervaleval: + message = str(message.replace(fulltriggerval, fulltriggervaleval)) + else: + if triggerval == "sender": + message = str(message.replace("$trigger.sender", 'privmsg')) + else: + message = str(message.replace(fulltriggerval, str(fulltriggervaleval))) + + return message + + def messagelog_kill(self, log_id): + if log_id in self.message_display: + del self.message_display[log_id] + + +messagelog = MessageLog() diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 1a4d775..e740c28 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -16,6 +16,7 @@ from .Tools import command_permissions_check from .Commands import commands as botcommands from .Database import db as botdb from .Channels import channels as botchannels +from .MessageLog import messagelog as botmessagelog def prerun(t_command_type='module', t_command_subtype=None): @@ -43,6 +44,9 @@ def prerun(t_command_type='module', t_command_subtype=None): argsdict_default["type"] = trigger_command_type argsdict_default["com"] = trigger_command + # messagelog ID + argsdict_default["log_id"] = botmessagelog.messagelog_assign() + realcom = botcommands.get_realcom(argsdict_default["com"], trigger_command_type) argsdict_default["realcom"] = realcom @@ -53,6 +57,7 @@ def prerun(t_command_type='module', t_command_subtype=None): argsdict_list = trigger_argsdict_list(argsdict_default, and_split) # Run the function for all splits + botmessagelog.messagelog_start(bot, trigger, argsdict_default["log_id"]) runcount = 0 for argsdict in argsdict_list: runcount += 1 @@ -67,6 +72,7 @@ def prerun(t_command_type='module', t_command_subtype=None): function(bot, trigger, *args, **kwargs) else: trigger_hyphen_arg_handler(bot, trigger) + botmessagelog.messagelog_exit(bot, argsdict_default["log_id"]) return internal_prerun return actual_decorator @@ -126,7 +132,7 @@ def trigger_runstatus(bot, trigger): if command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): return True else: - bot.osd("The admin switch (-a) is for use by authorized nicks ONLY.", 'notice') + botmessagelog.messagelog_error(trigger.sb["log_id"], "The admin switch (-a) is for use by authorized nicks ONLY.") return False if trigger.sb["hyphen_arg"]: @@ -176,9 +182,9 @@ def trigger_runstatus(bot, trigger): def trigger_cant_run(bot, trigger, message=None): if message: - bot.osd(message, trigger.nick, 'notice') + botmessagelog.messagelog_error(trigger.sb["log_id"], message) if command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): - bot.osd("You however are authorized to bypass this warning with the (-a) admin switch.", trigger.nick, 'notice') + botmessagelog.messagelog_error(trigger.sb["log_id"], "You however are authorized to bypass this warning with the (-a) admin switch.") return False @@ -206,9 +212,9 @@ def trigger_hyphen_arg_handler(bot, trigger): # Commands that cannot run via privmsg if trigger.sb["hyphen_arg"] in ['check']: if trigger.sb["com"].lower() != trigger.sb["realcom"]: - bot.osd(trigger.sb["com"] + " is a valid alias command for " + trigger.sb["realcom"]) + botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + " is a valid alias command for " + trigger.sb["realcom"]) else: - bot.osd(trigger.sb["com"] + " is a valid command") + botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + " is a valid command") return elif trigger.sb["hyphen_arg"] in [ 'enable', 'disable', @@ -220,92 +226,116 @@ def trigger_hyphen_arg_handler(bot, trigger): target = spicemanip.main(trigger.sb["args"], 1) or None if not target: if trigger.sb["hyphen_arg"] in ['enable', 'unblock', "activate", "on"]: - bot.osd("Who/Where am I enabling " + str(trigger.sb["realcom"]) + " usage for?", trigger.sender) + botmessagelog.messagelog_error(trigger.sb["log_id"], "Who/Where am I enabling " + str(trigger.sb["realcom"]) + " usage for?") else: - bot.osd("Who/Where am I disabling " + str(trigger.sb["realcom"]) + " usage for?", trigger.sender) + botmessagelog.messagelog_error(trigger.sb["log_id"], "Who/Where am I disabling " + str(trigger.sb["realcom"]) + " usage for?") return if not botdb.check_nick_id(target) and not botchannels.check_channel_bot(target, True): - bot.osd("I don't know who/what " + str(target) + " is.", trigger.sender) + botmessagelog.messagelog_error(trigger.sb["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 trigger.sb["hyphen_arg"] in ['enable', 'unblock', "activate", "on"]: - bot.osd("I was unable to enable this command for " + str(target) + " due to privilege issues.") + botmessagelog.messagelog_error(trigger.sb["log_id"], "I was unable to enable this command for " + str(target) + " due to privilege issues.") else: - bot.osd("I was unable to disable this command for " + str(target) + " due to privilege issues.") + botmessagelog.messagelog_error(trigger.sb["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 not botcommands.check_commands_disabled(trigger.sb["realcom"], target, "fully"): - bot.osd(trigger.sb["com"] + " is already enabled for " + str(target), trigger.nick, 'notice') + botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["com"] + " is already enabled for " + str(target)) return botcommands.unset_command_disabled(trigger.sb["realcom"], target, "fully") - bot.osd(trigger.sb["com"] + " is now enabled for " + str(target)) + botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + " is now enabled for " + str(target)) return else: if botcommands.check_commands_disabled(trigger.sb["realcom"], target, "fully"): - bot.osd(trigger.sb["com"] + " is already disabled for " + str(target), trigger.nick, 'notice') + botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["com"] + " 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["realcom"], target, timestamp, trailingmessage, trigger.nick, "fully") - bot.osd(trigger.sb["com"] + " is now disabled for " + str(target)) + botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + " is now disabled for " + str(target)) return if trigger.sb["hyphen_arg"] in ['multirun', 'multiruns']: onoff = spicemanip.main(trigger.sb["args"], 1) or None if not onoff or onoff not in ['enable', 'unblock', "activate", "on"]: - bot.osd("Do you want to enable or disable " + str(trigger.sb["realcom"]) + " multirun usage?", trigger.sender) + botmessagelog.messagelog_error(trigger.sb["log_id"], "Do you want to enable or disable " + str(trigger.sb["realcom"]) + " multirun usage?") return target = spicemanip.main(trigger.sb["args"], 1) or None if not target: if onoff in ['enable', 'unblock', "activate", "on"]: - bot.osd("Who/Where am I enabling " + str(trigger.sb["realcom"]) + " multirun usage for?", trigger.sender) + botmessagelog.messagelog_error(trigger.sb["log_id"], "Who/Where am I enabling " + str(trigger.sb["realcom"]) + " multirun usage for?") else: - bot.osd("Who/Where am I disabling " + str(trigger.sb["realcom"]) + " multirun usage for?", trigger.sender) + botmessagelog.messagelog_error(trigger.sb["log_id"], "Who/Where am I disabling " + str(trigger.sb["realcom"]) + " multirun usage for?") return if not botdb.check_nick_id(target) and not botchannels.check_channel_bot(target, True): - bot.osd("I don't know who/what " + str(target) + " is.", trigger.sender) + botmessagelog.messagelog_error(trigger.sb["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 onoff in ['enable', 'unblock', "activate", "on"]: - bot.osd("I was unable to enable multirun usage on " + str(trigger.sb["realcom"]) + " for " + str(target) + " due to privilege issues.") + botmessagelog.messagelog_error(trigger.sb["log_id"], "I was unable to enable multirun usage on " + str(trigger.sb["realcom"]) + " for " + str(target) + " due to privilege issues.") else: - bot.osd("I was unable to enable multirun usage on " + str(trigger.sb["realcom"]) + " for " + str(target) + " due to privilege issues.") + botmessagelog.messagelog_error(trigger.sb["log_id"], "I was unable to enable multirun usage on " + str(trigger.sb["realcom"]) + " for " + str(target) + " due to privilege issues.") return if onoff in ['enable', 'unblock', "activate", "on"]: if not botcommands.check_commands_disabled(trigger.sb["realcom"], target, "multirun"): - bot.osd(trigger.sb["com"] + " multirun is already enabled for " + str(target), trigger.nick, 'notice') + botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["com"] + " multirun is already enabled for " + str(target)) return botcommands.unset_command_disabled(trigger.sb["realcom"], target, "multirun") - bot.osd(trigger.sb["com"] + " multirun is now enabled for " + str(target)) + botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + " multirun is now enabled for " + str(target)) return else: if botcommands.check_commands_disabled(trigger.sb["realcom"], target, "multirun"): - bot.osd(trigger.sb["com"] + " multirun is already disabled for " + str(target), trigger.nick, 'notice') + botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["com"] + " multirun 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["realcom"], target, timestamp, trailingmessage, trigger.nick, "multirun") - bot.osd(trigger.sb["com"] + " multirun is now disabled for " + str(target)) + botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + " multirun is now disabled for " + str(target)) return + elif trigger.sb["hyphen_arg"] in ['example', 'usage']: + botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + ": " + str(trigger.sb["example"])) + return + + elif trigger.sb["hyphen_arg"] in ['filename', 'filepath']: + botmessagelog.messagelog(trigger.sb["log_id"], "The " + str(trigger.sb["com"]) + " file is located at " + str(trigger.sb[trigger.sb["hyphen_arg"]])) + return + + elif trigger.sb["hyphen_arg"] in ['foldername', 'folderpath']: + botmessagelog.messagelog(trigger.sb["log_id"], "The " + str(trigger.sb["com"]) + " folder is located at " + str(trigger.sb[trigger.sb["hyphen_arg"]])) + return + + elif trigger.sb["hyphen_arg"] in ['author']: + botmessagelog.messagelog(trigger.sb["log_id"], "The author of the " + str(trigger.sb["com"]) + " command is " + trigger.sb["author"] + ".") + return + + elif trigger.sb["hyphen_arg"] in ['contribs', 'contrib', "contributors"]: + botmessagelog.messagelog(trigger.sb["log_id"], "The contributors of the " + str(trigger.sb["com"]) + " command are " + spicemanip.main(trigger.sb["contributors"], "andlist") + ".") + return + + elif trigger.sb["hyphen_arg"] in ['alias', 'aliases']: + botmessagelog.messagelog(trigger.sb["log_id"], "The alaises of the " + str(trigger.sb["com"]) + " command are " + spicemanip.main(trigger.sb["validcoms"], "andlist") + ".") + return + return diff --git a/sopel_modules/SpiceBot/__init__.py b/sopel_modules/SpiceBot/__init__.py index 31db45c..95f1e36 100644 --- a/sopel_modules/SpiceBot/__init__.py +++ b/sopel_modules/SpiceBot/__init__.py @@ -9,6 +9,7 @@ This module contains references only for other modules to utilize. from .Config import * from .Logs import * from .Database import * +from .MessageLog import * from .Update import * from .osd import * From 705638e9b364317e61603338317bd3210dbf5287 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 13:16:33 -0400 Subject: [PATCH 06/23] test --- sopel_modules/SpiceBot/MessageLog.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sopel_modules/SpiceBot/MessageLog.py b/sopel_modules/SpiceBot/MessageLog.py index 6ec25ad..132f635 100644 --- a/sopel_modules/SpiceBot/MessageLog.py +++ b/sopel_modules/SpiceBot/MessageLog.py @@ -101,8 +101,22 @@ class MessageLog(): current_errors = [] for messagedict in current_messages: + + if not isinstance(messagedict["recipients"], list): + messagedict["recipients"] == [messagedict["recipients"]] + if messagedict["type"] == 'error': bot.osd(messagedict['message'], self.message_display[log_id]["trigger"]["nick"], 'notice') + + elif len(messagedict["recipients"]) > 1: + bot.osd(messagedict['message'], messagedict["recipients"], 'notice') + + elif len(messagedict["recipients"]) == 1: + if messagedict["recipients"][0] == self.message_display[log_id]["trigger"]["nick"]: + bot.osd(messagedict['message'], self.message_display[log_id]["trigger"]["nick"], 'notice') + else: + bot.osd(messagedict['message'], messagedict["recipients"], 'say') + else: bot.osd(messagedict['message'], messagedict["recipients"], 'say') From 0f874ecc84082c3a2e22703aa3e60d8bc5961554 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 13:17:55 -0400 Subject: [PATCH 07/23] oops --- sopel_modules/SpiceBot/MessageLog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/MessageLog.py b/sopel_modules/SpiceBot/MessageLog.py index 132f635..6f8060d 100644 --- a/sopel_modules/SpiceBot/MessageLog.py +++ b/sopel_modules/SpiceBot/MessageLog.py @@ -27,7 +27,7 @@ class MessageLog(): def messagelog_start(self, bot, trigger, log_id): - if not trigger.is_privmsg: + if trigger.is_privmsg: channelname = None else: channelname = trigger.sender From c312c1e51666c17ea3e5f87db548416c00d0754b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 13:23:15 -0400 Subject: [PATCH 08/23] not privmsg --- sopel_modules/SpiceBot/MessageLog.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot/MessageLog.py b/sopel_modules/SpiceBot/MessageLog.py index 6f8060d..e375a21 100644 --- a/sopel_modules/SpiceBot/MessageLog.py +++ b/sopel_modules/SpiceBot/MessageLog.py @@ -27,10 +27,10 @@ class MessageLog(): def messagelog_start(self, bot, trigger, log_id): - if trigger.is_privmsg: - channelname = None - else: + if not trigger.is_privmsg: channelname = trigger.sender + else: + channelname = None self.message_display[log_id] = { "trigger": { @@ -61,6 +61,10 @@ class MessageLog(): self.message_display[log_id]["messages"] = newloglist + def messagelog_error_admins(self, log_id, message): + # TODO + return + def messagelog(self, log_id, message, recipients=None): if not recipients: From c1d8845ade46a0910c2cffd12b72220c931d87e2 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 13:25:12 -0400 Subject: [PATCH 09/23] test --- sopel_modules/SpiceBot/MessageLog.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sopel_modules/SpiceBot/MessageLog.py b/sopel_modules/SpiceBot/MessageLog.py index e375a21..af85e55 100644 --- a/sopel_modules/SpiceBot/MessageLog.py +++ b/sopel_modules/SpiceBot/MessageLog.py @@ -110,18 +110,23 @@ class MessageLog(): messagedict["recipients"] == [messagedict["recipients"]] if messagedict["type"] == 'error': + bot.say("here a") bot.osd(messagedict['message'], self.message_display[log_id]["trigger"]["nick"], 'notice') elif len(messagedict["recipients"]) > 1: + bot.say("here b") bot.osd(messagedict['message'], messagedict["recipients"], 'notice') elif len(messagedict["recipients"]) == 1: if messagedict["recipients"][0] == self.message_display[log_id]["trigger"]["nick"]: + bot.say("here c") bot.osd(messagedict['message'], self.message_display[log_id]["trigger"]["nick"], 'notice') else: + bot.say("here d") bot.osd(messagedict['message'], messagedict["recipients"], 'say') else: + bot.say("here e") bot.osd(messagedict['message'], messagedict["recipients"], 'say') self.messagelog_kill(log_id) From ebb5dd398eff78b3da9c4f2c5660a9978286c3a2 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 13:26:17 -0400 Subject: [PATCH 10/23] test --- sopel_modules/SpiceBot/MessageLog.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sopel_modules/SpiceBot/MessageLog.py b/sopel_modules/SpiceBot/MessageLog.py index af85e55..ba57369 100644 --- a/sopel_modules/SpiceBot/MessageLog.py +++ b/sopel_modules/SpiceBot/MessageLog.py @@ -115,6 +115,7 @@ class MessageLog(): elif len(messagedict["recipients"]) > 1: bot.say("here b") + bot.say(str(messagedict["recipients"])) bot.osd(messagedict['message'], messagedict["recipients"], 'notice') elif len(messagedict["recipients"]) == 1: From 4454867c3014f31c14cddd5016f92bbf54684182 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 13:30:50 -0400 Subject: [PATCH 11/23] test --- sopel_modules/SpiceBot/MessageLog.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sopel_modules/SpiceBot/MessageLog.py b/sopel_modules/SpiceBot/MessageLog.py index ba57369..7beed9b 100644 --- a/sopel_modules/SpiceBot/MessageLog.py +++ b/sopel_modules/SpiceBot/MessageLog.py @@ -69,9 +69,12 @@ class MessageLog(): if not recipients: if self.message_display[log_id]["trigger"]["sender"]: - recipients = self.message_display[log_id]["trigger"]["sender"] + recipients = [self.message_display[log_id]["trigger"]["sender"]] else: - recipients = self.message_display[log_id]["trigger"]["nick"] + recipients = [self.message_display[log_id]["trigger"]["nick"]] + + if not isinstance(recipients, list): + recipients == [recipients] messagedict = {"type": "normal", "message": message, "recipients": recipients} @@ -106,9 +109,6 @@ class MessageLog(): for messagedict in current_messages: - if not isinstance(messagedict["recipients"], list): - messagedict["recipients"] == [messagedict["recipients"]] - if messagedict["type"] == 'error': bot.say("here a") bot.osd(messagedict['message'], self.message_display[log_id]["trigger"]["nick"], 'notice') From a6f20745f9b85c5075a26961bcbd2f9ec7a2bfbd Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 13:36:33 -0400 Subject: [PATCH 12/23] future planning --- sopel_modules/SpiceBot/MessageLog.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/sopel_modules/SpiceBot/MessageLog.py b/sopel_modules/SpiceBot/MessageLog.py index 7beed9b..3fcc485 100644 --- a/sopel_modules/SpiceBot/MessageLog.py +++ b/sopel_modules/SpiceBot/MessageLog.py @@ -6,6 +6,8 @@ This is the SpiceBot Message Log system. import uuid +from .Config import config as botconfig + class MessageLog(): @@ -61,7 +63,9 @@ class MessageLog(): self.message_display[log_id]["messages"] = newloglist - def messagelog_error_admins(self, log_id, message): + def messagelog_error_admins(self, bot, log_id, message): + recipients = list(botconfig.admins) + bot.osd(["Attention Bot Admin: ", message], recipients, 'notice') # TODO return @@ -110,24 +114,18 @@ class MessageLog(): for messagedict in current_messages: if messagedict["type"] == 'error': - bot.say("here a") bot.osd(messagedict['message'], self.message_display[log_id]["trigger"]["nick"], 'notice') elif len(messagedict["recipients"]) > 1: - bot.say("here b") - bot.say(str(messagedict["recipients"])) bot.osd(messagedict['message'], messagedict["recipients"], 'notice') elif len(messagedict["recipients"]) == 1: if messagedict["recipients"][0] == self.message_display[log_id]["trigger"]["nick"]: - bot.say("here c") bot.osd(messagedict['message'], self.message_display[log_id]["trigger"]["nick"], 'notice') else: - bot.say("here d") bot.osd(messagedict['message'], messagedict["recipients"], 'say') else: - bot.say("here e") bot.osd(messagedict['message'], messagedict["recipients"], 'say') self.messagelog_kill(log_id) From 39d2b179b279191000567e900f87d5b03b000227 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 13:45:05 -0400 Subject: [PATCH 13/23] more --- sopel_modules/SpiceBot/Prerun.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index e740c28..37aed7f 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -211,11 +211,18 @@ def trigger_hyphen_arg_handler(bot, trigger): # Commands that cannot run via privmsg if trigger.sb["hyphen_arg"] in ['check']: - if trigger.sb["com"].lower() != trigger.sb["realcom"]: - botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + " is a valid alias command for " + trigger.sb["realcom"]) + if trigger.sb["type"] == 'nickname': + if trigger.sb["com"].lower() != trigger.sb["realcom"]: + botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + " is a valid alias command for " + bot.nick + " " + trigger.sb["realcom"]) + else: + botmessagelog.messagelog(trigger.sb["log_id"], bot.nick + " " + trigger.sb["com"] + " is a valid command") else: - botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + " is a valid command") + if trigger.sb["com"].lower() != trigger.sb["realcom"]: + botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + " is a valid alias command for " + trigger.sb["realcom"]) + else: + botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + " is a valid command") return + elif trigger.sb["hyphen_arg"] in [ 'enable', 'disable', 'block', 'unblock', From ed7d0545e36b34080faac0eb630d85f76d92b61f Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 14:00:56 -0400 Subject: [PATCH 14/23] update valid list --- sopel_modules/SpiceBot/Prerun.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 37aed7f..ac397fc 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -191,7 +191,17 @@ def trigger_cant_run(bot, trigger, message=None): def trigger_hyphen_args(trigger_args_part): valid_hyphen_args = [ 'check', - 'enable', 'disable' + 'enable', 'disable', + 'block', 'unblock', + "activate", "deactivate", + "on", "off", + 'multirun', 'multiruns', + 'example', 'usage', + 'filename', 'filepath', + 'foldername', 'folderpath', + "author", + 'contribs', 'contrib', "contributors", + 'alias', 'aliases' ] hyphen_args = [] trigger_args_unhyphend = [] From 6806d6c1b2caf09f161a482f44524ca2aa3e78c7 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 14:10:51 -0400 Subject: [PATCH 15/23] test --- sopel_modules/SpiceBot/Commands.py | 9 +++++++++ sopel_modules/SpiceBot/Prerun.py | 17 +++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index 9a2ff27..891b5c3 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -11,6 +11,7 @@ from sopel.config.types import StaticSection, ValidatedAttribute import os import threading +import copy import spicemanip import sopel_modules @@ -68,6 +69,14 @@ class BotCommands(): return commandstype return None + def get_command_dict(self, command, trigger_command_type=None): + if not trigger_command_type: + trigger_command_type = self.find_command_type(command) + if not trigger_command_type: + return {} + command_dict = copy.deepcopy(self.dict['commands'][trigger_command_type][command]) + return command_dict + def get_realcom(self, command, trigger_command_type): realcom = command diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index ac397fc..7d5586a 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -47,8 +47,9 @@ def prerun(t_command_type='module', t_command_subtype=None): # messagelog ID argsdict_default["log_id"] = botmessagelog.messagelog_assign() - realcom = botcommands.get_realcom(argsdict_default["com"], trigger_command_type) - argsdict_default["realcom"] = realcom + argsdict_default["realcom"] = botcommands.get_realcom(argsdict_default["com"], trigger_command_type) + + argsdict_default["dict"] = botcommands.get_command_dict(argsdict_default["realcom"], trigger_command_type) # split into && groupings and_split = trigger_and_split(trigger_args) @@ -332,27 +333,27 @@ def trigger_hyphen_arg_handler(bot, trigger): return elif trigger.sb["hyphen_arg"] in ['example', 'usage']: - botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + ": " + str(trigger.sb["example"])) + botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + ": " + str(trigger.sb["dict"]["example"])) return elif trigger.sb["hyphen_arg"] in ['filename', 'filepath']: - botmessagelog.messagelog(trigger.sb["log_id"], "The " + str(trigger.sb["com"]) + " file is located at " + str(trigger.sb[trigger.sb["hyphen_arg"]])) + botmessagelog.messagelog(trigger.sb["log_id"], "The " + str(trigger.sb["com"]) + " file is located at " + str(trigger.sb["dict"][trigger.sb["hyphen_arg"]])) return elif trigger.sb["hyphen_arg"] in ['foldername', 'folderpath']: - botmessagelog.messagelog(trigger.sb["log_id"], "The " + str(trigger.sb["com"]) + " folder is located at " + str(trigger.sb[trigger.sb["hyphen_arg"]])) + botmessagelog.messagelog(trigger.sb["log_id"], "The " + str(trigger.sb["com"]) + " folder is located at " + str(trigger.sb["dict"][trigger.sb["hyphen_arg"]])) return elif trigger.sb["hyphen_arg"] in ['author']: - botmessagelog.messagelog(trigger.sb["log_id"], "The author of the " + str(trigger.sb["com"]) + " command is " + trigger.sb["author"] + ".") + botmessagelog.messagelog(trigger.sb["log_id"], "The author of the " + str(trigger.sb["com"]) + " command is " + trigger.sb["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["com"]) + " command are " + spicemanip.main(trigger.sb["contributors"], "andlist") + ".") + botmessagelog.messagelog(trigger.sb["log_id"], "The contributors of the " + str(trigger.sb["com"]) + " command are " + spicemanip.main(trigger.sb["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["com"]) + " command are " + spicemanip.main(trigger.sb["validcoms"], "andlist") + ".") + botmessagelog.messagelog(trigger.sb["log_id"], "The alaises of the " + str(trigger.sb["com"]) + " command are " + spicemanip.main(trigger.sb["dict"]["validcoms"], "andlist") + ".") return return From 87ca5c1398314737749bc108819a80ad1cd08ff7 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 14:31:01 -0400 Subject: [PATCH 16/23] fix --- sopel_modules/SpiceBot/MessageLog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/MessageLog.py b/sopel_modules/SpiceBot/MessageLog.py index 3fcc485..3217296 100644 --- a/sopel_modules/SpiceBot/MessageLog.py +++ b/sopel_modules/SpiceBot/MessageLog.py @@ -97,7 +97,7 @@ class MessageLog(): else: message = self.error_message_dict[messagedict["error_id"]] message += " (" + str(messagedict["count"]) + ")" - message = self.messagelog_fillin(bot, message, log_id) + message = self.messagelog_fillin(message, log_id) current_errors.append(message) else: if len(current_errors): From b323833c59d908a139641315824669be0cd30b36 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 14:44:08 -0400 Subject: [PATCH 17/23] test --- sopel_modules/SpiceBot/MessageLog.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sopel_modules/SpiceBot/MessageLog.py b/sopel_modules/SpiceBot/MessageLog.py index 3217296..ae2917f 100644 --- a/sopel_modules/SpiceBot/MessageLog.py +++ b/sopel_modules/SpiceBot/MessageLog.py @@ -15,6 +15,7 @@ class MessageLog(): self.dict = {} self.message_display = dict() self.used_ids = [0] + self.used_error_ids = [0] self.error_message_dict = { "command_inchan_only": "$command must be run in channel.", "admin_switch_unauth": "The admin switch (-a) is for use by authorized nicks ONLY.", @@ -27,6 +28,17 @@ class MessageLog(): self.used_ids.append(unique_id) return unique_id + def messagelog_error_get(self, errormsg): + for error_id in list(self.error_message_dict.keys()): + if self.error_message_dict[error_id] == errormsg: + return error_id + unique_id = 0 + while unique_id in self.used_error_ids: + unique_id = uuid.uuid4() + self.used_error_ids.append(unique_id) + self.error_message_dict[unique_id] = errormsg + return unique_id + def messagelog_start(self, bot, trigger, log_id): if not trigger.is_privmsg: @@ -50,6 +62,9 @@ class MessageLog(): newloglist = [] error_exists_prior = False + if error_id not in self.error_message_dict: + error_id = self.messagelog_error_get(error_id) + for existing_messagedict in self.message_display[log_id]["messages"]: if existing_messagedict["type"] == "error": if existing_messagedict["error_id"] == error_id: From 2c913d062cc27aec84f6724dc7fe2ce3bf03b944 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 14:48:50 -0400 Subject: [PATCH 18/23] allow self-dsaible --- sopel_modules/SpiceBot/Prerun.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 7d5586a..629d104 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -241,7 +241,7 @@ def trigger_hyphen_arg_handler(bot, trigger): "on", "off" ]: - target = spicemanip.main(trigger.sb["args"], 1) or None + target = spicemanip.main(trigger.sb["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["realcom"]) + " usage for?") @@ -254,11 +254,12 @@ def trigger_hyphen_arg_handler(bot, trigger): return if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): - 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.") - else: - botmessagelog.messagelog_error(trigger.sb["log_id"], "I was unable to disable this command for " + str(target) + " due to privilege issues.") - return + 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.") + else: + botmessagelog.messagelog_error(trigger.sb["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"]: @@ -290,7 +291,7 @@ def trigger_hyphen_arg_handler(bot, trigger): botmessagelog.messagelog_error(trigger.sb["log_id"], "Do you want to enable or disable " + str(trigger.sb["realcom"]) + " multirun usage?") return - target = spicemanip.main(trigger.sb["args"], 1) or None + target = spicemanip.main(trigger.sb["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["realcom"]) + " multirun usage for?") @@ -303,11 +304,12 @@ def trigger_hyphen_arg_handler(bot, trigger): return if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): - 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["realcom"]) + " 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["realcom"]) + " for " + str(target) + " due to privilege issues.") - return + 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["realcom"]) + " 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["realcom"]) + " for " + str(target) + " due to privilege issues.") + return if onoff in ['enable', 'unblock', "activate", "on"]: From 6e59a1aa8aabe2bee7907a7704ddc0dd3feb6b5d Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 14:58:28 -0400 Subject: [PATCH 19/23] test --- sopel_modules/SpiceBot/Prerun.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 629d104..b93076e 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -153,11 +153,15 @@ def trigger_runstatus(bot, trigger): # don't run commands that are disabled for specific users nick_disabled_list = botcommands.get_commands_disabled(str(trigger.nick), "multirun") if trigger.sb["realcom"] in list(nick_disabled_list.keys()): - reason = nick_disabled_list[trigger.sb["realcom"]]["reason"] - timestamp = nick_disabled_list[trigger.sb["realcom"]]["timestamp"] bywhom = nick_disabled_list[trigger.sb["realcom"]]["disabledby"] - message = "The " + str(trigger.sb["com"]) + " 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) + if bywhom != trigger.nick: + reason = nick_disabled_list[trigger.sb["realcom"]]["reason"] + timestamp = nick_disabled_list[trigger.sb["realcom"]]["timestamp"] + message = "The " + str(trigger.sb["com"]) + " 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["realcom"], trigger.nick, "multirun") + botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["com"] + " multirun is now enabled for " + str(trigger.nick)) # don't run commands that are disabled in channels if not trigger.is_privmsg: @@ -168,15 +172,19 @@ def trigger_runstatus(bot, trigger): bywhom = channel_disabled_list[trigger.sb["realcom"]]["disabledby"] message = "The " + str(trigger.sb["com"]) + " 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["realcom"], trigger.nick, "fully") + botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["com"] + " multirun is now enabled for " + str(trigger.nick)) # don't run commands that are disabled for specific users nick_disabled_list = botcommands.get_commands_disabled(str(trigger.nick), "fully") if trigger.sb["realcom"] in list(nick_disabled_list.keys()): - reason = nick_disabled_list[trigger.sb["realcom"]]["reason"] - timestamp = nick_disabled_list[trigger.sb["realcom"]]["timestamp"] bywhom = nick_disabled_list[trigger.sb["realcom"]]["disabledby"] - message = "The " + str(trigger.sb["com"]) + " 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) + if bywhom != trigger.nick: + reason = nick_disabled_list[trigger.sb["realcom"]]["reason"] + timestamp = nick_disabled_list[trigger.sb["realcom"]]["timestamp"] + message = "The " + str(trigger.sb["com"]) + " 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 True From b6ac66e87e0bbf3666503db80860cfb70e41580d Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 15:03:27 -0400 Subject: [PATCH 20/23] oops --- sopel_modules/SpiceBot/Prerun.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index b93076e..6d0d770 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -172,9 +172,6 @@ def trigger_runstatus(bot, trigger): bywhom = channel_disabled_list[trigger.sb["realcom"]]["disabledby"] message = "The " + str(trigger.sb["com"]) + " 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["realcom"], trigger.nick, "fully") - botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["com"] + " multirun is now enabled for " + str(trigger.nick)) # don't run commands that are disabled for specific users nick_disabled_list = botcommands.get_commands_disabled(str(trigger.nick), "fully") @@ -185,6 +182,9 @@ def trigger_runstatus(bot, trigger): timestamp = nick_disabled_list[trigger.sb["realcom"]]["timestamp"] message = "The " + str(trigger.sb["com"]) + " 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["realcom"], trigger.nick, "fully") + botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["com"] + " multirun is now enabled for " + str(trigger.nick)) return True From 8f3216f555ef7db90460725b1ebd365901d89c91 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 15:09:55 -0400 Subject: [PATCH 21/23] text verstionms --- sopel_modules/SpiceBot/Prerun.py | 73 ++++++++++++++++---------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 6d0d770..92f5429 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -49,6 +49,13 @@ def prerun(t_command_type='module', t_command_subtype=None): argsdict_default["realcom"] = botcommands.get_realcom(argsdict_default["com"], trigger_command_type) + if trigger.sb["type"] == 'nickname': + argsdict_default["comtext"] = bot.nick + " " + trigger.sb["com"] + argsdict_default["realcomtext"] = bot.nick + " " + trigger.sb["com"] + else: + argsdict_default["comtext"] = trigger.sb["com"] + argsdict_default["realcomtext"] = trigger.sb["com"] + argsdict_default["dict"] = botcommands.get_command_dict(argsdict_default["realcom"], trigger_command_type) # split into && groupings @@ -147,7 +154,7 @@ def trigger_runstatus(bot, trigger): reason = channel_disabled_list[trigger.sb["realcom"]]["reason"] timestamp = channel_disabled_list[trigger.sb["realcom"]]["timestamp"] bywhom = channel_disabled_list[trigger.sb["realcom"]]["disabledby"] - message = "The " + str(trigger.sb["com"]) + " command multirun usage was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) + 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) return trigger_cant_run(bot, trigger, message) # don't run commands that are disabled for specific users @@ -157,11 +164,11 @@ def trigger_runstatus(bot, trigger): if bywhom != trigger.nick: reason = nick_disabled_list[trigger.sb["realcom"]]["reason"] timestamp = nick_disabled_list[trigger.sb["realcom"]]["timestamp"] - message = "The " + str(trigger.sb["com"]) + " command was multirun unsage disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) + 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) return trigger_cant_run(bot, trigger, message) else: botcommands.unset_command_disabled(trigger.sb["realcom"], trigger.nick, "multirun") - botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["com"] + " multirun is now enabled for " + str(trigger.nick)) + botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["comtext"] + " multirun is now enabled for " + str(trigger.nick)) # don't run commands that are disabled in channels if not trigger.is_privmsg: @@ -170,7 +177,7 @@ def trigger_runstatus(bot, trigger): reason = channel_disabled_list[trigger.sb["realcom"]]["reason"] timestamp = channel_disabled_list[trigger.sb["realcom"]]["timestamp"] bywhom = channel_disabled_list[trigger.sb["realcom"]]["disabledby"] - message = "The " + str(trigger.sb["com"]) + " command was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) + 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) # don't run commands that are disabled for specific users @@ -180,11 +187,11 @@ def trigger_runstatus(bot, trigger): if bywhom != trigger.nick: reason = nick_disabled_list[trigger.sb["realcom"]]["reason"] timestamp = nick_disabled_list[trigger.sb["realcom"]]["timestamp"] - message = "The " + str(trigger.sb["com"]) + " command was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) + 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["realcom"], trigger.nick, "fully") - botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["com"] + " multirun is now enabled for " + str(trigger.nick)) + botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["comtext"] + " multirun is now enabled for " + str(trigger.nick)) return True @@ -230,16 +237,10 @@ def trigger_hyphen_arg_handler(bot, trigger): # Commands that cannot run via privmsg if trigger.sb["hyphen_arg"] in ['check']: - if trigger.sb["type"] == 'nickname': - if trigger.sb["com"].lower() != trigger.sb["realcom"]: - botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + " is a valid alias command for " + bot.nick + " " + trigger.sb["realcom"]) - else: - botmessagelog.messagelog(trigger.sb["log_id"], bot.nick + " " + trigger.sb["com"] + " is a valid command") + 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"]) else: - if trigger.sb["com"].lower() != trigger.sb["realcom"]: - botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + " is a valid alias command for " + trigger.sb["realcom"]) - else: - botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + " is a valid command") + botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["comtext"] + " is a valid command") return elif trigger.sb["hyphen_arg"] in [ @@ -252,9 +253,9 @@ def trigger_hyphen_arg_handler(bot, trigger): target = spicemanip.main(trigger.sb["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["realcom"]) + " usage for?") + botmessagelog.messagelog_error(trigger.sb["log_id"], "Who/Where am I enabling " + str(trigger.sb["comtext"]) + " usage for?") else: - botmessagelog.messagelog_error(trigger.sb["log_id"], "Who/Where am I disabling " + str(trigger.sb["realcom"]) + " usage for?") + botmessagelog.messagelog_error(trigger.sb["log_id"], "Who/Where am I disabling " + str(trigger.sb["comtext"]) + " usage for?") return if not botdb.check_nick_id(target) and not botchannels.check_channel_bot(target, True): @@ -272,39 +273,39 @@ 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["realcom"], target, "fully"): - botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["com"] + " is already enabled for " + str(target)) + botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["comtext"] + " is already enabled for " + str(target)) return botcommands.unset_command_disabled(trigger.sb["realcom"], target, "fully") - botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + " is now enabled for " + str(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["realcom"], target, "fully"): - botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["com"] + " is already disabled for " + str(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["realcom"], target, timestamp, trailingmessage, trigger.nick, "fully") - botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + " is now disabled for " + str(target)) + botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["comtext"] + " is now disabled for " + str(target)) return if trigger.sb["hyphen_arg"] in ['multirun', 'multiruns']: onoff = spicemanip.main(trigger.sb["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["realcom"]) + " multirun usage?") + botmessagelog.messagelog_error(trigger.sb["log_id"], "Do you want to enable or disable " + str(trigger.sb["comtext"]) + " multirun usage?") return target = spicemanip.main(trigger.sb["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["realcom"]) + " multirun usage for?") + botmessagelog.messagelog_error(trigger.sb["log_id"], "Who/Where am I enabling " + str(trigger.sb["comtext"]) + " multirun usage for?") else: - botmessagelog.messagelog_error(trigger.sb["log_id"], "Who/Where am I disabling " + str(trigger.sb["realcom"]) + " multirun usage for?") + botmessagelog.messagelog_error(trigger.sb["log_id"], "Who/Where am I disabling " + str(trigger.sb["comtext"]) + " multirun usage for?") return if not botdb.check_nick_id(target) and not botchannels.check_channel_bot(target, True): @@ -314,56 +315,56 @@ def trigger_hyphen_arg_handler(bot, trigger): 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["realcom"]) + " for " + str(target) + " due to privilege issues.") + 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.") else: - botmessagelog.messagelog_error(trigger.sb["log_id"], "I was unable to enable multirun usage on " + str(trigger.sb["realcom"]) + " for " + str(target) + " due to privilege issues.") + 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.") return if onoff in ['enable', 'unblock', "activate", "on"]: if not botcommands.check_commands_disabled(trigger.sb["realcom"], target, "multirun"): - botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["com"] + " multirun is already enabled for " + str(target)) + botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["comtext"] + " multirun is already enabled for " + str(target)) return botcommands.unset_command_disabled(trigger.sb["realcom"], target, "multirun") - botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + " multirun is now enabled for " + str(target)) + botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["comtext"] + " multirun is now enabled for " + str(target)) return else: if botcommands.check_commands_disabled(trigger.sb["realcom"], target, "multirun"): - botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["com"] + " multirun is already disabled for " + str(target)) + botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["comtext"] + " multirun 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["realcom"], target, timestamp, trailingmessage, trigger.nick, "multirun") - botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["com"] + " multirun is now disabled for " + str(target)) + botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["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["com"] + ": " + str(trigger.sb["dict"]["example"])) + botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["comtext"] + ": " + str(trigger.sb["dict"]["example"])) return elif trigger.sb["hyphen_arg"] in ['filename', 'filepath']: - botmessagelog.messagelog(trigger.sb["log_id"], "The " + str(trigger.sb["com"]) + " file is located at " + str(trigger.sb["dict"][trigger.sb["hyphen_arg"]])) + botmessagelog.messagelog(trigger.sb["log_id"], "The " + str(trigger.sb["comtext"]) + " file is located at " + str(trigger.sb["dict"][trigger.sb["hyphen_arg"]])) return elif trigger.sb["hyphen_arg"] in ['foldername', 'folderpath']: - botmessagelog.messagelog(trigger.sb["log_id"], "The " + str(trigger.sb["com"]) + " folder is located at " + str(trigger.sb["dict"][trigger.sb["hyphen_arg"]])) + botmessagelog.messagelog(trigger.sb["log_id"], "The " + str(trigger.sb["comtext"]) + " folder is located at " + str(trigger.sb["dict"][trigger.sb["hyphen_arg"]])) return elif trigger.sb["hyphen_arg"] in ['author']: - botmessagelog.messagelog(trigger.sb["log_id"], "The author of the " + str(trigger.sb["com"]) + " command is " + trigger.sb["dict"]["author"] + ".") + botmessagelog.messagelog(trigger.sb["log_id"], "The author of the " + str(trigger.sb["comtext"]) + " command is " + trigger.sb["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["com"]) + " command are " + spicemanip.main(trigger.sb["dict"]["contributors"], "andlist") + ".") + botmessagelog.messagelog(trigger.sb["log_id"], "The contributors of the " + str(trigger.sb["comtext"]) + " command are " + spicemanip.main(trigger.sb["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["com"]) + " command are " + spicemanip.main(trigger.sb["dict"]["validcoms"], "andlist") + ".") + botmessagelog.messagelog(trigger.sb["log_id"], "The alaises of the " + str(trigger.sb["comtext"]) + " command are " + spicemanip.main(trigger.sb["dict"]["validcoms"], "andlist") + ".") return return From e9fa15fbce089aa50805ae2835a7e4a4d52edfd3 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 15:11:12 -0400 Subject: [PATCH 22/23] fix --- 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 92f5429..c5f7c6f 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -49,7 +49,7 @@ def prerun(t_command_type='module', t_command_subtype=None): argsdict_default["realcom"] = botcommands.get_realcom(argsdict_default["com"], trigger_command_type) - if trigger.sb["type"] == 'nickname': + if argsdict_default["type"] == 'nickname': argsdict_default["comtext"] = bot.nick + " " + trigger.sb["com"] argsdict_default["realcomtext"] = bot.nick + " " + trigger.sb["com"] else: From 38c5d1e2587689a8da40259361e49510d4396fc9 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 26 Jun 2019 15:12:16 -0400 Subject: [PATCH 23/23] sdgf --- sopel_modules/SpiceBot/Prerun.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index c5f7c6f..8d922ee 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -50,11 +50,11 @@ def prerun(t_command_type='module', t_command_subtype=None): argsdict_default["realcom"] = botcommands.get_realcom(argsdict_default["com"], trigger_command_type) if argsdict_default["type"] == 'nickname': - argsdict_default["comtext"] = bot.nick + " " + trigger.sb["com"] - argsdict_default["realcomtext"] = bot.nick + " " + trigger.sb["com"] + argsdict_default["comtext"] = bot.nick + " " + argsdict_default["com"] + argsdict_default["realcomtext"] = bot.nick + " " + argsdict_default["realcom"] else: - argsdict_default["comtext"] = trigger.sb["com"] - argsdict_default["realcomtext"] = trigger.sb["com"] + argsdict_default["comtext"] = argsdict_default["com"] + argsdict_default["realcomtext"] = argsdict_default["realcom"] argsdict_default["dict"] = botcommands.get_command_dict(argsdict_default["realcom"], trigger_command_type)