From 4f3909948f76212ccb170e3e504419c204c94005 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 18 May 2019 14:25:32 -0400 Subject: [PATCH] Attempt SpiceBot import start --- .../System.py => SpiceBot/Events.py} | 16 ++++++---- .../{SpiceBot_Logs => SpiceBot}/Logs.py | 32 ++++--------------- sopel_modules/SpiceBot/__init__.py | 14 ++++++++ sopel_modules/SpiceBot_AI/AI.py | 2 +- sopel_modules/SpiceBot_Channels/Channels.py | 4 +-- .../SpiceBot_Channels/Channels_Command.py | 2 +- .../SpiceBot_CommandsQuery/CommandsQuery.py | 4 +-- .../NickQueryCommand.py | 2 +- .../SpiceBot_CommandsQuery/QueryCommand.py | 2 +- .../Databaseaddons.py | 2 +- .../SpiceBot_Database_Cache/DatabaseCache.py | 2 +- sopel_modules/SpiceBot_Events/Events.py | 4 +-- sopel_modules/SpiceBot_Events/__init__.py | 1 - sopel_modules/SpiceBot_GifSearch/gif.py | 2 +- sopel_modules/SpiceBot_GifSearch/gifapi.py | 2 +- sopel_modules/SpiceBot_GifSearch/gifsearch.py | 4 +-- .../SpiceBot_InvalidCommand/InvalidCommand.py | 2 +- sopel_modules/SpiceBot_Kick/__init__.py | 2 +- sopel_modules/SpiceBot_Logs/ErrorDisplay.py | 5 ++- sopel_modules/SpiceBot_Logs/Logs_Command.py | 4 +-- sopel_modules/SpiceBot_Logs/Queue.py | 28 ++++++++++++++++ sopel_modules/SpiceBot_Logs/__init__.py | 2 +- sopel_modules/SpiceBot_Restart/Restart.py | 2 +- sopel_modules/SpiceBot_SBTools/__init__.py | 2 +- .../SpiceBot_SopelPatches/Patches.py | 2 +- .../StartupMonologue.py | 4 +-- .../StartupMonologue_Display.py | 4 +-- sopel_modules/SpiceBot_Update/Update.py | 2 +- sopel_modules/SpiceBot_Uptime/Uptime.py | 2 +- sopel_modules/SpiceBot_osd/__init__.py | 2 +- 30 files changed, 92 insertions(+), 66 deletions(-) rename sopel_modules/{SpiceBot_Events/System.py => SpiceBot/Events.py} (93%) rename sopel_modules/{SpiceBot_Logs => SpiceBot}/Logs.py (80%) create mode 100644 sopel_modules/SpiceBot/__init__.py create mode 100644 sopel_modules/SpiceBot_Logs/Queue.py diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot/Events.py similarity index 93% rename from sopel_modules/SpiceBot_Events/System.py rename to sopel_modules/SpiceBot/Events.py index e2d27f8..d01b9a3 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot/Events.py @@ -1,10 +1,14 @@ -#!/usr/bin/env python -# coding=utf-8 -from __future__ import unicode_literals, absolute_import, print_function, division +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +""" +This is the SpiceBot events system. + +We utilize the Sopel code for event numbers and +self-trigger the bot into performing actions +""" + -# sopel imports import sopel -from sopel.trigger import PreTrigger import functools @@ -45,7 +49,7 @@ class BotEvents(object): def trigger(self, bot, number, message="SpiceBot_Events"): number = str(number) if number in self.defaultevents or self.check(self.BOT_CONNECTED): - pretrigger = PreTrigger( + pretrigger = sopel.trigger.PreTrigger( bot.nick, ":SpiceBot_Events " + number + " " + str(bot.nick) + " :" + message ) diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot/Logs.py similarity index 80% rename from sopel_modules/SpiceBot_Logs/Logs.py rename to sopel_modules/SpiceBot/Logs.py index 76627cd..da458ae 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot/Logs.py @@ -1,12 +1,14 @@ -# coding=utf-8 +# coding=utf8 from __future__ import unicode_literals, absolute_import, division, print_function +""" +This is the SpiceBot Logs system. -import sopel.module -import sopel.tools -import sopel.config +This Class stores logs in an easy to access manner +""" + +import sopel import os - import spicemanip @@ -102,23 +104,3 @@ class botlogs(): botlogs = botlogs() - - -@sopel.module.event('001') -@sopel.module.rule('.*') -def join_log_channel(bot, trigger): - - if bot.config.core.logging_channel: - channel = bot.config.core.logging_channel - if channel not in bot.channels.keys(): - bot.write(('JOIN', bot.nick, channel)) - if channel not in bot.channels.keys() and bot.config.SpiceBot_Channels.operadmin: - bot.write(('SAJOIN', bot.nick, channel)) - - while True: - if len(botlogs.SpiceBot_Logs["queue"]): - bot.say(str(botlogs.SpiceBot_Logs["queue"][0]), channel) - del botlogs.SpiceBot_Logs["queue"][0] - else: - botlogs.sopel_config["logging_channel"] = False - botlogs.SpiceBot_Logs["queue"] = [] diff --git a/sopel_modules/SpiceBot/__init__.py b/sopel_modules/SpiceBot/__init__.py new file mode 100644 index 0000000..aeefd66 --- /dev/null +++ b/sopel_modules/SpiceBot/__init__.py @@ -0,0 +1,14 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +""" +These are the core SpiceBot Classes + +This module contains references only for other modules to utilize. +""" + +from .Logs import * +from .Events import * + +__author__ = 'Sam Zick' +__email__ = 'sam@deathbybandaid.net' +__version__ = '0.1.1' diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index c476bcb..0a3f8f1 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -7,7 +7,7 @@ import sopel.module import spicemanip from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, googlesearch, bot_privs, inlist, inlist_match, similar_list -from sopel_modules.SpiceBot_Events.System import botevents +from sopel_modules.SpiceBot.Events import botevents @botevents.check_ready([botevents.BOT_LOADED, botevents.BOT_COMMANDSQUERY]) diff --git a/sopel_modules/SpiceBot_Channels/Channels.py b/sopel_modules/SpiceBot_Channels/Channels.py index 6424166..7a54d60 100644 --- a/sopel_modules/SpiceBot_Channels/Channels.py +++ b/sopel_modules/SpiceBot_Channels/Channels.py @@ -6,8 +6,8 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi import sopel.module from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute -from sopel_modules.SpiceBot_Logs.Logs import botlogs -from sopel_modules.SpiceBot_Events.System import botevents +from sopel_modules.SpiceBot.Logs import botlogs +from sopel_modules.SpiceBot.Events import botevents from sopel_modules.SpiceBot_SBTools import join_all_channels, chanadmin_all_channels, channel_list_current import spicemanip diff --git a/sopel_modules/SpiceBot_Channels/Channels_Command.py b/sopel_modules/SpiceBot_Channels/Channels_Command.py index 5648f2f..259132b 100644 --- a/sopel_modules/SpiceBot_Channels/Channels_Command.py +++ b/sopel_modules/SpiceBot_Channels/Channels_Command.py @@ -6,7 +6,7 @@ import sopel.module import spicemanip -from sopel_modules.SpiceBot_Events.System import botevents +from sopel_modules.SpiceBot.Events import botevents from sopel_modules.SpiceBot_SBTools import ( sopel_triggerargs, inlist, channel_privs, join_all_channels, channel_list_current, diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index af7f7ab..9677108 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -7,8 +7,8 @@ import sopel.module import os -from sopel_modules.SpiceBot_Logs.Logs import botlogs -from sopel_modules.SpiceBot_Events.System import botevents +from sopel_modules.SpiceBot.Logs import botlogs +from sopel_modules.SpiceBot.Events import botevents import spicemanip diff --git a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py index 23d4ca5..a04866f 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel import sopel.module -from sopel_modules.SpiceBot_Events.System import botevents +from sopel_modules.SpiceBot.Events import botevents from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, similar_list, letters_in_string diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index 7adb427..f2e6de1 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel import sopel.module -from sopel_modules.SpiceBot_Events.System import botevents +from sopel_modules.SpiceBot.Events import botevents from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, similar_list, letters_in_string diff --git a/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py b/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py index bb80e8d..9e8343d 100644 --- a/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py +++ b/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py @@ -10,7 +10,7 @@ from sopel.db import SopelDB, NickValues, ChannelValues from sqlalchemy.exc import SQLAlchemyError import json -from sopel_modules.SpiceBot_Logs.Logs import botlogs +from sopel_modules.SpiceBot.Logs import botlogs def setup(bot): diff --git a/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py b/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py index 8f474ef..f31ea22 100644 --- a/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py +++ b/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel.module -from sopel_modules.SpiceBot_Logs.Logs import botlogs +from sopel_modules.SpiceBot.Logs import botlogs def setup(bot): diff --git a/sopel_modules/SpiceBot_Events/Events.py b/sopel_modules/SpiceBot_Events/Events.py index 0eedcbd..2a92e6c 100644 --- a/sopel_modules/SpiceBot_Events/Events.py +++ b/sopel_modules/SpiceBot_Events/Events.py @@ -5,8 +5,8 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel.trigger import PreTrigger -from sopel_modules.SpiceBot_Logs.Logs import botlogs -from .System import botevents +from sopel_modules.SpiceBot.Logs import botlogs +from sopel_modules.SpiceBot.Events import botevents import time diff --git a/sopel_modules/SpiceBot_Events/__init__.py b/sopel_modules/SpiceBot_Events/__init__.py index 532880f..2e6b7d5 100644 --- a/sopel_modules/SpiceBot_Events/__init__.py +++ b/sopel_modules/SpiceBot_Events/__init__.py @@ -1,7 +1,6 @@ # coding=utf8 from __future__ import unicode_literals, absolute_import, division, print_function -from .System import * from .Events import * __author__ = 'Sam Zick' diff --git a/sopel_modules/SpiceBot_GifSearch/gif.py b/sopel_modules/SpiceBot_GifSearch/gif.py index e517965..88c5566 100644 --- a/sopel_modules/SpiceBot_GifSearch/gif.py +++ b/sopel_modules/SpiceBot_GifSearch/gif.py @@ -7,7 +7,7 @@ from sopel import module from .gifsearch import getGif from sopel_modules.SpiceBot_SBTools import sopel_triggerargs -from sopel_modules.SpiceBot_Events.System import botevents +from sopel_modules.SpiceBot.Events import botevents import spicemanip diff --git a/sopel_modules/SpiceBot_GifSearch/gifapi.py b/sopel_modules/SpiceBot_GifSearch/gifapi.py index 2f6cc7b..5fcd73e 100644 --- a/sopel_modules/SpiceBot_GifSearch/gifapi.py +++ b/sopel_modules/SpiceBot_GifSearch/gifapi.py @@ -9,7 +9,7 @@ import sopel.module import spicemanip from sopel_modules.SpiceBot_SBTools import sopel_triggerargs -from sopel_modules.SpiceBot_Events.System import botevents +from sopel_modules.SpiceBot.Events import botevents @botevents.check_ready([botevents.BOT_GIFSEARCH]) diff --git a/sopel_modules/SpiceBot_GifSearch/gifsearch.py b/sopel_modules/SpiceBot_GifSearch/gifsearch.py index 029c29c..1eb2ce4 100644 --- a/sopel_modules/SpiceBot_GifSearch/gifsearch.py +++ b/sopel_modules/SpiceBot_GifSearch/gifsearch.py @@ -5,8 +5,8 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel.config.types import StaticSection, ValidatedAttribute -from sopel_modules.SpiceBot_Logs.Logs import botlogs -from sopel_modules.SpiceBot_Events.System import botevents +from sopel_modules.SpiceBot.Logs import botlogs +from sopel_modules.SpiceBot.Events import botevents from sopel_modules.SpiceBot_CommandsQuery.CommandsQuery import commandsquery_register from sopel_modules.SpiceBot_SBTools import read_directory_json_to_dict diff --git a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py index 17cbe0a..3bff3a2 100644 --- a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py +++ b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel_modules.SpiceBot_SBTools import sopel_triggerargs -from sopel_modules.SpiceBot_Events.System import botevents +from sopel_modules.SpiceBot.Events import botevents def setup(bot): diff --git a/sopel_modules/SpiceBot_Kick/__init__.py b/sopel_modules/SpiceBot_Kick/__init__.py index 06ad646..2d1c429 100644 --- a/sopel_modules/SpiceBot_Kick/__init__.py +++ b/sopel_modules/SpiceBot_Kick/__init__.py @@ -14,7 +14,7 @@ from sopel import tools, module from sopel.tools import Identifier from sopel.config.types import StaticSection, ValidatedAttribute -from sopel_modules.SpiceBot_Logs.Logs import botlogs +from sopel_modules.SpiceBot.Logs import botlogs import time diff --git a/sopel_modules/SpiceBot_Logs/ErrorDisplay.py b/sopel_modules/SpiceBot_Logs/ErrorDisplay.py index 543973e..d075cff 100644 --- a/sopel_modules/SpiceBot_Logs/ErrorDisplay.py +++ b/sopel_modules/SpiceBot_Logs/ErrorDisplay.py @@ -3,9 +3,8 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module -from sopel_modules.SpiceBot_Events.System import botevents - -from .Logs import botlogs +from sopel_modules.SpiceBot.Logs import botlogs +from sopel_modules.SpiceBot.Events import botevents @sopel.module.event(botevents.BOT_STARTUPMONOLOGUE) diff --git a/sopel_modules/SpiceBot_Logs/Logs_Command.py b/sopel_modules/SpiceBot_Logs/Logs_Command.py index 2f78af7..7c6bf5f 100644 --- a/sopel_modules/SpiceBot_Logs/Logs_Command.py +++ b/sopel_modules/SpiceBot_Logs/Logs_Command.py @@ -5,8 +5,8 @@ import sopel.module import spicemanip -from .Logs import botlogs -from sopel_modules.SpiceBot_Events.System import botevents +from sopel_modules.SpiceBot.Logs import botlogs +from sopel_modules.SpiceBot.Events import botevents from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match, similar_list diff --git a/sopel_modules/SpiceBot_Logs/Queue.py b/sopel_modules/SpiceBot_Logs/Queue.py new file mode 100644 index 0000000..7ddb744 --- /dev/null +++ b/sopel_modules/SpiceBot_Logs/Queue.py @@ -0,0 +1,28 @@ +# coding=utf-8 +from __future__ import unicode_literals, absolute_import, division, print_function + +import sopel.module +import sopel.tools +import sopel.config + +from sopel_modules.SpiceBot.Logs import botlogs + + +@sopel.module.event('001') +@sopel.module.rule('.*') +def join_log_channel(bot, trigger): + + if bot.config.core.logging_channel: + channel = bot.config.core.logging_channel + if channel not in bot.channels.keys(): + bot.write(('JOIN', bot.nick, channel)) + if channel not in bot.channels.keys() and bot.config.SpiceBot_Channels.operadmin: + bot.write(('SAJOIN', bot.nick, channel)) + + while True: + if len(botlogs.SpiceBot_Logs["queue"]): + bot.say(str(botlogs.SpiceBot_Logs["queue"][0]), channel) + del botlogs.SpiceBot_Logs["queue"][0] + else: + botlogs.sopel_config["logging_channel"] = False + botlogs.SpiceBot_Logs["queue"] = [] diff --git a/sopel_modules/SpiceBot_Logs/__init__.py b/sopel_modules/SpiceBot_Logs/__init__.py index 091f24f..b0be6c0 100644 --- a/sopel_modules/SpiceBot_Logs/__init__.py +++ b/sopel_modules/SpiceBot_Logs/__init__.py @@ -1,7 +1,7 @@ # coding=utf8 from __future__ import unicode_literals, absolute_import, division, print_function -from .Logs import * +from .Queue import * from .Logs_Command import * from .ErrorDisplay import * diff --git a/sopel_modules/SpiceBot_Restart/Restart.py b/sopel_modules/SpiceBot_Restart/Restart.py index 421b990..89e083c 100644 --- a/sopel_modules/SpiceBot_Restart/Restart.py +++ b/sopel_modules/SpiceBot_Restart/Restart.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel.module -from sopel_modules.SpiceBot_Logs.Logs import botlogs +from sopel_modules.SpiceBot.Logs import botlogs from sopel_modules.SpiceBot_SBTools import spicebot_reload diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 5fb5f94..65da964 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -20,7 +20,7 @@ from pygit2 import clone_repository import spicemanip -from sopel_modules.SpiceBot_Logs.Logs import botlogs +from sopel_modules.SpiceBot.Logs import botlogs """Variable References""" diff --git a/sopel_modules/SpiceBot_SopelPatches/Patches.py b/sopel_modules/SpiceBot_SopelPatches/Patches.py index c6a4bdf..0aa3cc8 100644 --- a/sopel_modules/SpiceBot_SopelPatches/Patches.py +++ b/sopel_modules/SpiceBot_SopelPatches/Patches.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi import sopel import sopel.module -from sopel_modules.SpiceBot_Logs.Logs import botlogs +from sopel_modules.SpiceBot.Logs import botlogs from sopel_modules.SpiceBot_SBTools import stock_modules_begone diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py index 24ccb3b..2671bcc 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py @@ -4,8 +4,8 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module -from sopel_modules.SpiceBot_Logs.Logs import botlogs -from sopel_modules.SpiceBot_Events.System import botevents +from sopel_modules.SpiceBot.Logs import botlogs +from sopel_modules.SpiceBot.Events import botevents def setup(bot): diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py index 5bd857d..47a2fa9 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py @@ -4,8 +4,8 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module -from sopel_modules.SpiceBot_Logs.Logs import botlogs -from sopel_modules.SpiceBot_Events.System import botevents +from sopel_modules.SpiceBot.Logs import botlogs +from sopel_modules.SpiceBot.Events import botevents from sopel_modules.SpiceBot_SBTools import humanized_time import time diff --git a/sopel_modules/SpiceBot_Update/Update.py b/sopel_modules/SpiceBot_Update/Update.py index 111172d..d00464d 100644 --- a/sopel_modules/SpiceBot_Update/Update.py +++ b/sopel_modules/SpiceBot_Update/Update.py @@ -8,7 +8,7 @@ from sopel.config.types import StaticSection, ValidatedAttribute import spicemanip -from sopel_modules.SpiceBot_Logs.Logs import botlogs +from sopel_modules.SpiceBot.Logs import botlogs from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, spicebot_reload, spicebot_update diff --git a/sopel_modules/SpiceBot_Uptime/Uptime.py b/sopel_modules/SpiceBot_Uptime/Uptime.py index 4c127b9..3af0b71 100644 --- a/sopel_modules/SpiceBot_Uptime/Uptime.py +++ b/sopel_modules/SpiceBot_Uptime/Uptime.py @@ -6,7 +6,7 @@ import sopel.module import time -from sopel_modules.SpiceBot_Logs.Logs import botlogs +from sopel_modules.SpiceBot.Logs import botlogs from sopel_modules.SpiceBot_SBTools import humanized_time diff --git a/sopel_modules/SpiceBot_osd/__init__.py b/sopel_modules/SpiceBot_osd/__init__.py index a097396..91fa5a3 100644 --- a/sopel_modules/SpiceBot_osd/__init__.py +++ b/sopel_modules/SpiceBot_osd/__init__.py @@ -14,7 +14,7 @@ from sopel import tools, module from sopel.tools import Identifier from sopel.config.types import StaticSection, ValidatedAttribute -from sopel_modules.SpiceBot_Logs.Logs import botlogs +from sopel_modules.SpiceBot.Logs import botlogs import time from collections import abc