diff --git a/sopel_modules/SpiceBot/StartupMonologue.py b/sopel_modules/SpiceBot/StartupMonologue.py new file mode 100644 index 0000000..14a0211 --- /dev/null +++ b/sopel_modules/SpiceBot/StartupMonologue.py @@ -0,0 +1,13 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +"""StartupMonologue class""" + + +class BotMonologue(): + + def __init__(self): + + self.dict = {} + + +startupmonologue = BotMonologue() diff --git a/sopel_modules/SpiceBot/__init__.py b/sopel_modules/SpiceBot/__init__.py index 797e4d2..b0de42a 100644 --- a/sopel_modules/SpiceBot/__init__.py +++ b/sopel_modules/SpiceBot/__init__.py @@ -18,6 +18,7 @@ from .Prerun import * from .Logs import * from .Commands import * from .Events import * +from .StartupMonologue import * from .Channels import * from .Database import * diff --git a/sopel_modules/SpiceBot_Core_Processing/StartupMonologue.py b/sopel_modules/SpiceBot_Core_Processing/StartupMonologue.py new file mode 100644 index 0000000..f3c08f9 --- /dev/null +++ b/sopel_modules/SpiceBot_Core_Processing/StartupMonologue.py @@ -0,0 +1,80 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +""" +This is the SpiceBot StartupMonologue system. +""" +import sopel + +import sopel_modules.SpiceBot as SpiceBot + +import time + + +@sopel.module.event(SpiceBot.events.BOT_CONNECTED) +@sopel.module.rule('.*') +def bot_startup_monologue_start(bot, trigger): + # Startup + SpiceBot.logs.log('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') + SpiceBot.events.trigger(bot, SpiceBot.events.BOT_STARTUPMONOLOGUE_CONNECTED, "SpiceBot_StartupMonologue") + + +@sopel.module.event(SpiceBot.events.BOT_CHANNELS) +@sopel.module.rule('.*') +def bot_startup_monologue_channels(bot, trigger): + botcount = len(bot.channels.keys()) + servercount = len(SpiceBot.channels.dict['list'].keys()) + displayval = "I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server." + SpiceBot.startupmonologue.dict["channels"] = displayval + SpiceBot.logs.log('SpiceBot_StartupMonologue', displayval) + SpiceBot.events.trigger(bot, SpiceBot.events.BOT_STARTUPMONOLOGUE_CHANNELS, "SpiceBot_StartupMonologue") + + +@sopel.module.event(SpiceBot.events.BOT_COMMANDS) +@sopel.module.rule('.*') +def bot_startup_monologue_commands(bot, trigger): + availablecomsnum, availablecomsfiles = 0, 0 + for commandstype in SpiceBot.commands.dict['commands'].keys(): + availablecomsnum += len(SpiceBot.commands.dict['commands'][commandstype].keys()) + availablecomsfiles += SpiceBot.commands.dict['counts'] + displayval = "There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files." + SpiceBot.startupmonologue.dict["commands"] = displayval + SpiceBot.logs.log('SpiceBot_StartupMonologue', displayval) + SpiceBot.events.trigger(bot, SpiceBot.events.BOT_STARTUPMONOLOGUE_COMMANDSQUERY, "SpiceBot_StartupMonologue") + + +@sopel.module.event(SpiceBot.events.BOT_LOADED) +@sopel.module.rule('.*') +def bot_startup_monologue_display(bot, trigger): + dispmsg = [" startup complete"] + for messagekey in SpiceBot.startupmonologue.dict.keys(): + dispmsg.append(SpiceBot.startupmonologue.dict[messagekey]) + if SpiceBot.events.dict["RPL_WELCOME_Count"] == 1: + timesince = SpiceBot.humanized_time(time.time() - bot.memory["SpiceBot_Uptime"]) + dispmsg.append("Startup took " + timesince) + # Announce to chan, then handle some closing stuff + SpiceBot.logs.log('SpiceBot_StartupMonologue', bot.nick + " startup complete") + bot.osd(dispmsg, bot.channels.keys(), 'ACTION') + SpiceBot.events.trigger(bot, SpiceBot.events.BOT_STARTUPMONOLOGUE, "SpiceBot_StartupMonologue") + SpiceBot.logs.log('SpiceBot_StartupMonologue', "Startup Monologue has been issued to all channels.", True) + + +@sopel.module.event(SpiceBot.events.BOT_STARTUPMONOLOGUE) +@sopel.module.rule('.*') +def bot_startup_monologue_errors(bot, trigger): + + debuglines = SpiceBot.logs.stdio_logs_fetch() + + searchphrasefound = [] + for line in debuglines: + if str(line).endswith("failed to load") and not str(line).startswith("0"): + searchphrasefound.append(line) + + if len(searchphrasefound): + for foundphase in searchphrasefound: + SpiceBot.logs.log('SpiceBot_Logs', str(foundphase)) + searchphrasefound.insert(0, "Notice to Bot Admins: ") + searchphrasefound.append("Run the debug command for more information.") + bot.osd(searchphrasefound, bot.channels.keys()) + else: + SpiceBot.logs.log('SpiceBot_Logs', "No issues found at bot startup!", True) diff --git a/sopel_modules/SpiceBot_Core_Processing/__init__.py b/sopel_modules/SpiceBot_Core_Processing/__init__.py index 2de57a0..b2a3644 100644 --- a/sopel_modules/SpiceBot_Core_Processing/__init__.py +++ b/sopel_modules/SpiceBot_Core_Processing/__init__.py @@ -10,6 +10,7 @@ from .Channels import * from .Events import * from .Modules import * from .osd import * +from .StartupMonologue import * __author__ = 'Sam Zick' diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py deleted file mode 100644 index 8edd940..0000000 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py +++ /dev/null @@ -1,14 +0,0 @@ -# coding=utf-8 - -from __future__ import unicode_literals, absolute_import, division, print_function - -import sopel.module - -import sopel_modules.SpiceBot as SpiceBot - - -def setup(bot): - SpiceBot.logs.log('SpiceBot_StartupMonologue', "Starting setup procedure") - - if 'SpiceBot_StartupMonologue' not in bot.memory: - bot.memory['SpiceBot_StartupMonologue'] = [] diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Channels.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Channels.py deleted file mode 100644 index 70eecdc..0000000 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Channels.py +++ /dev/null @@ -1,19 +0,0 @@ -# coding=utf-8 - -from __future__ import unicode_literals, absolute_import, division, print_function - -import sopel.module - -import sopel_modules.SpiceBot as SpiceBot - - -@sopel.module.event(SpiceBot.events.BOT_CHANNELS) -@sopel.module.rule('.*') -def bot_startup_monologue_channels(bot, trigger): - - botcount = len(bot.channels.keys()) - servercount = len(SpiceBot.channels.dict['list'].keys()) - bot.memory['SpiceBot_StartupMonologue'].append("I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server.") - SpiceBot.logs.log('SpiceBot_StartupMonologue', "I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server.") - - SpiceBot.events.trigger(bot, SpiceBot.events.BOT_STARTUPMONOLOGUE_CHANNELS, "SpiceBot_StartupMonologue") diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Commands.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Commands.py deleted file mode 100644 index 4f16db4..0000000 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Commands.py +++ /dev/null @@ -1,22 +0,0 @@ -# coding=utf-8 - -from __future__ import unicode_literals, absolute_import, division, print_function - -import sopel.module - -import sopel_modules.SpiceBot as SpiceBot - - -@sopel.module.event(SpiceBot.events.BOT_COMMANDS) -@sopel.module.rule('.*') -def bot_startup_monologue_commands(bot, trigger): - - availablecomsnum, availablecomsfiles = 0, 0 - for commandstype in SpiceBot.commands.dict['commands'].keys(): - availablecomsnum += len(SpiceBot.commands.dict['commands'][commandstype].keys()) - availablecomsfiles += SpiceBot.commands.dict['counts'] - - bot.memory['SpiceBot_StartupMonologue'].append("There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.") - SpiceBot.logs.log('SpiceBot_StartupMonologue', "There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.") - - SpiceBot.events.trigger(bot, SpiceBot.events.BOT_STARTUPMONOLOGUE_COMMANDSQUERY, "SpiceBot_StartupMonologue") diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Connected.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Connected.py deleted file mode 100644 index 0eaa358..0000000 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Connected.py +++ /dev/null @@ -1,18 +0,0 @@ -# coding=utf-8 - -from __future__ import unicode_literals, absolute_import, division, print_function - -import sopel.module - -import sopel_modules.SpiceBot as SpiceBot - - -@sopel.module.event(SpiceBot.events.BOT_CONNECTED) -@sopel.module.rule('.*') -def bot_startup_monologue_start(bot, trigger): - - # Startup - SpiceBot.logs.log('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') - - SpiceBot.events.trigger(bot, SpiceBot.events.BOT_STARTUPMONOLOGUE_CONNECTED, "SpiceBot_StartupMonologue") diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Errors.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Errors.py deleted file mode 100644 index 4cd49db..0000000 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Errors.py +++ /dev/null @@ -1,27 +0,0 @@ -# coding=utf-8 -from __future__ import unicode_literals, absolute_import, division, print_function - -import sopel.module - -import sopel_modules.SpiceBot as SpiceBot - - -@sopel.module.event(SpiceBot.events.BOT_STARTUPMONOLOGUE) -@sopel.module.rule('.*') -def bot_startup_monologue_start(bot, trigger): - - debuglines = SpiceBot.logs.stdio_logs_fetch() - - searchphrasefound = [] - for line in debuglines: - if str(line).endswith("failed to load") and not str(line).startswith("0"): - searchphrasefound.append(line) - - if len(searchphrasefound): - for foundphase in searchphrasefound: - SpiceBot.logs.log('SpiceBot_Logs', str(foundphase)) - searchphrasefound.insert(0, "Notice to Bot Admins: ") - searchphrasefound.append("Run the debug command for more information.") - bot.osd(searchphrasefound, bot.channels.keys()) - else: - SpiceBot.logs.log('SpiceBot_Logs', "No issues found at bot startup!", True) diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Loaded.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Loaded.py deleted file mode 100644 index c7bb713..0000000 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Loaded.py +++ /dev/null @@ -1,27 +0,0 @@ -# coding=utf-8 - -from __future__ import unicode_literals, absolute_import, division, print_function - -import sopel.module - -import sopel_modules.SpiceBot as SpiceBot - -import time - - -@sopel.module.event(SpiceBot.events.BOT_LOADED) -@sopel.module.rule('.*') -def bot_startup_monologue_display(bot, trigger): - - if SpiceBot.events.dict["RPL_WELCOME_Count"] == 1: - timesince = SpiceBot.humanized_time(time.time() - bot.memory["SpiceBot_Uptime"]) - SpiceBot.bot.memory['SpiceBot_StartupMonologue'].append("Startup took " + timesince) - - # Announce to chan, then handle some closing stuff - SpiceBot.logs.log('SpiceBot_StartupMonologue', bot.nick + " startup complete") - bot.memory['SpiceBot_StartupMonologue'].insert(0, " startup complete") - - bot.osd(bot.memory['SpiceBot_StartupMonologue'], bot.channels.keys(), 'ACTION') - - SpiceBot.events.trigger(bot, SpiceBot.events.BOT_STARTUPMONOLOGUE, "SpiceBot_StartupMonologue") - SpiceBot.logs.log('SpiceBot_StartupMonologue', "Startup Monologue has been issued to all channels.", True) diff --git a/sopel_modules/SpiceBot_StartupMonologue/__init__.py b/sopel_modules/SpiceBot_StartupMonologue/__init__.py deleted file mode 100644 index 8ab7cf1..0000000 --- a/sopel_modules/SpiceBot_StartupMonologue/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -# coding=utf8 -"""Sopel Startup Monologue - -Sopel Startup Monologue displays to all channels that the bot is online -""" -from __future__ import unicode_literals, absolute_import, division, print_function - -from .StartupMonologue import * -from .StartupMonologue_Display_Channels import * -from .StartupMonologue_Display_Commands import * -from .StartupMonologue_Display_Connected import * -from .StartupMonologue_Display_Loaded import * -from .StartupMonologue_Display_Errors import * - -__author__ = 'Sam Zick' -__email__ = 'sam@deathbybandaid.net' -__version__ = '0.1.1'