From 9a48017060607302d81e7abf98db03652cc560ed Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 4 May 2019 16:25:03 -0400 Subject: [PATCH 01/15] Logging Feature --- sopel_modules/SpiceBot_Botevents/BotEvents.py | 4 +- sopel_modules/SpiceBot_Botevents/Connected.py | 1 - .../SpiceBot_Botevents/Startup_Complete.py | 4 +- sopel_modules/SpiceBot_Channels/Channels.py | 28 ++++-- .../SpiceBot_CommandsQuery/CommandsQuery.py | 88 +++++++++++++------ .../Databaseaddons.py | 5 +- .../SpiceBot_Database_Cache/DatabaseCache.py | 7 +- .../SpiceBot_FriendlyBot/FriendlyBot.py | 1 - sopel_modules/SpiceBot_Gender/Gender.py | 3 - sopel_modules/SpiceBot_GifSearch/gifsearch.py | 18 ++-- .../SpiceBot_InsultHandler/InsultHandler.py | 5 -- sopel_modules/SpiceBot_Logs/Logs.py | 46 +++++++++- sopel_modules/SpiceBot_Restart/Restart.py | 6 +- sopel_modules/SpiceBot_SBTools/__init__.py | 49 +++-------- .../StartupMonologue.py | 33 ++++--- sopel_modules/SpiceBot_Update/Update.py | 36 ++++++-- sopel_modules/SpiceBot_Uptime/Uptime.py | 10 ++- sopel_modules/SpiceBot_osd/__init__.py | 10 ++- 18 files changed, 219 insertions(+), 135 deletions(-) diff --git a/sopel_modules/SpiceBot_Botevents/BotEvents.py b/sopel_modules/SpiceBot_Botevents/BotEvents.py index 6f831d5..5ec3128 100644 --- a/sopel_modules/SpiceBot_Botevents/BotEvents.py +++ b/sopel_modules/SpiceBot_Botevents/BotEvents.py @@ -6,7 +6,7 @@ Sopel BotEvents is a poor mans way to create module load order dependencies from __future__ import unicode_literals, absolute_import, division, print_function import sopel.module -from sopel.tools import stderr +from sopel_modules.SpiceBot_Logs import bot_logging import threading @@ -15,7 +15,7 @@ def configure(config): def setup(bot): - stderr("[Sopel_BotEvents] Starting Module Events Logging") + bot_logging(bot, 'Sopel_BotEvents', "Starting Module Events Logging") threading.Thread(target=setup_thread, args=(bot,)).start() diff --git a/sopel_modules/SpiceBot_Botevents/Connected.py b/sopel_modules/SpiceBot_Botevents/Connected.py index a027c66..d804c01 100644 --- a/sopel_modules/SpiceBot_Botevents/Connected.py +++ b/sopel_modules/SpiceBot_Botevents/Connected.py @@ -3,7 +3,6 @@ from __future__ import unicode_literals, absolute_import, division, print_function import sopel.module -from sopel.tools import stderr from .BotEvents import check_bot_events, startup_bot_event, set_bot_event import time diff --git a/sopel_modules/SpiceBot_Botevents/Startup_Complete.py b/sopel_modules/SpiceBot_Botevents/Startup_Complete.py index 6891b79..6f211eb 100644 --- a/sopel_modules/SpiceBot_Botevents/Startup_Complete.py +++ b/sopel_modules/SpiceBot_Botevents/Startup_Complete.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals, absolute_import, division, print_function import sopel.module -from sopel.tools import stderr +from sopel_modules.SpiceBot_Logs import bot_logging from .BotEvents import set_bot_event, check_bot_startup @@ -16,4 +16,4 @@ def bot_startup_complete(bot, trigger): pass set_bot_event(bot, "startup_complete") - stderr("[Sopel_BotEvents] Module Events Logging Complete") + bot_logging(bot, 'Sopel_BotEvents', "Module Events Logging Complete") diff --git a/sopel_modules/SpiceBot_Channels/Channels.py b/sopel_modules/SpiceBot_Channels/Channels.py index 05bc7f5..7341b8f 100644 --- a/sopel_modules/SpiceBot_Channels/Channels.py +++ b/sopel_modules/SpiceBot_Channels/Channels.py @@ -4,9 +4,11 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel.module -from sopel.tools import stderr +from sopel_modules.SpiceBot_Logs import bot_logging from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute +from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, startup_bot_event + import time import spicemanip @@ -33,14 +35,20 @@ def configure(config): def setup(bot): - stderr("[SpiceBot_Channels] Initial Setup processing...") + bot_logging(bot, 'SpiceBot_Channels', "Initial Setup processing") + + startup_bot_event(bot, "SpiceBot_Channels") bot.config.define_section("SpiceBot_Channels", SpiceBot_Channels_MainSection, validate=False) - bot.memory['SpiceBot_Channels'] = dict() - bot.memory['SpiceBot_Channels']['channels'] = dict() - bot.memory['SpiceBot_Channels']['InitialProcess'] = False - bot.memory['SpiceBot_Channels']['ProcessLock'] = False + if 'SpiceBot_Channels' not in bot.memory: + bot.memory['SpiceBot_Channels'] = dict() + if 'channels' not in bot.memory['SpiceBot_Channels'].keys(): + bot.memory['SpiceBot_Channels']['channels'] = dict() + if 'InitialProcess' not in bot.memory['SpiceBot_Channels'].keys(): + bot.memory['SpiceBot_Channels']['InitialProcess'] = False + if 'ProcessLock' not in bot.memory['SpiceBot_Channels'].keys(): + bot.memory['SpiceBot_Channels']['ProcessLock'] = False @sopel.module.event('001') @@ -53,7 +61,7 @@ def trigger_channel_list_initial(bot, trigger): bot.write(['LIST']) bot.memory['SpiceBot_Channels']['ProcessLock'] = True - stderr("[SpiceBot_Channels] Initial Channel list populating...") + bot_logging(bot, 'SpiceBot_Channels', "Initial Channel list populating") starttime = time.time() while not bot.memory['SpiceBot_Channels']['InitialProcess']: @@ -61,12 +69,13 @@ def trigger_channel_list_initial(bot, trigger): if timesince < 60: pass else: - stderr("[SpiceBot_Channels] Initial Channel list populating Timed Out.") + bot_logging(bot, 'SpiceBot_Channels', "Initial Channel list populating Timed Out") bot.memory['SpiceBot_Channels']['InitialProcess'] = True channel_list_current(bot) foundchannelcount = len(bot.memory['SpiceBot_Channels']['channels'].keys()) - stderr("[SpiceBot_Channels] Channel listing finished! " + str(foundchannelcount) + " channel(s) found.") + bot_logging(bot, 'SpiceBot_Channels', "Channel listing finished! " + str(foundchannelcount) + " channel(s) found.") + set_bot_event(bot, "SpiceBot_Channels") join_all_channels(bot) chanadmin_all_channels(bot) @@ -167,6 +176,7 @@ def nickname_comand_chanstats(bot, trigger): bot.memory['SpiceBot_Channels']['ProcessLock'] = True while bot.memory['SpiceBot_Channels']['ProcessLock']: pass + join_all_channels(bot) foundchannelcount = len(bot.memory['SpiceBot_Channels']['channels'].keys()) bot.osd("[SpiceBot_Channels]", "Channel listing finished!", str(foundchannelcount) + " channel(s) found.") return diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index 81080b5..63554c2 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel import sopel.module -from sopel.tools import stderr +from sopel_modules.SpiceBot_Logs import bot_logging import os from difflib import SequenceMatcher @@ -12,7 +12,7 @@ from operator import itemgetter import threading -from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event +from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, check_bot_events import spicemanip @@ -22,17 +22,27 @@ def configure(config): def setup(bot): - stderr("[SpiceBot_CommandsQuery] Evaluating Core Commands List") + bot_logging(bot, 'SpiceBot_CommandsQuery', "Evaluating Core Commands List") threading.Thread(target=setup_thread, args=(bot,)).start() def setup_thread(bot): - bot.memory['SpiceBot_CommandsQuery'] = dict() + if 'SpiceBot_CommandsQuery' not in bot.memory: + bot.memory['SpiceBot_CommandsQuery'] = dict() + + if ['counts'] not in bot.memory['SpiceBot_CommandsQuery'].keys(): + bot.memory['SpiceBot_CommandsQuery']['counts'] = dict() + + if ['commands'] not in bot.memory['SpiceBot_CommandsQuery'].keys(): + bot.memory['SpiceBot_CommandsQuery']['commands'] = dict() + for comtype in ['module', 'nickname', 'rule']: - bot.memory['SpiceBot_CommandsQuery'][comtype + "_commands"] = dict() - bot.memory['SpiceBot_CommandsQuery'][comtype + "_commands_count"] = 0 + if comtype not in bot.memory['SpiceBot_CommandsQuery']['counts'].keys(): + bot.memory['SpiceBot_CommandsQuery']['counts'][comtype] = 0 + if comtype not in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): + bot.memory['SpiceBot_CommandsQuery']['commands'][comtype] = dict() filepathlisting = [] @@ -54,7 +64,7 @@ def setup_thread(bot): pypi_modules_dir = os.path.join(plugin_dir, pathname) filepathlisting.append(pypi_modules_dir) except Exception as e: - stderr("[SpiceBot_CommandsQuery] sopel_modules not loaded :" + str(e)) + bot_logging(bot, 'SpiceBot_CommandsQuery', "sopel_modules not loaded :" + str(e)) # Extra directories filepathlist = [] @@ -125,9 +135,7 @@ def setup_thread(bot): comtype = atlinefound["comtype"] validcoms = atlinefound["validcoms"] - comtypedict = str(comtype + "_commands") - - bot.memory['SpiceBot_CommandsQuery'][comtypedict + "_count"] += 1 + bot.memory['SpiceBot_CommandsQuery']['count'][comtype] += 1 # default command to filename if "validcoms" not in dict_from_file.keys(): @@ -139,13 +147,20 @@ def setup_thread(bot): else: comaliases = [] - bot.memory['SpiceBot_CommandsQuery'][comtypedict][maincom] = dict_from_file + bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][maincom] = dict_from_file for comalias in comaliases: - if comalias not in bot.memory['SpiceBot_CommandsQuery'][comtypedict].keys(): - bot.memory['SpiceBot_CommandsQuery'][comtypedict][comalias] = {"aliasfor": maincom} + if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys(): + bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][comalias] = {"aliasfor": maincom} - for comtype in ['module_commands', 'nickname_commands', 'rule_commands']: - stderr("[SpiceBot_CommandsQuery] Found " + str(len(bot.memory['SpiceBot_CommandsQuery'][comtype].keys())) + " " + comtype + " commands.") + for comtype in ['module', 'nickname', 'rule']: + bot_logging(bot, 'SpiceBot_CommandsQuery', "Found " + str(len(bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys())) + " " + comtype + " commands.") + + while not check_bot_events(bot, ["startup_complete"]): + pass + + for comtype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): + if comtype not in ['module', 'nickname', 'rule']: + bot_logging(bot, 'SpiceBot_CommandsQuery', "Found " + str(len(bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys())) + " " + comtype + " commands.") set_bot_event(bot, "SpiceBot_CommandsQuery") @@ -161,11 +176,10 @@ def query_detection(bot, trigger): return commands_list = dict() - for commandstype in bot.memory['SpiceBot_CommandsQuery'].keys(): - if not commandstype.endswith("_count"): - for com in bot.memory['SpiceBot_CommandsQuery'][commandstype].keys(): - if com not in commands_list.keys(): - commands_list[com] = bot.memory['SpiceBot_CommandsQuery'][commandstype][com] + for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): + for com in bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys(): + if com not in commands_list.keys(): + commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] triggerargsarray = spicemanip.main(trigger, 'create') @@ -236,10 +250,18 @@ def commandsquery_register_type(bot, command_type): if 'SpiceBot_CommandsQuery' not in bot.memory: bot.memory['SpiceBot_CommandsQuery'] = dict() + if ['counts'] not in bot.memory['SpiceBot_CommandsQuery'].keys(): + bot.memory['SpiceBot_CommandsQuery']['counts'] = dict() + + if ['commands'] not in bot.memory['SpiceBot_CommandsQuery'].keys(): + bot.memory['SpiceBot_CommandsQuery']['commands'] = dict() + if command_type not in bot.memory['SpiceBot_CommandsQuery'].keys(): - bot.memory['SpiceBot_CommandsQuery'][command_type] = dict() - bot.memory['SpiceBot_CommandsQuery'][command_type + "_count"] = 0 - bot.memory['SpiceBot_CommandsQuery'][command_type + "_count"] += 1 + if command_type not in bot.memory['SpiceBot_CommandsQuery']['counts'].keys(): + bot.memory['SpiceBot_CommandsQuery']['counts'][command_type] = 0 + if command_type not in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): + bot.memory['SpiceBot_CommandsQuery']['commands'][command_type] = dict() + bot.memory['SpiceBot_CommandsQuery']['counts'][command_type] += 1 def commandsquery_register(bot, command_type, validcoms, aliasfor=None): @@ -250,10 +272,18 @@ def commandsquery_register(bot, command_type, validcoms, aliasfor=None): if 'SpiceBot_CommandsQuery' not in bot.memory: bot.memory['SpiceBot_CommandsQuery'] = dict() + if ['counts'] not in bot.memory['SpiceBot_CommandsQuery'].keys(): + bot.memory['SpiceBot_CommandsQuery']['counts'] = dict() + + if ['commands'] not in bot.memory['SpiceBot_CommandsQuery'].keys(): + bot.memory['SpiceBot_CommandsQuery']['commands'] = dict() + if command_type not in bot.memory['SpiceBot_CommandsQuery'].keys(): - bot.memory['SpiceBot_CommandsQuery'][command_type] = dict() - bot.memory['SpiceBot_CommandsQuery'][command_type + "_count"] = 0 - bot.memory['SpiceBot_CommandsQuery'][command_type + "_count"] += 1 + if command_type not in bot.memory['SpiceBot_CommandsQuery']['counts'].keys(): + bot.memory['SpiceBot_CommandsQuery']['counts'][command_type] = 0 + if command_type not in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): + bot.memory['SpiceBot_CommandsQuery']['commands'][command_type] = dict() + bot.memory['SpiceBot_CommandsQuery']['counts'][command_type] += 1 dict_from_file = dict() @@ -268,10 +298,10 @@ def commandsquery_register(bot, command_type, validcoms, aliasfor=None): comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list') else: comaliases = [] - bot.memory['SpiceBot_CommandsQuery'][command_type][maincom] = dict_from_file + bot.memory['SpiceBot_CommandsQuery']['commands'][command_type][maincom] = dict_from_file else: comaliases = validcoms for comalias in comaliases: - if comalias not in bot.memory['SpiceBot_CommandsQuery'][command_type].keys(): - bot.memory['SpiceBot_CommandsQuery'][command_type][comalias] = {"aliasfor": aliasfor} + if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands'][command_type].keys(): + bot.memory['SpiceBot_CommandsQuery']['commands'][command_type][comalias] = {"aliasfor": aliasfor} diff --git a/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py b/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py index f1f135a..e92021b 100644 --- a/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py +++ b/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py @@ -4,7 +4,8 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel.module -from sopel.tools import stderr, Identifier +from sopel.tools import Identifier +from sopel_modules.SpiceBot_Logs import bot_logging from sopel.db import _deserialize, SopelDB import json @@ -12,7 +13,7 @@ import json def setup(bot): # Inject Database Functions - stderr("[SpiceBot_Databaseaddons] Implanting Database functions into bot.") + bot_logging(bot, 'SpiceBot_Databaseaddons', "Implanting Database functions into bot") SopelDB.reset_nick_value = SopelDBCache.reset_nick_value SopelDB.adjust_nick_value = SopelDBCache.adjust_nick_value SopelDB.reset_channel_value = SopelDBCache.reset_channel_value diff --git a/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py b/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py index bc9f133..3f8ec06 100644 --- a/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py +++ b/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py @@ -4,9 +4,10 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel.module -from sopel.tools import stderr +from sopel_modules.SpiceBot_Logs import bot_logging def setup(bot): - stderr("[SpiceBot_DatabaseCache] Setting up Database Cache.") - bot.memory['SpiceBot_DatabaseCache'] = dict() + bot_logging(bot, 'SpiceBot_DatabaseCache', "Setting up Database Cache") + if 'SpiceBot_DatabaseCache' not in bot.memory: + bot.memory['SpiceBot_DatabaseCache'] = dict() diff --git a/sopel_modules/SpiceBot_FriendlyBot/FriendlyBot.py b/sopel_modules/SpiceBot_FriendlyBot/FriendlyBot.py index e14e5a2..12b9431 100644 --- a/sopel_modules/SpiceBot_FriendlyBot/FriendlyBot.py +++ b/sopel_modules/SpiceBot_FriendlyBot/FriendlyBot.py @@ -3,7 +3,6 @@ from __future__ import unicode_literals, absolute_import, division, print_function import sopel.module -from sopel.tools import stderr import spicemanip diff --git a/sopel_modules/SpiceBot_Gender/Gender.py b/sopel_modules/SpiceBot_Gender/Gender.py index 5d5b5b1..8069f0d 100644 --- a/sopel_modules/SpiceBot_Gender/Gender.py +++ b/sopel_modules/SpiceBot_Gender/Gender.py @@ -3,9 +3,6 @@ from __future__ import unicode_literals, absolute_import, division, print_function import sopel.module -from sopel.tools import stderr - -import spicemanip def configure(config): diff --git a/sopel_modules/SpiceBot_GifSearch/gifsearch.py b/sopel_modules/SpiceBot_GifSearch/gifsearch.py index a85b916..87e971f 100644 --- a/sopel_modules/SpiceBot_GifSearch/gifsearch.py +++ b/sopel_modules/SpiceBot_GifSearch/gifsearch.py @@ -3,10 +3,10 @@ from __future__ import unicode_literals, absolute_import, division, print_function import sopel.module -from sopel.tools import stderr +from sopel_modules.SpiceBot_Logs import bot_logging from sopel.config.types import StaticSection, ValidatedAttribute -from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, check_bot_events, startup_bot_event +from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, startup_bot_event from sopel_modules.SpiceBot_CommandsQuery.CommandsQuery import commandsquery_register, commandsquery_register_type @@ -39,7 +39,7 @@ class GifAPISection(StaticSection): def configure(config): moduledir = os.path.dirname(os.path.abspath(__file__)) api_dir = os.path.join(moduledir, 'gifapi') - valid_gif_api_dict = read_directory_json_to_dict([api_dir], "Gif API", "[SpiceBot_GifSearch] ") + valid_gif_api_dict = read_directory_json_to_dict(None, [api_dir], "Gif API", "SpiceBot_GifSearch") config.define_section("SopelGifSearch", GifAPIMainSection, validate=False) config.SopelGifSearch.configure_setting('extra', 'SpiceBot_GifSearch API Extra directory') @@ -53,7 +53,7 @@ def configure(config): def setup(bot): - stderr("[SpiceBot_GifSearch] Starting Setup Procedure") + bot_logging(bot, 'SpiceBot_GifSearch', "Starting Setup Procedure") threading.Thread(target=setup_thread, args=(bot,)).start() @@ -62,7 +62,8 @@ def setup_thread(bot): startup_bot_event(bot, "SpiceBot_GifSearch") - bot.memory["SpiceBot_GifSearch"] = {"cache": {}, "badgiflinks": [], 'valid_gif_api_dict': {}} + if 'SpiceBot_GifSearch' not in bot.memory: + bot.memory["SpiceBot_GifSearch"] = {"cache": {}, "badgiflinks": [], 'valid_gif_api_dict': {}} dir_to_scan = [] @@ -74,7 +75,7 @@ def setup_thread(bot): if bot.config.SopelGifSearch.extra: dir_to_scan.append(bot.config.SopelGifSearch.extra) - valid_gif_api_dict = read_directory_json_to_dict(dir_to_scan, "Gif API", "[SpiceBot_GifSearch] ") + valid_gif_api_dict = read_directory_json_to_dict(bot, dir_to_scan, "Gif API", "SpiceBot_GifSearch") for gif_api in valid_gif_api_dict.keys(): bot.config.define_section(gif_api, GifAPISection, validate=False) @@ -85,15 +86,10 @@ def setup_thread(bot): valid_gif_api_dict[gif_api]["apikey"] = None bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'][gif_api] = valid_gif_api_dict[gif_api] - while not check_bot_events(bot, ["SpiceBot_CommandsQuery"]): - pass - commandsquery_register_type(bot, "prefix_command") for prefix_command in bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'].keys(): commandsquery_register(bot, "prefix_command", prefix_command) - stderr("[SpiceBot_CommandsQuery] Found " + str(len(bot.memory['SpiceBot_CommandsQuery']["prefix_command"].keys())) + " " + "prefix_command" + " commands.") - set_bot_event(bot, "SpiceBot_GifSearch") diff --git a/sopel_modules/SpiceBot_InsultHandler/InsultHandler.py b/sopel_modules/SpiceBot_InsultHandler/InsultHandler.py index ae18b36..724aae4 100644 --- a/sopel_modules/SpiceBot_InsultHandler/InsultHandler.py +++ b/sopel_modules/SpiceBot_InsultHandler/InsultHandler.py @@ -3,11 +3,6 @@ from __future__ import unicode_literals, absolute_import, division, print_function import sopel.module -from sopel.tools import stderr - -import spicemanip - -from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match def configure(config): diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index 0e8d6be..2ddf8e7 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -4,19 +4,48 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel.tools import stderr +from sopel.config.types import StaticSection, ValidatedAttribute import spicemanip from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match +from sopel_modules.SpiceBot_Botevents.BotEvents import check_bot_events + def configure(config): - pass + config.define_section("SpiceBot_Logs", SpiceBot_Logs_MainSection, validate=False) + config.SpiceBot_Logs.configure_setting('logging_channel', 'SpiceBot_Logs channels') + + +class SpiceBot_Logs_MainSection(StaticSection): + logging_channel = ValidatedAttribute('logging_channel', default=False) def setup(bot): - stderr("[SpiceBot_Logs] Starting Setup Procedure") - bot.memory['SpiceBot_Logs'] = {} + bot_logging(bot, 'SpiceBot_Logs', "Starting Setup Procedure") + bot.config.define_section("SpiceBot_Logs", SpiceBot_Logs_MainSection, validate=False) + if 'SpiceBot_Logs' not in bot.memory: + bot.memory['SpiceBot_Logs'] = {} + + if 'SpiceBot_Logs_queue' not in bot.memory: + bot.memory['SpiceBot_Logs_queue'] = [] + + +@sopel.module.event('001') +@sopel.module.rule('.*') +def join_log_channel(bot, trigger): + if bot.config.SpiceBot_Logs.logging_channel: + channel = bot.config.SpiceBot_Logs.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(bot.memory['SpiceBot_Logs_queue']): + bot.say(str(bot.memory['SpiceBot_Logs_queue'][0])) + del bot.memory['SpiceBot_Logs_queue'][0] @sopel.module.nickname_commands('logs') @@ -46,6 +75,17 @@ def bot_command_action(bot, trigger): def bot_logging(bot, logtype, logentry): + if 'SpiceBot_Logs_queue' not in bot.memory: + bot.memory['SpiceBot_Logs_queue'] = [] + + logmessage = "[" + logtype + "] " + logentry + + if not check_bot_events(bot, ["connected"]): + if bot.config.SpiceBot_Logs.logging_channel: + bot.memory['SpiceBot_Logs_queue'].append(logmessage) + + stderr(logmessage) + if 'SpiceBot_Logs' not in bot.memory: bot.memory['SpiceBot_Logs'] = {} diff --git a/sopel_modules/SpiceBot_Restart/Restart.py b/sopel_modules/SpiceBot_Restart/Restart.py index 146824a..17c7f49 100644 --- a/sopel_modules/SpiceBot_Restart/Restart.py +++ b/sopel_modules/SpiceBot_Restart/Restart.py @@ -4,10 +4,10 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel.module -from sopel.tools import stderr from sopel.config.types import StaticSection, ValidatedAttribute from sopel_modules.SpiceBot_SBTools import service_manip +from sopel_modules.SpiceBot_Logs import bot_logging @sopel.module.nickname_commands('restart') @@ -16,7 +16,7 @@ def nickname_comand_chanstats(bot, trigger): if not trigger.admin: bot.say("You are not authorized to perform this function.") - stderr("Recieved Command to update.") + bot_logging(bot, 'SpiceBot_Restart', "Received command from " + trigger.nick + " to restart") bot.osd("Received command from " + trigger.nick + " to restart. Be Back Soon!", bot.channels.keys()) - service_manip(bot, bot.nick, 'restart') + service_manip(bot, bot.nick, 'restart', 'SpiceBot_Restart') diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 4bbd84e..8eafded 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi import sopel from sopel.module import OP, ADMIN, VOICE, OWNER, HALFOP -from sopel.tools import stderr +from sopel_modules.SpiceBot_Logs import bot_logging HOP = HALFOP import collections @@ -195,7 +195,7 @@ def join_all_channels(bot): for channel in bot.memory['SpiceBot_Channels']['channels'].keys(): if channel not in bot.channels.keys() and channel not in bot.config.SpiceBot_Channels.chanignore: bot.write(('JOIN', bot.nick, bot.memory['SpiceBot_Channels']['channels'][channel]['name'])) - if channel not in bot.channels.keys(): + if channel not in bot.channels.keys() and bot.config.SpiceBot_Channels.operadmin: bot.write(('SAJOIN', bot.nick, bot.memory['SpiceBot_Channels']['channels'][channel]['name'])) @@ -226,44 +226,20 @@ def channel_list_current(bot): """Environment Functions""" -def service_manip(bot, servicename, dowhat): +def service_manip(bot, servicename, dowhat, log_from='service_manip'): if str(dowhat) not in ["start", "stop", "restart"]: return try: - stderr(str(dowhat).title() + "ing " + str(servicename) + ".service.") + bot_logging(bot, log_from, str(dowhat).title() + "ing " + str(servicename) + ".service.") os.system("sudo service " + str(servicename) + " " + str(dowhat)) except Exception as e: - stderr(str(dowhat).title() + "ing " + str(servicename) + ".service Failed: " + str(e)) - - -def spicebot_update(bot, deps="False"): - stderr("Updating " + bot.nick + " from Github.") - - pipcommand = "sudo pip3 install --upgrade" - if deps == "False": - pipcommand += " --no-deps" - pipcommand += " --force-reinstall" - pipcommand += " git+" + str(bot.config.SpiceBot_Update.gitrepo) + "@" + str(bot.config.SpiceBot_Update.gitbranch) - stderr(pipcommand) - for line in os.popen(pipcommand).read().split('\n'): - stderr(line) - - # Remove stock modules, if present - main_sopel_dir = os.path.dirname(os.path.abspath(sopel.__file__)) - modules_dir = os.path.join(main_sopel_dir, 'modules') - stockdir = os.path.join(modules_dir, "stock") - if not os.path.exists(stockdir) or not os.path.isdir(stockdir): - os.system("sudo mkdir " + stockdir) - for pathname in os.listdir(modules_dir): - path = os.path.join(modules_dir, pathname) - if (os.path.isfile(path) and path.endswith('.py') and not path.startswith('_')): - os.system("sudo mv " + path + " " + stockdir) + bot_logging(bot, log_from, str(dowhat).title() + "ing " + str(servicename) + ".service Failed: " + str(e)) """Config Reading Functions""" -def read_directory_json_to_dict(directories, configtypename="Config File", stderrname=''): +def read_directory_json_to_dict(bot, directories, configtypename="Config File", log_from='read_directory_json_to_dict'): if not isinstance(directories, list): directories = [directories] @@ -277,8 +253,6 @@ def read_directory_json_to_dict(directories, configtypename="Config File", stder filepath = os.path.join(directory, file) if os.path.isfile(filepath): filesprocess.append(filepath) - else: - stderr(stderrname + directory) for filepath in filesprocess: @@ -290,7 +264,8 @@ def read_directory_json_to_dict(directories, configtypename="Config File", stder dict_from_file = eval(infread) except Exception as e: filereadgood = False - stderr(stderrname + "Error loading %s: %s (%s)" % (configtypename, e, filepath)) + if bot: + bot_logging(bot, log_from, "Error loading %s: %s (%s)" % (configtypename, e, filepath)) dict_from_file = dict() # Close File inf.close() @@ -304,9 +279,11 @@ def read_directory_json_to_dict(directories, configtypename="Config File", stder fileopenfail += 1 if filecount: - stderr(stderrname + 'Registered %d %s files,' % (filecount, configtypename)) - stderr(stderrname + '%d %s files failed to load' % (fileopenfail, configtypename)) + if bot: + bot_logging(bot, log_from, 'Registered %d %s files,' % (filecount, configtypename)) + bot_logging(bot, log_from, '%d %s files failed to load' % (fileopenfail, configtypename)) else: - stderr(stderrname + "Warning: Couldn't load any %s files" % (configtypename)) + if bot: + bot_logging(bot, log_from, "Warning: Couldn't load any %s files" % (configtypename)) return configs_dict diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py index 322511f..5bf1e6b 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py @@ -3,11 +3,12 @@ from __future__ import unicode_literals, absolute_import, division, print_function from sopel import module -from sopel.tools import stderr +from sopel_modules.SpiceBot_Logs import bot_logging from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, check_bot_events -from sopel_modules.SpiceBot_CommandsQuery.CommandsQuery import commandsquery_register +from sopel_modules.SpiceBot_SBTools import humanized_time +import time def configure(config): @@ -35,7 +36,7 @@ def bot_startup_monologue(bot, trigger): def startup_fresh(bot, trigger): # Startup - stderr("[SpiceBot_StartupMonologue] " + bot.nick + " is now starting. Please wait while I load my configuration.") + bot_logging(bot, 'SpiceBot_StartupMonologue', bot.nick + " is now starting. Please wait while I load my configuration") bot.osd(" is now starting. Please wait while I load my configuration.", bot.channels.keys(), 'ACTION') startupcomplete = [bot.nick + " startup complete"] @@ -44,22 +45,30 @@ def startup_fresh(bot, trigger): pass availablecomsnum, availablecomsfiles = 0, 0 - - for commandstype in bot.memory['SpiceBot_CommandsQuery'].keys(): - if commandstype.endswith("_count"): - availablecomsfiles += bot.memory['SpiceBot_CommandsQuery'][commandstype] - else: - availablecomsnum += len(bot.memory['SpiceBot_CommandsQuery'][commandstype].keys()) + for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): + availablecomsnum += len(bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys()) + for commandstype in bot.memory['SpiceBot_CommandsQuery']['counts'].keys(): + availablecomsfiles += bot.memory['SpiceBot_CommandsQuery']['counts'][commandstype] startupcomplete.append("There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.") - stderr("[SpiceBot_StartupMonologue] " + "There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.") + bot_logging(bot, 'SpiceBot_StartupMonologue', "There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.") + + while not check_bot_events(bot, ["SpiceBot_Channels"]): + pass + + botcount = len(bot.channels.keys()) + servercount = len(bot.memory['SpiceBot_Channels']['channels'].keys()) + startupcomplete.append("I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server.") while not check_bot_events(bot, ["startup_complete"]): pass + timesince = humanized_time(time.time() - bot.memory["SpiceBot_Uptime"]) + bot.osd("Startup took" + timesince) + # Announce to chan, then handle some closing stuff + bot_logging(bot, 'SpiceBot_StartupMonologue', bot.nick + " startup complete") bot.osd(startupcomplete, bot.channels.keys()) - stderr("[SpiceBot_StartupMonologue] " + bot.nick + " startup complete") set_bot_event(bot, "SpiceBot_StartupMonologue") @@ -67,5 +76,5 @@ def startup_fresh(bot, trigger): def startup_reconnect(bot, trigger): # Startup - stderr("[SpiceBot_StartupMonologue] " + bot.nick + " has reconnected.") + bot_logging(bot, 'SpiceBot_StartupMonologue', bot.nick + " has reconnected.") bot.osd(" has reconnected.", bot.channels.keys(), 'ACTION') diff --git a/sopel_modules/SpiceBot_Update/Update.py b/sopel_modules/SpiceBot_Update/Update.py index 06b93f0..3b8d06d 100644 --- a/sopel_modules/SpiceBot_Update/Update.py +++ b/sopel_modules/SpiceBot_Update/Update.py @@ -4,12 +4,14 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel.module -from sopel.tools import stderr +from sopel_modules.SpiceBot_Logs import bot_logging from sopel.config.types import StaticSection, ValidatedAttribute +import os + import spicemanip -from sopel_modules.SpiceBot_SBTools import service_manip, spicebot_update, sopel_triggerargs, command_permissions_check +from sopel_modules.SpiceBot_SBTools import service_manip, sopel_triggerargs, command_permissions_check class SpiceBot_Update_MainSection(StaticSection): @@ -24,7 +26,7 @@ def configure(config): def setup(bot): - stderr("[SpiceBot_Update] Initial Setup processing...") + bot_logging(bot, 'SpiceBot_Update', "Initial Setup processing") bot.config.define_section("SpiceBot_Update", SpiceBot_Update_MainSection, validate=False) @@ -48,7 +50,7 @@ def nickname_comand_chanstats(bot, trigger): triggerargs = spicemanip.main(triggerargs, '2+', 'list') - stderr("Recieved Command to update.") + bot_logging(bot, 'SpiceBot_Update', "Received command from " + trigger.nick + " to update from Github and restart") bot.osd("Received command from " + trigger.nick + " to update from Github and restart. Be Back Soon!", bot.channels.keys()) if commandused == 'nodeps': @@ -56,4 +58,28 @@ def nickname_comand_chanstats(bot, trigger): if commandused == 'deps': spicebot_update(bot, "True") - service_manip(bot, bot.nick, 'restart') + service_manip(bot, bot.nick, 'restart', 'SpiceBot_Update') + + +def spicebot_update(bot, deps="False"): + + pipcommand = "sudo pip3 install --upgrade" + if deps == "False": + pipcommand += " --no-deps" + pipcommand += " --force-reinstall" + pipcommand += " git+" + str(bot.config.SpiceBot_Update.gitrepo) + "@" + str(bot.config.SpiceBot_Update.gitbranch) + + bot_logging(bot, 'SpiceBot_Update', "Running `" + pipcommand + "`") + for line in os.popen(pipcommand).read().split('\n'): + bot_logging(bot, 'SpiceBot_Update', " " + line) + + # Remove stock modules, if present + main_sopel_dir = os.path.dirname(os.path.abspath(sopel.__file__)) + modules_dir = os.path.join(main_sopel_dir, 'modules') + stockdir = os.path.join(modules_dir, "stock") + if not os.path.exists(stockdir) or not os.path.isdir(stockdir): + os.system("sudo mkdir " + stockdir) + for pathname in os.listdir(modules_dir): + path = os.path.join(modules_dir, pathname) + if (os.path.isfile(path) and path.endswith('.py') and not path.startswith('_')): + os.system("sudo mv " + path + " " + stockdir) diff --git a/sopel_modules/SpiceBot_Uptime/Uptime.py b/sopel_modules/SpiceBot_Uptime/Uptime.py index 282eb71..43dd5bc 100644 --- a/sopel_modules/SpiceBot_Uptime/Uptime.py +++ b/sopel_modules/SpiceBot_Uptime/Uptime.py @@ -3,21 +3,23 @@ from __future__ import unicode_literals, absolute_import, division, print_function import sopel.module -from sopel.tools import stderr - -import spicemanip import time from sopel_modules.SpiceBot_SBTools import humanized_time +from sopel_modules.SpiceBot_Logs import bot_logging + def configure(config): pass def setup(bot): - bot.memory["SpiceBot_Uptime"] = time.time() + if 'SpiceBot_Uptime' not in bot.memory: + now = time.time() + bot_logging(bot, 'SpiceBot_Uptime', "Start time set to " + str(time.time())) + bot.memory["SpiceBot_Uptime"] = now @sopel.module.nickname_commands('uptime') diff --git a/sopel_modules/SpiceBot_osd/__init__.py b/sopel_modules/SpiceBot_osd/__init__.py index 7890905..fb4c98f 100644 --- a/sopel_modules/SpiceBot_osd/__init__.py +++ b/sopel_modules/SpiceBot_osd/__init__.py @@ -11,9 +11,11 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.bot from sopel import tools, module -from sopel.tools import stderr, Identifier +from sopel.tools import Identifier from sopel.config.types import StaticSection, ValidatedAttribute +from sopel_modules.SpiceBot_Logs import bot_logging + import time from collections import abc import sys @@ -33,7 +35,7 @@ def configure(config): def setup(bot): # Inject OSD - stderr("[Sopel-OSD] Implanting OSD function into bot.") + bot_logging(bot, 'SpiceBot_OSD', "Implanting OSD function into bot") bot.osd = SopelOSD.osd bot.SopelWrapper.osd = SopelOSD.SopelWrapper.osd tools.get_available_message_bytes = ToolsOSD.get_available_message_bytes @@ -41,14 +43,14 @@ def setup(bot): tools.get_message_recipientgroups = ToolsOSD.get_message_recipientgroups # overwrite default bot messaging - stderr("[Sopel-OSD] Overwrite Default Sopel messaging commands.") + bot_logging(bot, 'SpiceBot_OSD', "Overwrite Default Sopel messaging commands") bot.SopelWrapper.say = SopelOSD.SopelWrapper.say bot.SopelWrapper.action = SopelOSD.SopelWrapper.action bot.SopelWrapper.notice = SopelOSD.SopelWrapper.notice bot.SopelWrapper.reply = SopelOSD.SopelWrapper.reply # verify config settings for server - stderr("[Sopel-OSD] Checking for config settings.") + bot_logging(bot, 'SpiceBot_OSD', "Checking for config settings") bot.config.define_section("MAXTARGCONFIG", MAXTARGCONFIG, validate=False) From ad82cd07e44a769d88b8416ca05e882bc129992d Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 4 May 2019 16:26:51 -0400 Subject: [PATCH 02/15] Repair Broken Logging import --- sopel_modules/SpiceBot_Botevents/BotEvents.py | 2 +- sopel_modules/SpiceBot_Botevents/Startup_Complete.py | 2 +- sopel_modules/SpiceBot_Channels/Channels.py | 2 +- sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py | 2 +- sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py | 2 +- sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py | 2 +- sopel_modules/SpiceBot_GifSearch/gifsearch.py | 2 +- sopel_modules/SpiceBot_Restart/Restart.py | 2 +- sopel_modules/SpiceBot_SBTools/__init__.py | 2 +- sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py | 2 +- sopel_modules/SpiceBot_Update/Update.py | 2 +- sopel_modules/SpiceBot_Uptime/Uptime.py | 2 +- sopel_modules/SpiceBot_osd/__init__.py | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/sopel_modules/SpiceBot_Botevents/BotEvents.py b/sopel_modules/SpiceBot_Botevents/BotEvents.py index 5ec3128..63701e2 100644 --- a/sopel_modules/SpiceBot_Botevents/BotEvents.py +++ b/sopel_modules/SpiceBot_Botevents/BotEvents.py @@ -6,7 +6,7 @@ Sopel BotEvents is a poor mans way to create module load order dependencies from __future__ import unicode_literals, absolute_import, division, print_function import sopel.module -from sopel_modules.SpiceBot_Logs import bot_logging +from sopel_modules.SpiceBot_Logs.Logs import bot_logging import threading diff --git a/sopel_modules/SpiceBot_Botevents/Startup_Complete.py b/sopel_modules/SpiceBot_Botevents/Startup_Complete.py index 6f211eb..0fcd84f 100644 --- a/sopel_modules/SpiceBot_Botevents/Startup_Complete.py +++ b/sopel_modules/SpiceBot_Botevents/Startup_Complete.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals, absolute_import, division, print_function import sopel.module -from sopel_modules.SpiceBot_Logs import bot_logging +from sopel_modules.SpiceBot_Logs.Logs import bot_logging from .BotEvents import set_bot_event, check_bot_startup diff --git a/sopel_modules/SpiceBot_Channels/Channels.py b/sopel_modules/SpiceBot_Channels/Channels.py index 7341b8f..e3f697d 100644 --- a/sopel_modules/SpiceBot_Channels/Channels.py +++ b/sopel_modules/SpiceBot_Channels/Channels.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel.module -from sopel_modules.SpiceBot_Logs import bot_logging +from sopel_modules.SpiceBot_Logs.Logs import bot_logging from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, startup_bot_event diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index 63554c2..57774cb 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel import sopel.module -from sopel_modules.SpiceBot_Logs import bot_logging +from sopel_modules.SpiceBot_Logs.Logs import bot_logging import os from difflib import SequenceMatcher diff --git a/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py b/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py index e92021b..3bd1806 100644 --- a/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py +++ b/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel.module from sopel.tools import Identifier -from sopel_modules.SpiceBot_Logs import bot_logging +from sopel_modules.SpiceBot_Logs.Logs import bot_logging from sopel.db import _deserialize, SopelDB import json diff --git a/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py b/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py index 3f8ec06..1ae2841 100644 --- a/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py +++ b/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel.module -from sopel_modules.SpiceBot_Logs import bot_logging +from sopel_modules.SpiceBot_Logs.Logs import bot_logging def setup(bot): diff --git a/sopel_modules/SpiceBot_GifSearch/gifsearch.py b/sopel_modules/SpiceBot_GifSearch/gifsearch.py index 87e971f..f2e9bcb 100644 --- a/sopel_modules/SpiceBot_GifSearch/gifsearch.py +++ b/sopel_modules/SpiceBot_GifSearch/gifsearch.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals, absolute_import, division, print_function import sopel.module -from sopel_modules.SpiceBot_Logs import bot_logging +from sopel_modules.SpiceBot_Logs.Logs import bot_logging from sopel.config.types import StaticSection, ValidatedAttribute from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, startup_bot_event diff --git a/sopel_modules/SpiceBot_Restart/Restart.py b/sopel_modules/SpiceBot_Restart/Restart.py index 17c7f49..246f7b8 100644 --- a/sopel_modules/SpiceBot_Restart/Restart.py +++ b/sopel_modules/SpiceBot_Restart/Restart.py @@ -7,7 +7,7 @@ import sopel.module from sopel.config.types import StaticSection, ValidatedAttribute from sopel_modules.SpiceBot_SBTools import service_manip -from sopel_modules.SpiceBot_Logs import bot_logging +from sopel_modules.SpiceBot_Logs.Logs import bot_logging @sopel.module.nickname_commands('restart') diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 8eafded..ec207bd 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi import sopel from sopel.module import OP, ADMIN, VOICE, OWNER, HALFOP -from sopel_modules.SpiceBot_Logs import bot_logging +from sopel_modules.SpiceBot_Logs.Logs import bot_logging HOP = HALFOP import collections diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py index 5bf1e6b..29a5636 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals, absolute_import, division, print_function from sopel import module -from sopel_modules.SpiceBot_Logs import bot_logging +from sopel_modules.SpiceBot_Logs.Logs import bot_logging from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, check_bot_events diff --git a/sopel_modules/SpiceBot_Update/Update.py b/sopel_modules/SpiceBot_Update/Update.py index 3b8d06d..7797e44 100644 --- a/sopel_modules/SpiceBot_Update/Update.py +++ b/sopel_modules/SpiceBot_Update/Update.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel.module -from sopel_modules.SpiceBot_Logs import bot_logging +from sopel_modules.SpiceBot_Logs.Logs import bot_logging from sopel.config.types import StaticSection, ValidatedAttribute import os diff --git a/sopel_modules/SpiceBot_Uptime/Uptime.py b/sopel_modules/SpiceBot_Uptime/Uptime.py index 43dd5bc..03a5f14 100644 --- a/sopel_modules/SpiceBot_Uptime/Uptime.py +++ b/sopel_modules/SpiceBot_Uptime/Uptime.py @@ -8,7 +8,7 @@ import time from sopel_modules.SpiceBot_SBTools import humanized_time -from sopel_modules.SpiceBot_Logs import bot_logging +from sopel_modules.SpiceBot_Logs.Logs import bot_logging def configure(config): diff --git a/sopel_modules/SpiceBot_osd/__init__.py b/sopel_modules/SpiceBot_osd/__init__.py index fb4c98f..ae143d4 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 import bot_logging +from sopel_modules.SpiceBot_Logs.Logs import bot_logging import time from collections import abc From 2c9340b92b0c0d273e3f8866243b0105bb7583fb Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 4 May 2019 16:37:46 -0400 Subject: [PATCH 03/15] Test Import cycle --- sopel_modules/SpiceBot_SBTools/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index ec207bd..fc44f03 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -5,7 +5,6 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi import sopel from sopel.module import OP, ADMIN, VOICE, OWNER, HALFOP -from sopel_modules.SpiceBot_Logs.Logs import bot_logging HOP = HALFOP import collections @@ -227,6 +226,7 @@ def channel_list_current(bot): def service_manip(bot, servicename, dowhat, log_from='service_manip'): + from sopel_modules.SpiceBot_Logs.Logs import bot_logging if str(dowhat) not in ["start", "stop", "restart"]: return try: @@ -240,6 +240,7 @@ def service_manip(bot, servicename, dowhat, log_from='service_manip'): def read_directory_json_to_dict(bot, directories, configtypename="Config File", log_from='read_directory_json_to_dict'): + from sopel_modules.SpiceBot_Logs.Logs import bot_logging if not isinstance(directories, list): directories = [directories] From d7d36fa015434095875d926b23ac7756036c8639 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 4 May 2019 16:46:21 -0400 Subject: [PATCH 04/15] Remove Import --- sopel_modules/SpiceBot_SBTools/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index fc44f03..553282b 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -226,7 +226,6 @@ def channel_list_current(bot): def service_manip(bot, servicename, dowhat, log_from='service_manip'): - from sopel_modules.SpiceBot_Logs.Logs import bot_logging if str(dowhat) not in ["start", "stop", "restart"]: return try: @@ -240,7 +239,6 @@ def service_manip(bot, servicename, dowhat, log_from='service_manip'): def read_directory_json_to_dict(bot, directories, configtypename="Config File", log_from='read_directory_json_to_dict'): - from sopel_modules.SpiceBot_Logs.Logs import bot_logging if not isinstance(directories, list): directories = [directories] From 1882582a9a1b7648521d0691da1ad862f1c36cf9 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 4 May 2019 16:50:19 -0400 Subject: [PATCH 05/15] Remove Import --- sopel_modules/SpiceBot_Logs/Logs.py | 7 ++----- sopel_modules/SpiceBot_SBTools/__init__.py | 2 ++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index 2ddf8e7..3aa7879 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -10,8 +10,6 @@ import spicemanip from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match -from sopel_modules.SpiceBot_Botevents.BotEvents import check_bot_events - def configure(config): config.define_section("SpiceBot_Logs", SpiceBot_Logs_MainSection, validate=False) @@ -80,9 +78,8 @@ def bot_logging(bot, logtype, logentry): logmessage = "[" + logtype + "] " + logentry - if not check_bot_events(bot, ["connected"]): - if bot.config.SpiceBot_Logs.logging_channel: - bot.memory['SpiceBot_Logs_queue'].append(logmessage) + if bot.config.SpiceBot_Logs.logging_channel: + bot.memory['SpiceBot_Logs_queue'].append(logmessage) stderr(logmessage) diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 553282b..8de382d 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -7,6 +7,8 @@ import sopel from sopel.module import OP, ADMIN, VOICE, OWNER, HALFOP HOP = HALFOP +from sopel_modules.SpiceBot_Logs.Logs import bot_logging + import collections import re import os From e7c7cc87e411c1496d0cbe4b2534840ca0d39f17 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 4 May 2019 16:57:32 -0400 Subject: [PATCH 06/15] migrate Logging Features --- sopel_modules/SpiceBot_Botevents/BotEvents.py | 2 +- .../SpiceBot_Botevents/Startup_Complete.py | 2 +- sopel_modules/SpiceBot_Channels/Channels.py | 4 +-- .../SpiceBot_CommandsQuery/CommandsQuery.py | 3 +- .../Databaseaddons.py | 2 +- .../SpiceBot_Database_Cache/DatabaseCache.py | 2 +- sopel_modules/SpiceBot_GifSearch/gifsearch.py | 3 +- sopel_modules/SpiceBot_Logs/Logs.py | 23 --------------- sopel_modules/SpiceBot_Restart/Restart.py | 3 +- sopel_modules/SpiceBot_SBTools/__init__.py | 28 +++++++++++++++++-- .../StartupMonologue.py | 3 +- sopel_modules/SpiceBot_Update/Update.py | 3 +- sopel_modules/SpiceBot_Uptime/Uptime.py | 2 +- sopel_modules/SpiceBot_osd/__init__.py | 2 +- 14 files changed, 39 insertions(+), 43 deletions(-) diff --git a/sopel_modules/SpiceBot_Botevents/BotEvents.py b/sopel_modules/SpiceBot_Botevents/BotEvents.py index 63701e2..57db01d 100644 --- a/sopel_modules/SpiceBot_Botevents/BotEvents.py +++ b/sopel_modules/SpiceBot_Botevents/BotEvents.py @@ -6,7 +6,7 @@ Sopel BotEvents is a poor mans way to create module load order dependencies from __future__ import unicode_literals, absolute_import, division, print_function import sopel.module -from sopel_modules.SpiceBot_Logs.Logs import bot_logging +from sopel_modules.SpiceBot_SBTools import bot_logging import threading diff --git a/sopel_modules/SpiceBot_Botevents/Startup_Complete.py b/sopel_modules/SpiceBot_Botevents/Startup_Complete.py index 0fcd84f..ad8e106 100644 --- a/sopel_modules/SpiceBot_Botevents/Startup_Complete.py +++ b/sopel_modules/SpiceBot_Botevents/Startup_Complete.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals, absolute_import, division, print_function import sopel.module -from sopel_modules.SpiceBot_Logs.Logs import bot_logging +from sopel_modules.SpiceBot_SBTools import bot_logging from .BotEvents import set_bot_event, check_bot_startup diff --git a/sopel_modules/SpiceBot_Channels/Channels.py b/sopel_modules/SpiceBot_Channels/Channels.py index e3f697d..54dca05 100644 --- a/sopel_modules/SpiceBot_Channels/Channels.py +++ b/sopel_modules/SpiceBot_Channels/Channels.py @@ -4,7 +4,6 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel.module -from sopel_modules.SpiceBot_Logs.Logs import bot_logging from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, startup_bot_event @@ -15,7 +14,8 @@ import spicemanip from sopel_modules.SpiceBot_SBTools import ( sopel_triggerargs, inlist, topic_compile, channel_privs, - join_all_channels, chanadmin_all_channels, channel_list_current + join_all_channels, chanadmin_all_channels, channel_list_current, + bot_logging ) diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index 57774cb..45deae7 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -4,7 +4,6 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel import sopel.module -from sopel_modules.SpiceBot_Logs.Logs import bot_logging import os from difflib import SequenceMatcher @@ -12,7 +11,7 @@ from operator import itemgetter import threading -from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, check_bot_events +from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, check_bot_events, bot_logging import spicemanip diff --git a/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py b/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py index 3bd1806..7c07129 100644 --- a/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py +++ b/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel.module from sopel.tools import Identifier -from sopel_modules.SpiceBot_Logs.Logs import bot_logging +from sopel_modules.SpiceBot_SBTools import bot_logging from sopel.db import _deserialize, SopelDB import json diff --git a/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py b/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py index 1ae2841..754d0ed 100644 --- a/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py +++ b/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel.module -from sopel_modules.SpiceBot_Logs.Logs import bot_logging +from sopel_modules.SpiceBot_SBTools import bot_logging def setup(bot): diff --git a/sopel_modules/SpiceBot_GifSearch/gifsearch.py b/sopel_modules/SpiceBot_GifSearch/gifsearch.py index f2e9bcb..a12c189 100644 --- a/sopel_modules/SpiceBot_GifSearch/gifsearch.py +++ b/sopel_modules/SpiceBot_GifSearch/gifsearch.py @@ -3,14 +3,13 @@ from __future__ import unicode_literals, absolute_import, division, print_function import sopel.module -from sopel_modules.SpiceBot_Logs.Logs import bot_logging from sopel.config.types import StaticSection, ValidatedAttribute from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, startup_bot_event from sopel_modules.SpiceBot_CommandsQuery.CommandsQuery import commandsquery_register, commandsquery_register_type -from sopel_modules.SpiceBot_SBTools import read_directory_json_to_dict, sopel_triggerargs +from sopel_modules.SpiceBot_SBTools import read_directory_json_to_dict, sopel_triggerargs, bot_logging import spicemanip diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index 3aa7879..9bf46d1 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -69,26 +69,3 @@ def bot_command_action(bot, trigger): bot.osd("Is Examining " + str(logtype) + " log(s).") for line in bot.memory['SpiceBot_Logs'][logtype]: bot.osd(str(line), trigger.sender, 'action') - - -def bot_logging(bot, logtype, logentry): - - if 'SpiceBot_Logs_queue' not in bot.memory: - bot.memory['SpiceBot_Logs_queue'] = [] - - logmessage = "[" + logtype + "] " + logentry - - if bot.config.SpiceBot_Logs.logging_channel: - bot.memory['SpiceBot_Logs_queue'].append(logmessage) - - stderr(logmessage) - - if 'SpiceBot_Logs' not in bot.memory: - bot.memory['SpiceBot_Logs'] = {} - - if logtype not in bot.memory['SpiceBot_Logs'].keys(): - bot.memory['SpiceBot_Logs'][logtype] = [] - - bot.memory['SpiceBot_Logs'][logtype].append(logentry) - if len(bot.memory['SpiceBot_Logs'][logtype]) > 10: - del bot.memory['SpiceBot_Logs'][logtype][0] diff --git a/sopel_modules/SpiceBot_Restart/Restart.py b/sopel_modules/SpiceBot_Restart/Restart.py index 246f7b8..58baea5 100644 --- a/sopel_modules/SpiceBot_Restart/Restart.py +++ b/sopel_modules/SpiceBot_Restart/Restart.py @@ -6,8 +6,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi import sopel.module from sopel.config.types import StaticSection, ValidatedAttribute -from sopel_modules.SpiceBot_SBTools import service_manip -from sopel_modules.SpiceBot_Logs.Logs import bot_logging +from sopel_modules.SpiceBot_SBTools import service_manip, bot_logging @sopel.module.nickname_commands('restart') diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 8de382d..26fb14c 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -7,8 +7,6 @@ import sopel from sopel.module import OP, ADMIN, VOICE, OWNER, HALFOP HOP = HALFOP -from sopel_modules.SpiceBot_Logs.Logs import bot_logging - import collections import re import os @@ -88,6 +86,32 @@ def command_permissions_check(bot, trigger, privslist): return True +"""Logging""" + + +def bot_logging(bot, logtype, logentry): + + if 'SpiceBot_Logs_queue' not in bot.memory: + bot.memory['SpiceBot_Logs_queue'] = [] + + logmessage = "[" + logtype + "] " + logentry + + if bot.config.SpiceBot_Logs.logging_channel: + bot.memory['SpiceBot_Logs_queue'].append(logmessage) + + stderr(logmessage) + + if 'SpiceBot_Logs' not in bot.memory: + bot.memory['SpiceBot_Logs'] = {} + + if logtype not in bot.memory['SpiceBot_Logs'].keys(): + bot.memory['SpiceBot_Logs'][logtype] = [] + + bot.memory['SpiceBot_Logs'][logtype].append(logentry) + if len(bot.memory['SpiceBot_Logs'][logtype]) > 10: + del bot.memory['SpiceBot_Logs'][logtype][0] + + """ Time """ diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py index 29a5636..0a0e0ef 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py @@ -3,11 +3,10 @@ from __future__ import unicode_literals, absolute_import, division, print_function from sopel import module -from sopel_modules.SpiceBot_Logs.Logs import bot_logging from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, check_bot_events -from sopel_modules.SpiceBot_SBTools import humanized_time +from sopel_modules.SpiceBot_SBTools import humanized_time, bot_logging import time diff --git a/sopel_modules/SpiceBot_Update/Update.py b/sopel_modules/SpiceBot_Update/Update.py index 7797e44..c137b5c 100644 --- a/sopel_modules/SpiceBot_Update/Update.py +++ b/sopel_modules/SpiceBot_Update/Update.py @@ -4,14 +4,13 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel.module -from sopel_modules.SpiceBot_Logs.Logs import bot_logging from sopel.config.types import StaticSection, ValidatedAttribute import os import spicemanip -from sopel_modules.SpiceBot_SBTools import service_manip, sopel_triggerargs, command_permissions_check +from sopel_modules.SpiceBot_SBTools import service_manip, sopel_triggerargs, command_permissions_check, bot_logging class SpiceBot_Update_MainSection(StaticSection): diff --git a/sopel_modules/SpiceBot_Uptime/Uptime.py b/sopel_modules/SpiceBot_Uptime/Uptime.py index 03a5f14..1e56e13 100644 --- a/sopel_modules/SpiceBot_Uptime/Uptime.py +++ b/sopel_modules/SpiceBot_Uptime/Uptime.py @@ -8,7 +8,7 @@ import time from sopel_modules.SpiceBot_SBTools import humanized_time -from sopel_modules.SpiceBot_Logs.Logs import bot_logging +from sopel_modules.SpiceBot_SBTools import bot_logging def configure(config): diff --git a/sopel_modules/SpiceBot_osd/__init__.py b/sopel_modules/SpiceBot_osd/__init__.py index ae143d4..92c3810 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 bot_logging +from sopel_modules.SpiceBot_SBTools import bot_logging import time from collections import abc From 59218bedf4d168aa1cffa3f51a61b2b961d53574 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 4 May 2019 17:01:41 -0400 Subject: [PATCH 07/15] More Logging Tweaks --- sopel_modules/SpiceBot_Botevents/Connected.py | 2 ++ sopel_modules/SpiceBot_Logs/Logs.py | 2 +- sopel_modules/SpiceBot_SBTools/__init__.py | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_Botevents/Connected.py b/sopel_modules/SpiceBot_Botevents/Connected.py index d804c01..1c62e49 100644 --- a/sopel_modules/SpiceBot_Botevents/Connected.py +++ b/sopel_modules/SpiceBot_Botevents/Connected.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from .BotEvents import check_bot_events, startup_bot_event, set_bot_event +from sopel_modules.SpiceBot_SBTools import bot_logging import time @@ -21,3 +22,4 @@ def bot_startup_connection(bot, trigger): time.sleep(1) set_bot_event(bot, "connected") + bot_logging(bot, 'Sopel_BotEvents', "Connected to IRC") diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index 9bf46d1..8086580 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -8,7 +8,7 @@ from sopel.config.types import StaticSection, ValidatedAttribute import spicemanip -from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match +from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match, bot_logging def configure(config): diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 26fb14c..ab494cd 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi import sopel from sopel.module import OP, ADMIN, VOICE, OWNER, HALFOP +from sopel.tools import stderr HOP = HALFOP import collections From 1ebab29aa9459a7fbdeba99ad40d2fbab6e17403 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 4 May 2019 17:04:46 -0400 Subject: [PATCH 08/15] Error --- .../SpiceBot_CommandsQuery/CommandsQuery.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index 45deae7..9755489 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -31,10 +31,10 @@ def setup_thread(bot): if 'SpiceBot_CommandsQuery' not in bot.memory: bot.memory['SpiceBot_CommandsQuery'] = dict() - if ['counts'] not in bot.memory['SpiceBot_CommandsQuery'].keys(): + if 'counts' not in bot.memory['SpiceBot_CommandsQuery'].keys(): bot.memory['SpiceBot_CommandsQuery']['counts'] = dict() - if ['commands'] not in bot.memory['SpiceBot_CommandsQuery'].keys(): + if 'commands' not in bot.memory['SpiceBot_CommandsQuery'].keys(): bot.memory['SpiceBot_CommandsQuery']['commands'] = dict() for comtype in ['module', 'nickname', 'rule']: @@ -249,10 +249,10 @@ def commandsquery_register_type(bot, command_type): if 'SpiceBot_CommandsQuery' not in bot.memory: bot.memory['SpiceBot_CommandsQuery'] = dict() - if ['counts'] not in bot.memory['SpiceBot_CommandsQuery'].keys(): + if 'counts' not in bot.memory['SpiceBot_CommandsQuery'].keys(): bot.memory['SpiceBot_CommandsQuery']['counts'] = dict() - if ['commands'] not in bot.memory['SpiceBot_CommandsQuery'].keys(): + if 'commands' not in bot.memory['SpiceBot_CommandsQuery'].keys(): bot.memory['SpiceBot_CommandsQuery']['commands'] = dict() if command_type not in bot.memory['SpiceBot_CommandsQuery'].keys(): @@ -271,10 +271,10 @@ def commandsquery_register(bot, command_type, validcoms, aliasfor=None): if 'SpiceBot_CommandsQuery' not in bot.memory: bot.memory['SpiceBot_CommandsQuery'] = dict() - if ['counts'] not in bot.memory['SpiceBot_CommandsQuery'].keys(): + if 'counts' not in bot.memory['SpiceBot_CommandsQuery'].keys(): bot.memory['SpiceBot_CommandsQuery']['counts'] = dict() - if ['commands'] not in bot.memory['SpiceBot_CommandsQuery'].keys(): + if 'commands' not in bot.memory['SpiceBot_CommandsQuery'].keys(): bot.memory['SpiceBot_CommandsQuery']['commands'] = dict() if command_type not in bot.memory['SpiceBot_CommandsQuery'].keys(): From cf2771a1a1a1e46f05d0aef2b2c54b4ac75b59b2 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 4 May 2019 17:05:52 -0400 Subject: [PATCH 09/15] missing s --- sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index 9755489..0d3f6fc 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -134,7 +134,7 @@ def setup_thread(bot): comtype = atlinefound["comtype"] validcoms = atlinefound["validcoms"] - bot.memory['SpiceBot_CommandsQuery']['count'][comtype] += 1 + bot.memory['SpiceBot_CommandsQuery']['counts'][comtype] += 1 # default command to filename if "validcoms" not in dict_from_file.keys(): From 835b6aa0b867ed5654d27d091c5e7d1ad18d0e5a Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 4 May 2019 17:16:53 -0400 Subject: [PATCH 10/15] add newlines to logging --- sopel_modules/SpiceBot_SBTools/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index ab494cd..7a30865 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -95,7 +95,7 @@ def bot_logging(bot, logtype, logentry): if 'SpiceBot_Logs_queue' not in bot.memory: bot.memory['SpiceBot_Logs_queue'] = [] - logmessage = "[" + logtype + "] " + logentry + logmessage = "\n[" + logtype + "] " + logentry + "\n" if bot.config.SpiceBot_Logs.logging_channel: bot.memory['SpiceBot_Logs_queue'].append(logmessage) From 03f15c0b295b4f7ff14b8def14289675dc847a07 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 4 May 2019 17:18:26 -0400 Subject: [PATCH 11/15] startupcomplete.append --- sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py index 0a0e0ef..c80417e 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py @@ -63,7 +63,7 @@ def startup_fresh(bot, trigger): pass timesince = humanized_time(time.time() - bot.memory["SpiceBot_Uptime"]) - bot.osd("Startup took" + timesince) + startupcomplete.append("Startup took" + timesince) # Announce to chan, then handle some closing stuff bot_logging(bot, 'SpiceBot_StartupMonologue', bot.nick + " startup complete") From 2c125c7879b75ec4df9fb90ecdb50a35c7b7c384 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 4 May 2019 17:20:21 -0400 Subject: [PATCH 12/15] clean up logic --- sopel_modules/SpiceBot_GifSearch/gifsearch.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot_GifSearch/gifsearch.py b/sopel_modules/SpiceBot_GifSearch/gifsearch.py index a12c189..28f9b69 100644 --- a/sopel_modules/SpiceBot_GifSearch/gifsearch.py +++ b/sopel_modules/SpiceBot_GifSearch/gifsearch.py @@ -85,9 +85,9 @@ def setup_thread(bot): valid_gif_api_dict[gif_api]["apikey"] = None bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'][gif_api] = valid_gif_api_dict[gif_api] - commandsquery_register_type(bot, "prefix_command") - for prefix_command in bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'].keys(): - commandsquery_register(bot, "prefix_command", prefix_command) + commandsquery_register_type(bot, "prefix") + for prefixcommand in bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'].keys(): + commandsquery_register(bot, "prefix", prefixcommand) set_bot_event(bot, "SpiceBot_GifSearch") From a27d2dfd2f7da75094da24c7adb3ee6c16d79dec Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 4 May 2019 17:21:17 -0400 Subject: [PATCH 13/15] Logging Channel --- sopel_modules/SpiceBot_Logs/Logs.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index 8086580..1ef2e43 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -40,10 +40,10 @@ def join_log_channel(bot, trigger): if channel not in bot.channels.keys() and bot.config.SpiceBot_Channels.operadmin: bot.write(('SAJOIN', bot.nick, channel)) - while True: - if len(bot.memory['SpiceBot_Logs_queue']): - bot.say(str(bot.memory['SpiceBot_Logs_queue'][0])) - del bot.memory['SpiceBot_Logs_queue'][0] + while True: + if len(bot.memory['SpiceBot_Logs_queue']): + bot.say(str(bot.memory['SpiceBot_Logs_queue'][0]), channel) + del bot.memory['SpiceBot_Logs_queue'][0] @sopel.module.nickname_commands('logs') From a91587c2bf02e77730b4bbb3abfeb3860a5a2d10 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 4 May 2019 17:21:48 -0400 Subject: [PATCH 14/15] update \n logic --- sopel_modules/SpiceBot_SBTools/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 7a30865..b664170 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -95,12 +95,12 @@ def bot_logging(bot, logtype, logentry): if 'SpiceBot_Logs_queue' not in bot.memory: bot.memory['SpiceBot_Logs_queue'] = [] - logmessage = "\n[" + logtype + "] " + logentry + "\n" + logmessage = "[" + logtype + "] " + logentry + "" if bot.config.SpiceBot_Logs.logging_channel: bot.memory['SpiceBot_Logs_queue'].append(logmessage) - stderr(logmessage) + stderr("\n" + logmessage + "\n") if 'SpiceBot_Logs' not in bot.memory: bot.memory['SpiceBot_Logs'] = {} From 45755efb07f6f097e73f61082f851e957539f6bc Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 4 May 2019 17:23:30 -0400 Subject: [PATCH 15/15] Add Space --- sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py index c80417e..ef27a1a 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py @@ -63,7 +63,7 @@ def startup_fresh(bot, trigger): pass timesince = humanized_time(time.time() - bot.memory["SpiceBot_Uptime"]) - startupcomplete.append("Startup took" + timesince) + startupcomplete.append("Startup took " + timesince) # Announce to chan, then handle some closing stuff bot_logging(bot, 'SpiceBot_StartupMonologue', bot.nick + " startup complete")