Logging Feature

This commit is contained in:
deathbybandaid 2019-05-04 16:25:03 -04:00
parent ea30f8c3dd
commit 9a48017060
18 changed files with 219 additions and 135 deletions

View File

@ -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()

View File

@ -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

View File

@ -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")

View File

@ -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

View File

@ -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}

View File

@ -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

View File

@ -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()

View File

@ -3,7 +3,6 @@
from __future__ import unicode_literals, absolute_import, division, print_function
import sopel.module
from sopel.tools import stderr
import spicemanip

View File

@ -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):

View File

@ -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")

View File

@ -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):

View File

@ -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'] = {}

View File

@ -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')

View File

@ -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

View File

@ -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')

View File

@ -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)

View File

@ -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')

View File

@ -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)