From 1ebf73f155e5d43e8e49100b04157a3c02bd6a9b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 28 Jun 2019 14:59:58 -0400 Subject: [PATCH] pass botcom --- sopel_modules/SpiceBot/Prerun.py | 10 ++++-- sopel_modules/SpiceBot/Tools.py | 35 +++++++++++++++++++ sopel_modules/SpiceBot_Core_Commands/AI.py | 2 +- .../SpiceBot_Core_Commands/BotPrivs.py | 4 +-- .../SpiceBot_Core_Commands/Channels.py | 2 +- .../SpiceBot_Core_Commands/Commands.py | 2 +- .../SpiceBot_Core_Commands/CommandsQuery.py | 6 ++-- .../SpiceBot_Core_Commands/DictComs.py | 2 +- sopel_modules/SpiceBot_Core_Commands/Gif.py | 4 +-- sopel_modules/SpiceBot_Core_Commands/Logs.py | 2 +- .../SpiceBot_Core_Commands/Messaging.py | 6 ++-- .../Runtime_Controls.py | 4 +-- .../SpiceBot_Core_Commands/Search.py | 8 ++--- .../SpiceBot_Core_Commands/Sherlock.py | 2 +- .../SpiceBot_Core_Commands/Uptime.py | 2 +- 15 files changed, 65 insertions(+), 26 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index e95a41f..7cf0c4f 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -12,7 +12,7 @@ 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 @@ -27,6 +27,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(): @@ -91,7 +93,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 +109,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(): @@ -155,7 +159,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 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_Core_Commands/AI.py b/sopel_modules/SpiceBot_Core_Commands/AI.py index 5a27f6d..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." 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..cc6e015 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' 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 836a068..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 diff --git a/sopel_modules/SpiceBot_Core_Commands/Gif.py b/sopel_modules/SpiceBot_Core_Commands/Gif.py index 5ab145a..de886f2 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Gif.py +++ b/sopel_modules/SpiceBot_Core_Commands/Gif.py @@ -13,7 +13,7 @@ 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.") @@ -32,7 +32,7 @@ def gif_trigger(bot, trigger): @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 diff --git a/sopel_modules/SpiceBot_Core_Commands/Logs.py b/sopel_modules/SpiceBot_Core_Commands/Logs.py index e66b69b..1009fc6 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Logs.py +++ b/sopel_modules/SpiceBot_Core_Commands/Logs.py @@ -15,7 +15,7 @@ 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.") diff --git a/sopel_modules/SpiceBot_Core_Commands/Messaging.py b/sopel_modules/SpiceBot_Core_Commands/Messaging.py index 9083841..0d8d1a1 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Messaging.py +++ b/sopel_modules/SpiceBot_Core_Commands/Messaging.py @@ -11,19 +11,19 @@ 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) diff --git a/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py b/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py index fa36758..50fc99c 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py +++ b/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py @@ -11,7 +11,7 @@ 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.") @@ -42,7 +42,7 @@ 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.") diff --git a/sopel_modules/SpiceBot_Core_Commands/Search.py b/sopel_modules/SpiceBot_Core_Commands/Search.py index d33b673..1ae974f 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Search.py +++ b/sopel_modules/SpiceBot_Core_Commands/Search.py @@ -12,7 +12,7 @@ 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: @@ -28,7 +28,7 @@ def search_main(bot, trigger): @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: @@ -44,7 +44,7 @@ def search_where(bot, trigger): @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: @@ -60,7 +60,7 @@ def search_what(bot, trigger): @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: 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)