diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index 15ee7f3..002ac5a 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -21,6 +21,7 @@ from .Config import config as botconfig from .Database import db as botdb from .Read import read as botread from .Channels import channels as botchannels +from .Users import users as botusers class SpiceBot_Commands_MainSection(StaticSection): @@ -91,72 +92,89 @@ class BotCommands(): return realcom + def chan_or_nick(self, target): + if botchannels.check_channel_bot(target, True): + return "channel" + elif botdb.check_nick_id(target): + return "nick" + else: + raise Exception(str(target.lower()) + " appears to not be a valid user/channel") + def get_commands_disabled(self, target, disabletype="fully"): disabletype = str(disabletype) + target_type = self.chan_or_nick(target) if disabletype not in list(self.dict['disabled'].keys()): self.dict['disabled'][disabletype] = { - "users": {}, - "channels": {} + "nick": {}, + "channel": {} } - 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_' + disabletype + 'disabled') or {} - return self.dict['disabled'][disabletype]["channels"] + if target_type == "nick": + 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 {} + return 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 {} + return self.dict['disabled'][disabletype]["channel"][target] else: raise Exception(str(target.lower()) + " appears to not be a valid user/channel") def check_commands_disabled(self, command, target, disabletype="fully"): - if disabletype not in list(self.dict['disabled'].keys()): - self.dict['disabled'][disabletype] = { - "users": {}, - "channels": {} - } + 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()): self.dict['disabled'][disabletype] = { - "users": {}, - "channels": {} + "nick": {}, + "channel": {} } - 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 {} - self.dict['disabled'][disabletype]["users"][command] = {"reason": reason, "timestamp": timestamp, "disabledby": bywhom} - botdb.set_nick_value(target, 'commands_' + disabletype + '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_' + disabletype + 'disabled') or {} - self.dict['disabled'][disabletype]["channels"][command] = {"reason": reason, "timestamp": timestamp, "disabledby": bywhom} - botdb.set_channel_value(target, 'commands_' + disabletype + 'disabled', self.dict['disabled'][disabletype]["channels"]) + if target_type == "nick": + 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 {} + 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"][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"][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()): self.dict['disabled'][disabletype] = { - "users": {}, - "channels": {} + "nick": {}, + "channel": {} } - 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 {} - if command in list(self.dict['disabled'][disabletype]["users"].keys()): - del self.dict['disabled'][disabletype]["users"][command] - botdb.set_nick_value(target, 'commands_' + disabletype + '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_' + disabletype + '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_' + disabletype + 'disabled', self.dict['disabled'][disabletype]["channels"]) + if target_type == "nick": + 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"][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].keys()): + del self.dict['disabled'][disabletype]["channel"][target][command] + 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") diff --git a/sopel_modules/SpiceBot/MessageLog.py b/sopel_modules/SpiceBot/MessageLog.py index ae2917f..1947bc7 100644 --- a/sopel_modules/SpiceBot/MessageLog.py +++ b/sopel_modules/SpiceBot/MessageLog.py @@ -39,7 +39,7 @@ class MessageLog(): self.error_message_dict[unique_id] = errormsg return unique_id - def messagelog_start(self, bot, trigger, log_id): + def messagelog_start(self, bot, trigger, log_id, commandname): if not trigger.is_privmsg: channelname = trigger.sender @@ -55,6 +55,7 @@ class MessageLog(): "nick": bot.nick }, "messages": [], + "commandname": commandname, } def messagelog_error(self, log_id, error_id): diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index e95a41f..29f96a4 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -12,12 +12,13 @@ import datetime import spicemanip -from .Tools import command_permissions_check +from .Tools import command_permissions_check, class_create from .Commands import commands as botcommands from .Database import db as botdb from .Channels import channels as botchannels from .MessageLog import messagelog as botmessagelog from .Config import config as botconfig +from .Users import users as botusers def prerun(t_command_type='module', t_command_subtype=None): @@ -27,6 +28,8 @@ def prerun(t_command_type='module', t_command_subtype=None): @functools.wraps(function) def internal_prerun(bot, trigger, *args, **kwargs): + botcom = class_create('botcom') + if t_command_type == "nickname": check_nick = spicemanip.main(trigger.args[1], 1).lower() if check_nick != str(bot.nick).lower(): @@ -79,7 +82,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"]) + botmessagelog.messagelog_start(bot, trigger, argsdict_default["log_id"], argsdict_default["realcomtext"]) runcount = 0 for argsdict in argsdict_list: runcount += 1 @@ -91,7 +94,7 @@ def prerun(t_command_type='module', t_command_subtype=None): if not trigger.sb["hyphen_arg"]: # check if anything prohibits the nick from running the command if trigger_runstatus(bot, trigger): - function(bot, trigger, *args, **kwargs) + function(bot, trigger, botcom, *args, **kwargs) else: trigger_hyphen_arg_handler(bot, trigger) botmessagelog.messagelog_exit(bot, argsdict_default["log_id"]) @@ -107,6 +110,8 @@ def prerun_query(t_command_type='module', t_command_subtype=None): @functools.wraps(function) def internal_prerun(bot, trigger, *args, **kwargs): + botcom = class_create('botcom') + if t_command_type == "nickname": check_nick = spicemanip.main(trigger.args[1], 1).lower() if check_nick != str(bot.nick).lower(): @@ -147,7 +152,7 @@ def prerun_query(t_command_type='module', t_command_subtype=None): argsdict = trigger_argsdict_single(argsdict_default, trigger_args) # Run the function for all splits - botmessagelog.messagelog_start(bot, trigger, argsdict_default["log_id"]) + botmessagelog.messagelog_start(bot, trigger, argsdict_default["log_id"], argsdict_default["realcomtext"]) trigger.sb = copy.deepcopy(argsdict) @@ -155,7 +160,7 @@ def prerun_query(t_command_type='module', t_command_subtype=None): # check if anything prohibits the nick from running the command if trigger_runstatus_query(bot, trigger): - function(bot, trigger, *args, **kwargs) + function(bot, trigger, botcom, *args, **kwargs) botmessagelog.messagelog_exit(bot, argsdict_default["log_id"]) return internal_prerun @@ -231,37 +236,37 @@ 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 # 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") - if "nickname_query" in list(channel_disabled_list.keys()): - reason = channel_disabled_list["nickname_query"]["reason"] - timestamp = channel_disabled_list["nickname_query"]["timestamp"] - bywhom = channel_disabled_list["nickname_query"]["disabledby"] + 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) 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 "nickname_query" in list(nick_disabled_list.keys()): - bywhom = nick_disabled_list["nickname_query"]["disabledby"] - if bywhom != trigger.nick: - reason = nick_disabled_list["nickname_query"]["reason"] - timestamp = nick_disabled_list["nickname_query"]["timestamp"] + 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): + 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) return trigger_cant_run(bot, trigger, message) else: - botcommands.unset_command_disabled(trigger.sb["realcomref"], trigger.nick, "fully") - botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["comtext"] + " is now enabled for " + str(trigger.nick)) + 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 @@ -287,20 +292,20 @@ def trigger_runstatus(bot, trigger): # 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"] + 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) 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()): - bywhom = nick_disabled_list[trigger.sb["realcom"]]["disabledby"] - if bywhom != trigger.nick: - reason = nick_disabled_list[trigger.sb["realcom"]]["reason"] - timestamp = nick_disabled_list[trigger.sb["realcom"]]["timestamp"] + 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): + 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) return trigger_cant_run(bot, trigger, message) else: @@ -309,26 +314,26 @@ 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") - 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"] + 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) 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()): - bywhom = nick_disabled_list[trigger.sb["realcom"]]["disabledby"] - if bywhom != trigger.nick: - reason = nick_disabled_list[trigger.sb["realcom"]]["reason"] - timestamp = nick_disabled_list[trigger.sb["realcom"]]["timestamp"] + 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): + 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) return trigger_cant_run(bot, trigger, message) else: - botcommands.unset_command_disabled(trigger.sb["realcomref"], trigger.nick, "fully") - botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["comtext"] + " is now enabled for " + str(trigger.nick)) + 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 @@ -394,6 +399,7 @@ def trigger_hyphen_arg_handler(bot, trigger): else: botmessagelog.messagelog_error(trigger.sb["log_id"], "Who/Where am I disabling " + str(trigger.sb["comtext"]) + " usage for?") return + trigger.sb["args"] = spicemanip.main(trigger.sb["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.") @@ -409,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 @@ -444,6 +450,7 @@ def trigger_hyphen_arg_handler(bot, trigger): else: botmessagelog.messagelog_error(trigger.sb["log_id"], "Who/Where am I disabling " + str(trigger.sb["comtext"]) + " multirun usage for?") return + trigger.sb["args"] = spicemanip.main(trigger.sb["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.") diff --git a/sopel_modules/SpiceBot/Tools.py b/sopel_modules/SpiceBot/Tools.py index 79b24c0..8e989a4 100644 --- a/sopel_modules/SpiceBot/Tools.py +++ b/sopel_modules/SpiceBot/Tools.py @@ -86,6 +86,41 @@ def command_permissions_check(bot, trigger, privslist): return True +""" +Classes +""" + + +def class_create(classname): + compiletext = """ + def __init__(self): + self.default = str(self.__class__.__name__) + def __repr__(self): + return repr(self.default) + def __str__(self): + return str(self.default) + def __iter__(self): + return str(self.default) + pass + """ + exec(compile("class class_" + str(classname) + ": " + compiletext, "", "exec")) + newclass = eval('class_'+classname+"()") + return newclass + + +def class_directory(inputclass): + + # make sure input is a class + # if not isinstance(inputclass, class): + # return [] + + classdirlistfull, classdirlistclean = dir(inputclass), [] + for classdiritem in classdirlistfull: + if not classdiritem.startswith("_"): + classdirlistclean.append(classdiritem) + return classdirlistclean + + """ Time """ diff --git a/sopel_modules/SpiceBot/Users.py b/sopel_modules/SpiceBot/Users.py index fb915b3..21100ae 100644 --- a/sopel_modules/SpiceBot/Users.py +++ b/sopel_modules/SpiceBot/Users.py @@ -236,13 +236,6 @@ class BotUsers(): def mode(self, bot, trigger): return - def targetcheck(self, target): - return True - - # idk whois - if not botdb.check_nick_id(target): - return - def nick_actual(self, nick, altlist=None): nick_id = self.whois_ident(nick) nick_actual = self.ID(nick_id) diff --git a/sopel_modules/SpiceBot_Core_Commands/AI.py b/sopel_modules/SpiceBot_Core_Commands/AI.py index 3881d14..98b6fce 100644 --- a/sopel_modules/SpiceBot_Core_Commands/AI.py +++ b/sopel_modules/SpiceBot_Core_Commands/AI.py @@ -11,7 +11,7 @@ import spicemanip @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('ai') -def ai_trigger(bot, trigger): +def ai_trigger(bot, trigger, botcom): availablecomsnum = SpiceBot.botai.dict['patterncounts'] availablecomsfiles = SpiceBot.botai.dict['filecounts'] displayval = "There are " + str(availablecomsnum) + " AI pattern matches available in " + str(availablecomsfiles) + " files." @@ -209,7 +209,7 @@ def bot_command_rule_ai(bot, trigger): # elif fulltrigger.lower().startswith(tuple(["have you seen"])): # posstarget = spicemanip.main(trigger_args, 4) or 0 - # message = seen_search(bot, botcom, posstarget) + # message = seen_search(bot, trigger, posstarget) # bot.osd(message) # return # TODO diff --git a/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py b/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py index 84d98c8..be1b25f 100644 --- a/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py +++ b/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py @@ -11,13 +11,13 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('owners', 'owner') -def bot_command_owners(bot, trigger): +def bot_command_owners(bot, trigger, botcom): bot_command_process(bot, trigger) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('admins', 'admin') -def bot_command_admins(bot, trigger): +def bot_command_admins(bot, trigger, botcom): bot_command_process(bot, trigger) diff --git a/sopel_modules/SpiceBot_Core_Commands/Channels.py b/sopel_modules/SpiceBot_Core_Commands/Channels.py index d213971..8f88427 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Channels.py +++ b/sopel_modules/SpiceBot_Core_Commands/Channels.py @@ -13,7 +13,7 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('channels', 'channel') -def nickname_comand_channels(bot, trigger): +def nickname_comand_channels(bot, trigger, botcom): if not len(trigger.sb['args']): commandused = 'list' @@ -49,7 +49,7 @@ def nickname_comand_channels(bot, trigger): elif commandused == 'update': if not trigger.admin: - bot.osd("You do not have permission to update the channel listing.") + SpiceBot.messagelog.messagelog_error("You do not have permission to update the channel listing.") return SpiceBot.channels.bot_part_empty(bot) SpiceBot.channels.channel_list_request(bot) @@ -64,11 +64,11 @@ def nickname_comand_channels(bot, trigger): elif commandused == 'topic': if not len(trigger.sb['args']): - bot.osd("Channel name input missing.") + SpiceBot.messagelog.messagelog_error("Channel name input missing.") return channel = spicemanip.main(trigger.sb['args'], 1) if not SpiceBot.inlist(channel.lower(), list(SpiceBot.channels.dict['list'].keys())): - bot.osd("Channel name {} not valid.".format(channel)) + SpiceBot.messagelog.messagelog_error("Channel name {} not valid.".format(channel)) return topic = SpiceBot.channels.dict['list'][channel.lower()]['topic'] channel = SpiceBot.channels.dict['list'][channel.lower()]['name'] @@ -78,17 +78,17 @@ def nickname_comand_channels(bot, trigger): if commandused.upper() in ['OP', 'HOP', 'VOICE', 'OWNER', 'ADMIN']: if not len(trigger.sb['args']): if trigger.is_privmsg: - bot.osd("Channel name required.") + SpiceBot.messagelog.messagelog_error("Channel name required.") return else: channel = trigger.sender else: channel = spicemanip.main(trigger.sb['args'], 1) if not SpiceBot.inlist(channel.lower(), list(SpiceBot.channels.dict['list'].keys())): - bot.osd("Channel name {} not valid.".format(channel)) + SpiceBot.messagelog.messagelog_error("Channel name {} not valid.".format(channel)) return if not SpiceBot.inlist(channel.lower(), list(bot.channels.keys())): - bot.osd("I need to be in {} to see nick privileges.".format(channel)) + SpiceBot.messagelog.messagelog_error("I need to be in {} to see nick privileges.".format(channel)) return privlist = SpiceBot.channel_privs(bot, channel, commandused.upper()) @@ -105,10 +105,10 @@ def nickname_comand_channels(bot, trigger): if commandused == 'users': channel = spicemanip.main(trigger.sb['args'], 1) if not SpiceBot.inlist(channel.lower(), list(SpiceBot.channels.dict['list'].keys())): - bot.osd("Channel name {} not valid.".format(channel)) + SpiceBot.messagelog.messagelog_error("Channel name {} not valid.".format(channel)) return if not SpiceBot.inlist(channel.lower(), list(bot.channels.keys())): - bot.osd("I need to be in {} to see user list.".format(channel)) + SpiceBot.messagelog.messagelog_error("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 42b7fa6..ce7c5f9 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Commands.py +++ b/sopel_modules/SpiceBot_Core_Commands/Commands.py @@ -17,7 +17,7 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS]) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('commands', 'command') -def nickname_comand_commands(bot, trigger): +def nickname_comand_commands(bot, trigger, botcom): if not len(trigger.sb['args']): commandused = 'list' diff --git a/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py b/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py index 6820f03..2732765 100644 --- a/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py +++ b/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py @@ -14,14 +14,14 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('query') -def query_trigger(bot, trigger): +def query_trigger(bot, trigger, botcom): bot.osd("I have been programmed to help find new commands by using `?`.") @SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS]) @SpiceBot.prerun_query('nickname', 'nickname') @sopel.module.nickname_commands('(.*)') -def query_detection_nick(bot, trigger): +def query_detection_nick(bot, trigger, botcom): # command issued, check if valid if not trigger.sb['com'] or not len(trigger.sb['com']): @@ -87,7 +87,7 @@ def query_detection_nick(bot, trigger): @SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS]) @SpiceBot.prerun_query('module', 'module') @sopel.module.rule('^\?(.*)') -def query_detection(bot, trigger): +def query_detection(bot, trigger, botcom): # command issued, check if valid if not trigger.sb['com'] or not len(trigger.sb['com']): diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index 0516897..507e379 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -17,7 +17,7 @@ from random import randint @SpiceBot.prerun('module', 'dictcom') @sopel.module.commands('(.*)') -def command_dictcom(bot, trigger): +def command_dictcom(bot, trigger, botcom): if trigger.sb['com'] not in list(SpiceBot.commands.dict['commands']["dictcom"].keys()): return @@ -145,7 +145,7 @@ def bot_dictcom_process(bot, trigger): if trigger.sb["dict"][trigger.sb["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, botcom)') + command_function_run = str('bot_dictcom_' + trigger.sb["dict"][trigger.sb["responsekey"]]["type"] + '(bot, trigger)') eval(command_function_run) @@ -404,5 +404,5 @@ def bot_dictcom_feeds(bot, trigger): """ -def bot_dictcom_search(bot, botcom): +def bot_dictcom_search(bot, trigger): bot.say("testing done") diff --git a/sopel_modules/SpiceBot_Core_Commands/Gif.py b/sopel_modules/SpiceBot_Core_Commands/Gif.py index 5ab145a..09ee2c4 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Gif.py +++ b/sopel_modules/SpiceBot_Core_Commands/Gif.py @@ -13,10 +13,10 @@ import spicemanip @SpiceBot.prerun('module') @sopel.module.commands('gif') -def gif_trigger(bot, trigger): +def gif_trigger(bot, trigger, botcom): if not len(trigger.sb['args']): - return bot.osd("Please present a query to search.") + return SpiceBot.messagelog.messagelog_error("Please present a query to search.") query = spicemanip.main(trigger.sb['args'], 0) searchapis = list(SpiceBot.gif.valid_api.keys()) @@ -25,20 +25,20 @@ def gif_trigger(bot, trigger): gifdict = SpiceBot.gif.get_gif(searchdict) if gifdict["error"]: - bot.osd(gifdict["error"]) + SpiceBot.messagelog.messagelog_error(gifdict["error"]) else: bot.osd(str(gifdict['gifapi'].title() + " Result (" + str(query) + " #" + str(gifdict["returnnum"]) + "): " + str(gifdict["returnurl"]))) @SpiceBot.prerun('module', "gif_prefix") @sopel.module.commands('(.*)') -def gifapi_triggers(bot, trigger): +def gifapi_triggers(bot, trigger, botcom): if trigger.sb['com'] not in list(SpiceBot.gif.valid_api.keys()): return if not len(trigger.sb['args']): - return bot.osd("Please present a query to search.") + return SpiceBot.messagelog.messagelog_error("Please present a query to search.") query = spicemanip.main(trigger.sb['args'], 0) searchdict = {"query": query, "gifsearch": trigger.sb['com']} @@ -46,6 +46,6 @@ def gifapi_triggers(bot, trigger): gifdict = SpiceBot.gif.get_gif(searchdict) if gifdict["error"]: - bot.osd(gifdict["error"]) + SpiceBot.messagelog.messagelog_error(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 e66b69b..a65f6ba 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Logs.py +++ b/sopel_modules/SpiceBot_Core_Commands/Logs.py @@ -15,10 +15,10 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.events.check_ready([SpiceBot.events.BOT_LOGS]) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('logs', 'debug') -def bot_command_logs(bot, trigger): +def bot_command_logs(bot, trigger, botcom): if not SpiceBot.command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): - bot.osd("I was unable to process this Bot Nick command due to privilege issues.") + SpiceBot.messagelog.messagelog_error("I was unable to process this Bot Nick command due to privilege issues.") return logtype = spicemanip.main(trigger.sb['args'], 1) or None @@ -29,9 +29,9 @@ def bot_command_logs(bot, trigger): 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): - bot.osd("No valid logs match " + str(logtype) + ".", trigger.nick, 'notice') + SpiceBot.messagelog.messagelog_error("No valid logs match " + str(logtype) + ".", trigger.nick, 'notice') else: - bot.osd("The following commands may match " + str(logtype) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick, 'notice') + SpiceBot.messagelog.messagelog_error("The following commands may match " + str(logtype) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick, 'notice') return @@ -40,7 +40,7 @@ def bot_command_logs(bot, trigger): logindex = SpiceBot.logs.get_logs(logtype) if not len(logindex): - bot.osd("No logs found for " + str(logtype) + ".") + SpiceBot.messagelog.messagelog_error("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 9083841..f342a83 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Messaging.py +++ b/sopel_modules/SpiceBot_Core_Commands/Messaging.py @@ -11,40 +11,40 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('action') -def bot_command_action(bot, trigger): +def bot_command_action(bot, trigger, botcom): bot_command_process(bot, trigger) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('notice') -def bot_command_notice(bot, trigger): +def bot_command_notice(bot, trigger, botcom): bot_command_process(bot, trigger) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('privmsg', 'say', 'msg') -def bot_command_privmsg(bot, trigger): +def bot_command_privmsg(bot, trigger, botcom): bot_command_process(bot, trigger) def bot_command_process(bot, trigger): if not SpiceBot.command_permissions_check(bot, trigger, ['admins', 'owner']): - bot.osd("I was unable to process this Bot Nick command due to privilege issues.") + SpiceBot.messagelog.messagelog_error("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 not len(trigger.sb['args']): - bot.osd("You must specify a channel or nick.") + SpiceBot.messagelog.messagelog_error("You must specify a channel or nick.") return target = spicemanip.main(trigger.sb['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)): - bot.osd("Channel/nick name {} not valid.".format(target)) + SpiceBot.messagelog.messagelog_error("Channel/nick name {} not valid.".format(target)) return trigger.sb['args'] = spicemanip.main(trigger.sb['args'], '2+', 'list') @@ -58,7 +58,7 @@ def bot_command_process(bot, trigger): botmessage = spicemanip.main(trigger.sb['args'], 0) if not botmessage: - bot.osd("You must specify a message to send.") + SpiceBot.messagelog.messagelog_error("You must specify a message to send.") return bot.osd(botmessage, targetsendlist, trigger.sb['com'].upper()) diff --git a/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py b/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py index fa36758..0bd832f 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py +++ b/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py @@ -11,10 +11,10 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('update') -def nickname_comand_update(bot, trigger): +def nickname_comand_update(bot, trigger, botcom): if not SpiceBot.command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): - bot.osd("I was unable to process this Bot Nick command due to privilege issues.") + SpiceBot.messagelog.messagelog_error("I was unable to process this Bot Nick command due to privilege issues.") return if not len(trigger.sb['args']): @@ -23,7 +23,7 @@ def nickname_comand_update(bot, trigger): commandused = spicemanip.main(trigger.sb['args'], 1).lower() if commandused not in ['deps', 'nodeps']: - bot.osd("Please specify deps or nodeps") + SpiceBot.messagelog.messagelog_error("Please specify deps or nodeps") return trigger.sb['args'] = spicemanip.main(trigger.sb['args'], '2+', 'list') @@ -42,10 +42,10 @@ def nickname_comand_update(bot, trigger): @sopel.module.nickname_commands('restart') -def nickname_comand_restart(bot, trigger): +def nickname_comand_restart(bot, trigger, botcom): if not trigger.admin: - bot.osd("You are not authorized to perform this function.") + SpiceBot.messagelog.messagelog_error("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 d33b673..b958167 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Search.py +++ b/sopel_modules/SpiceBot_Core_Commands/Search.py @@ -12,63 +12,63 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.prerun('module') @sopel.module.commands('search', 'find', 'google', 'lookup') -def search_main(bot, trigger): +def search_main(bot, trigger, botcom): searchterm = spicemanip.main(trigger.sb['args'], 0) or None if not searchterm: - bot.osd("Not sure what you want me to look for.") + SpiceBot.messagelog.messagelog_error("Not sure what you want me to look for.") return searchreturn = SpiceBot.google.search(searchterm) if not searchreturn: - bot.osd('I cannot find anything about that') + SpiceBot.messagelog.messagelog_error('I cannot find anything about that') else: bot.osd(["[Information search for '" + str(searchterm) + "']", str(searchreturn)]) @SpiceBot.prerun('module') @sopel.module.commands("where", "whereis") -def search_where(bot, trigger): +def search_where(bot, trigger, botcom): searchterm = spicemanip.main(trigger.sb['args'], 0) or None if not searchterm: - bot.osd("Not sure what you want me to look for.") + SpiceBot.messagelog.messagelog_error("Not sure what you want me to look for.") return searchreturn = SpiceBot.google.search(searchterm, 'maps') if not searchreturn: - bot.osd('I cannot find anything about that') + SpiceBot.messagelog.messagelog_error('I cannot find anything about that') else: bot.osd(["[Location search for " + str(searchterm) + "]", str(searchreturn)]) @SpiceBot.prerun('module') @sopel.module.commands("what", "whatis") -def search_what(bot, trigger): +def search_what(bot, trigger, botcom): searchterm = spicemanip.main(trigger.sb['args'], 0) or None if not searchterm: - bot.osd("Not sure what you want me to look for.") + SpiceBot.messagelog.messagelog_error("Not sure what you want me to look for.") return searchreturn = SpiceBot.google.search(searchterm) if not searchreturn: - bot.osd('I cannot find anything about that') + SpiceBot.messagelog.messagelog_error('I cannot find anything about that') else: bot.osd(["[Information search for '" + str(searchterm) + "']", str(searchreturn)]) @SpiceBot.prerun('module') @sopel.module.commands("youtube", "video") -def search_video(bot, trigger): +def search_video(bot, trigger, botcom): searchterm = spicemanip.main(trigger.sb['args'], 0) or None if not searchterm: - bot.osd("Not sure what you want me to look for.") + SpiceBot.messagelog.messagelog_error("Not sure what you want me to look for.") return searchreturn = SpiceBot.google.search(searchterm, 'youtube') if not searchreturn: - bot.osd('I cannot find anything about that') + SpiceBot.messagelog.messagelog_error('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 d4a19cb..49b22de 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Sherlock.py +++ b/sopel_modules/SpiceBot_Core_Commands/Sherlock.py @@ -11,7 +11,7 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.prerun('module') @sopel.module.commands('sherlock', 'username') -def bot_command_sherlock(bot, trigger): +def bot_command_sherlock(bot, trigger, botcom): netlist = list(SpiceBot.sherlock.dict.keys()) diff --git a/sopel_modules/SpiceBot_Core_Commands/Uptime.py b/sopel_modules/SpiceBot_Core_Commands/Uptime.py index ecf823a..a644e37 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Uptime.py +++ b/sopel_modules/SpiceBot_Core_Commands/Uptime.py @@ -11,6 +11,6 @@ import sopel_modules.SpiceBot as SpiceBot @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('uptime') -def bot_command_uptime(bot, trigger): +def bot_command_uptime(bot, trigger, botcom): timesince = str(SpiceBot.humanized_time(time.time() - SpiceBot.events.BOT_UPTIME)) + " ago." bot.osd("I have been running since " + timesince)