Merge pull request #16 from deathbybandaid/development

Development
This commit is contained in:
Deathbybandaid 2019-05-04 17:39:32 -04:00 committed by GitHub
commit 1ebdc9ab6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 235 additions and 154 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 from __future__ import unicode_literals, absolute_import, division, print_function
import sopel.module import sopel.module
from sopel.tools import stderr from sopel_modules.SpiceBot_SBTools import bot_logging
import threading import threading
@ -15,7 +15,7 @@ def configure(config):
def setup(bot): 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() threading.Thread(target=setup_thread, args=(bot,)).start()

View File

@ -3,8 +3,8 @@
from __future__ import unicode_literals, absolute_import, division, print_function from __future__ import unicode_literals, absolute_import, division, print_function
import sopel.module import sopel.module
from sopel.tools import stderr
from .BotEvents import check_bot_events, startup_bot_event, set_bot_event from .BotEvents import check_bot_events, startup_bot_event, set_bot_event
from sopel_modules.SpiceBot_SBTools import bot_logging
import time import time
@ -22,3 +22,4 @@ def bot_startup_connection(bot, trigger):
time.sleep(1) time.sleep(1)
set_bot_event(bot, "connected") set_bot_event(bot, "connected")
bot_logging(bot, 'Sopel_BotEvents', "Connected to IRC")

View File

@ -3,7 +3,7 @@
from __future__ import unicode_literals, absolute_import, division, print_function from __future__ import unicode_literals, absolute_import, division, print_function
import sopel.module import sopel.module
from sopel.tools import stderr from sopel_modules.SpiceBot_SBTools import bot_logging
from .BotEvents import set_bot_event, check_bot_startup from .BotEvents import set_bot_event, check_bot_startup
@ -16,4 +16,4 @@ def bot_startup_complete(bot, trigger):
pass pass
set_bot_event(bot, "startup_complete") 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,16 +4,18 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi
# sopel imports # sopel imports
import sopel.module import sopel.module
from sopel.tools import stderr
from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute
from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, startup_bot_event
import time import time
import spicemanip import spicemanip
from sopel_modules.SpiceBot_SBTools import ( from sopel_modules.SpiceBot_SBTools import (
sopel_triggerargs, inlist, topic_compile, channel_privs, 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
) )
@ -33,13 +35,19 @@ def configure(config):
def setup(bot): 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.config.define_section("SpiceBot_Channels", SpiceBot_Channels_MainSection, validate=False)
if 'SpiceBot_Channels' not in bot.memory:
bot.memory['SpiceBot_Channels'] = dict() bot.memory['SpiceBot_Channels'] = dict()
if 'channels' not in bot.memory['SpiceBot_Channels'].keys():
bot.memory['SpiceBot_Channels']['channels'] = dict() bot.memory['SpiceBot_Channels']['channels'] = dict()
if 'InitialProcess' not in bot.memory['SpiceBot_Channels'].keys():
bot.memory['SpiceBot_Channels']['InitialProcess'] = False bot.memory['SpiceBot_Channels']['InitialProcess'] = False
if 'ProcessLock' not in bot.memory['SpiceBot_Channels'].keys():
bot.memory['SpiceBot_Channels']['ProcessLock'] = False bot.memory['SpiceBot_Channels']['ProcessLock'] = False
@ -53,7 +61,7 @@ def trigger_channel_list_initial(bot, trigger):
bot.write(['LIST']) bot.write(['LIST'])
bot.memory['SpiceBot_Channels']['ProcessLock'] = True 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() starttime = time.time()
while not bot.memory['SpiceBot_Channels']['InitialProcess']: while not bot.memory['SpiceBot_Channels']['InitialProcess']:
@ -61,12 +69,13 @@ def trigger_channel_list_initial(bot, trigger):
if timesince < 60: if timesince < 60:
pass pass
else: 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 bot.memory['SpiceBot_Channels']['InitialProcess'] = True
channel_list_current(bot) channel_list_current(bot)
foundchannelcount = len(bot.memory['SpiceBot_Channels']['channels'].keys()) 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) join_all_channels(bot)
chanadmin_all_channels(bot) chanadmin_all_channels(bot)
@ -167,6 +176,7 @@ def nickname_comand_chanstats(bot, trigger):
bot.memory['SpiceBot_Channels']['ProcessLock'] = True bot.memory['SpiceBot_Channels']['ProcessLock'] = True
while bot.memory['SpiceBot_Channels']['ProcessLock']: while bot.memory['SpiceBot_Channels']['ProcessLock']:
pass pass
join_all_channels(bot)
foundchannelcount = len(bot.memory['SpiceBot_Channels']['channels'].keys()) foundchannelcount = len(bot.memory['SpiceBot_Channels']['channels'].keys())
bot.osd("[SpiceBot_Channels]", "Channel listing finished!", str(foundchannelcount) + " channel(s) found.") bot.osd("[SpiceBot_Channels]", "Channel listing finished!", str(foundchannelcount) + " channel(s) found.")
return return

View File

@ -4,7 +4,6 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
import sopel import sopel
import sopel.module import sopel.module
from sopel.tools import stderr
import os import os
from difflib import SequenceMatcher from difflib import SequenceMatcher
@ -12,7 +11,7 @@ from operator import itemgetter
import threading 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, bot_logging
import spicemanip import spicemanip
@ -22,17 +21,27 @@ def configure(config):
def setup(bot): 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() threading.Thread(target=setup_thread, args=(bot,)).start()
def setup_thread(bot): def setup_thread(bot):
if 'SpiceBot_CommandsQuery' not in bot.memory:
bot.memory['SpiceBot_CommandsQuery'] = dict() 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']: for comtype in ['module', 'nickname', 'rule']:
bot.memory['SpiceBot_CommandsQuery'][comtype + "_commands"] = dict() if comtype not in bot.memory['SpiceBot_CommandsQuery']['counts'].keys():
bot.memory['SpiceBot_CommandsQuery'][comtype + "_commands_count"] = 0 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 = [] filepathlisting = []
@ -54,7 +63,7 @@ def setup_thread(bot):
pypi_modules_dir = os.path.join(plugin_dir, pathname) pypi_modules_dir = os.path.join(plugin_dir, pathname)
filepathlisting.append(pypi_modules_dir) filepathlisting.append(pypi_modules_dir)
except Exception as e: 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 # Extra directories
filepathlist = [] filepathlist = []
@ -125,9 +134,7 @@ def setup_thread(bot):
comtype = atlinefound["comtype"] comtype = atlinefound["comtype"]
validcoms = atlinefound["validcoms"] validcoms = atlinefound["validcoms"]
comtypedict = str(comtype + "_commands") bot.memory['SpiceBot_CommandsQuery']['counts'][comtype] += 1
bot.memory['SpiceBot_CommandsQuery'][comtypedict + "_count"] += 1
# default command to filename # default command to filename
if "validcoms" not in dict_from_file.keys(): if "validcoms" not in dict_from_file.keys():
@ -139,13 +146,20 @@ def setup_thread(bot):
else: else:
comaliases = [] comaliases = []
bot.memory['SpiceBot_CommandsQuery'][comtypedict][maincom] = dict_from_file bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][maincom] = dict_from_file
for comalias in comaliases: for comalias in comaliases:
if comalias not in bot.memory['SpiceBot_CommandsQuery'][comtypedict].keys(): if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys():
bot.memory['SpiceBot_CommandsQuery'][comtypedict][comalias] = {"aliasfor": maincom} bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][comalias] = {"aliasfor": maincom}
for comtype in ['module_commands', 'nickname_commands', 'rule_commands']: for comtype in ['module', 'nickname', 'rule']:
stderr("[SpiceBot_CommandsQuery] Found " + str(len(bot.memory['SpiceBot_CommandsQuery'][comtype].keys())) + " " + comtype + " commands.") 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") set_bot_event(bot, "SpiceBot_CommandsQuery")
@ -161,11 +175,10 @@ def query_detection(bot, trigger):
return return
commands_list = dict() commands_list = dict()
for commandstype in bot.memory['SpiceBot_CommandsQuery'].keys(): for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
if not commandstype.endswith("_count"): for com in bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys():
for com in bot.memory['SpiceBot_CommandsQuery'][commandstype].keys():
if com not in commands_list.keys(): if com not in commands_list.keys():
commands_list[com] = bot.memory['SpiceBot_CommandsQuery'][commandstype][com] commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com]
triggerargsarray = spicemanip.main(trigger, 'create') triggerargsarray = spicemanip.main(trigger, 'create')
@ -236,10 +249,18 @@ def commandsquery_register_type(bot, command_type):
if 'SpiceBot_CommandsQuery' not in bot.memory: if 'SpiceBot_CommandsQuery' not in bot.memory:
bot.memory['SpiceBot_CommandsQuery'] = dict() 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(): if command_type not in bot.memory['SpiceBot_CommandsQuery'].keys():
bot.memory['SpiceBot_CommandsQuery'][command_type] = dict() if command_type not in bot.memory['SpiceBot_CommandsQuery']['counts'].keys():
bot.memory['SpiceBot_CommandsQuery'][command_type + "_count"] = 0 bot.memory['SpiceBot_CommandsQuery']['counts'][command_type] = 0
bot.memory['SpiceBot_CommandsQuery'][command_type + "_count"] += 1 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): def commandsquery_register(bot, command_type, validcoms, aliasfor=None):
@ -250,10 +271,18 @@ def commandsquery_register(bot, command_type, validcoms, aliasfor=None):
if 'SpiceBot_CommandsQuery' not in bot.memory: if 'SpiceBot_CommandsQuery' not in bot.memory:
bot.memory['SpiceBot_CommandsQuery'] = dict() 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(): if command_type not in bot.memory['SpiceBot_CommandsQuery'].keys():
bot.memory['SpiceBot_CommandsQuery'][command_type] = dict() if command_type not in bot.memory['SpiceBot_CommandsQuery']['counts'].keys():
bot.memory['SpiceBot_CommandsQuery'][command_type + "_count"] = 0 bot.memory['SpiceBot_CommandsQuery']['counts'][command_type] = 0
bot.memory['SpiceBot_CommandsQuery'][command_type + "_count"] += 1 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() dict_from_file = dict()
@ -268,10 +297,10 @@ def commandsquery_register(bot, command_type, validcoms, aliasfor=None):
comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list') comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list')
else: else:
comaliases = [] comaliases = []
bot.memory['SpiceBot_CommandsQuery'][command_type][maincom] = dict_from_file bot.memory['SpiceBot_CommandsQuery']['commands'][command_type][maincom] = dict_from_file
else: else:
comaliases = validcoms comaliases = validcoms
for comalias in comaliases: for comalias in comaliases:
if comalias not in bot.memory['SpiceBot_CommandsQuery'][command_type].keys(): if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands'][command_type].keys():
bot.memory['SpiceBot_CommandsQuery'][command_type][comalias] = {"aliasfor": aliasfor} 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 # sopel imports
import sopel.module import sopel.module
from sopel.tools import stderr, Identifier from sopel.tools import Identifier
from sopel_modules.SpiceBot_SBTools import bot_logging
from sopel.db import _deserialize, SopelDB from sopel.db import _deserialize, SopelDB
import json import json
@ -12,7 +13,7 @@ import json
def setup(bot): def setup(bot):
# Inject Database Functions # 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.reset_nick_value = SopelDBCache.reset_nick_value
SopelDB.adjust_nick_value = SopelDBCache.adjust_nick_value SopelDB.adjust_nick_value = SopelDBCache.adjust_nick_value
SopelDB.reset_channel_value = SopelDBCache.reset_channel_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 # sopel imports
import sopel.module import sopel.module
from sopel.tools import stderr from sopel_modules.SpiceBot_SBTools import bot_logging
def setup(bot): def setup(bot):
stderr("[SpiceBot_DatabaseCache] Setting up Database Cache.") bot_logging(bot, 'SpiceBot_DatabaseCache', "Setting up Database Cache")
if 'SpiceBot_DatabaseCache' not in bot.memory:
bot.memory['SpiceBot_DatabaseCache'] = dict() bot.memory['SpiceBot_DatabaseCache'] = dict()

View File

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

View File

@ -3,9 +3,6 @@
from __future__ import unicode_literals, absolute_import, division, print_function from __future__ import unicode_literals, absolute_import, division, print_function
import sopel.module import sopel.module
from sopel.tools import stderr
import spicemanip
def configure(config): def configure(config):

View File

@ -3,14 +3,13 @@
from __future__ import unicode_literals, absolute_import, division, print_function from __future__ import unicode_literals, absolute_import, division, print_function
import sopel.module import sopel.module
from sopel.tools import stderr
from sopel.config.types import StaticSection, ValidatedAttribute 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 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 import spicemanip
@ -39,7 +38,7 @@ class GifAPISection(StaticSection):
def configure(config): def configure(config):
moduledir = os.path.dirname(os.path.abspath(__file__)) moduledir = os.path.dirname(os.path.abspath(__file__))
api_dir = os.path.join(moduledir, 'gifapi') 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.define_section("SopelGifSearch", GifAPIMainSection, validate=False)
config.SopelGifSearch.configure_setting('extra', 'SpiceBot_GifSearch API Extra directory') config.SopelGifSearch.configure_setting('extra', 'SpiceBot_GifSearch API Extra directory')
@ -53,7 +52,7 @@ def configure(config):
def setup(bot): 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() threading.Thread(target=setup_thread, args=(bot,)).start()
@ -62,6 +61,7 @@ def setup_thread(bot):
startup_bot_event(bot, "SpiceBot_GifSearch") startup_bot_event(bot, "SpiceBot_GifSearch")
if 'SpiceBot_GifSearch' not in bot.memory:
bot.memory["SpiceBot_GifSearch"] = {"cache": {}, "badgiflinks": [], 'valid_gif_api_dict': {}} bot.memory["SpiceBot_GifSearch"] = {"cache": {}, "badgiflinks": [], 'valid_gif_api_dict': {}}
dir_to_scan = [] dir_to_scan = []
@ -74,7 +74,7 @@ def setup_thread(bot):
if bot.config.SopelGifSearch.extra: if bot.config.SopelGifSearch.extra:
dir_to_scan.append(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(): for gif_api in valid_gif_api_dict.keys():
bot.config.define_section(gif_api, GifAPISection, validate=False) bot.config.define_section(gif_api, GifAPISection, validate=False)
@ -85,14 +85,9 @@ def setup_thread(bot):
valid_gif_api_dict[gif_api]["apikey"] = None valid_gif_api_dict[gif_api]["apikey"] = None
bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'][gif_api] = valid_gif_api_dict[gif_api] bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'][gif_api] = valid_gif_api_dict[gif_api]
while not check_bot_events(bot, ["SpiceBot_CommandsQuery"]): commandsquery_register_type(bot, "prefix")
pass for prefixcommand in bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'].keys():
commandsquery_register(bot, "prefix", prefixcommand)
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") set_bot_event(bot, "SpiceBot_GifSearch")

View File

@ -3,11 +3,6 @@
from __future__ import unicode_literals, absolute_import, division, print_function from __future__ import unicode_literals, absolute_import, division, print_function
import sopel.module 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): def configure(config):

View File

@ -4,20 +4,47 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
import sopel.module import sopel.module
from sopel.tools import stderr from sopel.tools import stderr
from sopel.config.types import StaticSection, ValidatedAttribute
import spicemanip 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): 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): def setup(bot):
stderr("[SpiceBot_Logs] Starting Setup Procedure") 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'] = {} 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]), channel)
del bot.memory['SpiceBot_Logs_queue'][0]
@sopel.module.nickname_commands('logs') @sopel.module.nickname_commands('logs')
def bot_command_action(bot, trigger): def bot_command_action(bot, trigger):
@ -42,16 +69,3 @@ def bot_command_action(bot, trigger):
bot.osd("Is Examining " + str(logtype) + " log(s).") bot.osd("Is Examining " + str(logtype) + " log(s).")
for line in bot.memory['SpiceBot_Logs'][logtype]: for line in bot.memory['SpiceBot_Logs'][logtype]:
bot.osd(str(line), trigger.sender, 'action') bot.osd(str(line), trigger.sender, 'action')
def bot_logging(bot, logtype, logentry):
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]

View File

@ -4,10 +4,9 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi
# sopel imports # sopel imports
import sopel.module import sopel.module
from sopel.tools import stderr
from sopel.config.types import StaticSection, ValidatedAttribute from sopel.config.types import StaticSection, ValidatedAttribute
from sopel_modules.SpiceBot_SBTools import service_manip from sopel_modules.SpiceBot_SBTools import service_manip, bot_logging
@sopel.module.nickname_commands('restart') @sopel.module.nickname_commands('restart')
@ -16,7 +15,7 @@ def nickname_comand_chanstats(bot, trigger):
if not trigger.admin: if not trigger.admin:
bot.say("You are not authorized to perform this function.") 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()) 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

@ -87,6 +87,32 @@ def command_permissions_check(bot, trigger, privslist):
return True 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("\n" + logmessage + "\n")
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 Time
""" """
@ -195,7 +221,7 @@ def join_all_channels(bot):
for channel in bot.memory['SpiceBot_Channels']['channels'].keys(): 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: 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'])) 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'])) bot.write(('SAJOIN', bot.nick, bot.memory['SpiceBot_Channels']['channels'][channel]['name']))
@ -226,44 +252,20 @@ def channel_list_current(bot):
"""Environment Functions""" """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"]: if str(dowhat) not in ["start", "stop", "restart"]:
return return
try: 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)) os.system("sudo service " + str(servicename) + " " + str(dowhat))
except Exception as e: except Exception as e:
stderr(str(dowhat).title() + "ing " + str(servicename) + ".service Failed: " + str(e)) bot_logging(bot, log_from, 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)
"""Config Reading Functions""" """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): if not isinstance(directories, list):
directories = [directories] directories = [directories]
@ -277,8 +279,6 @@ def read_directory_json_to_dict(directories, configtypename="Config File", stder
filepath = os.path.join(directory, file) filepath = os.path.join(directory, file)
if os.path.isfile(filepath): if os.path.isfile(filepath):
filesprocess.append(filepath) filesprocess.append(filepath)
else:
stderr(stderrname + directory)
for filepath in filesprocess: for filepath in filesprocess:
@ -290,7 +290,8 @@ def read_directory_json_to_dict(directories, configtypename="Config File", stder
dict_from_file = eval(infread) dict_from_file = eval(infread)
except Exception as e: except Exception as e:
filereadgood = False 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() dict_from_file = dict()
# Close File # Close File
inf.close() inf.close()
@ -304,9 +305,11 @@ def read_directory_json_to_dict(directories, configtypename="Config File", stder
fileopenfail += 1 fileopenfail += 1
if filecount: if filecount:
stderr(stderrname + 'Registered %d %s files,' % (filecount, configtypename)) if bot:
stderr(stderrname + '%d %s files failed to load' % (fileopenfail, configtypename)) 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: 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 return configs_dict

View File

@ -3,11 +3,11 @@
from __future__ import unicode_literals, absolute_import, division, print_function from __future__ import unicode_literals, absolute_import, division, print_function
from sopel import module from sopel import module
from sopel.tools import stderr
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
from sopel_modules.SpiceBot_CommandsQuery.CommandsQuery import commandsquery_register from sopel_modules.SpiceBot_SBTools import humanized_time, bot_logging
import time
def configure(config): def configure(config):
@ -35,7 +35,7 @@ def bot_startup_monologue(bot, trigger):
def startup_fresh(bot, trigger): def startup_fresh(bot, trigger):
# Startup # 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') bot.osd(" is now starting. Please wait while I load my configuration.", bot.channels.keys(), 'ACTION')
startupcomplete = [bot.nick + " startup complete"] startupcomplete = [bot.nick + " startup complete"]
@ -44,22 +44,30 @@ def startup_fresh(bot, trigger):
pass pass
availablecomsnum, availablecomsfiles = 0, 0 availablecomsnum, availablecomsfiles = 0, 0
for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
for commandstype in bot.memory['SpiceBot_CommandsQuery'].keys(): availablecomsnum += len(bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys())
if commandstype.endswith("_count"): for commandstype in bot.memory['SpiceBot_CommandsQuery']['counts'].keys():
availablecomsfiles += bot.memory['SpiceBot_CommandsQuery'][commandstype] availablecomsfiles += bot.memory['SpiceBot_CommandsQuery']['counts'][commandstype]
else:
availablecomsnum += len(bot.memory['SpiceBot_CommandsQuery'][commandstype].keys())
startupcomplete.append("There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.") 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"]): while not check_bot_events(bot, ["startup_complete"]):
pass pass
timesince = humanized_time(time.time() - bot.memory["SpiceBot_Uptime"])
startupcomplete.append("Startup took " + timesince)
# Announce to chan, then handle some closing stuff # Announce to chan, then handle some closing stuff
bot_logging(bot, 'SpiceBot_StartupMonologue', bot.nick + " startup complete")
bot.osd(startupcomplete, bot.channels.keys()) bot.osd(startupcomplete, bot.channels.keys())
stderr("[SpiceBot_StartupMonologue] " + bot.nick + " startup complete")
set_bot_event(bot, "SpiceBot_StartupMonologue") set_bot_event(bot, "SpiceBot_StartupMonologue")
@ -67,5 +75,5 @@ def startup_fresh(bot, trigger):
def startup_reconnect(bot, trigger): def startup_reconnect(bot, trigger):
# Startup # 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') bot.osd(" has reconnected.", bot.channels.keys(), 'ACTION')

View File

@ -4,12 +4,13 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi
# sopel imports # sopel imports
import sopel.module import sopel.module
from sopel.tools import stderr
from sopel.config.types import StaticSection, ValidatedAttribute from sopel.config.types import StaticSection, ValidatedAttribute
import os
import spicemanip 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, bot_logging
class SpiceBot_Update_MainSection(StaticSection): class SpiceBot_Update_MainSection(StaticSection):
@ -24,7 +25,7 @@ def configure(config):
def setup(bot): 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) bot.config.define_section("SpiceBot_Update", SpiceBot_Update_MainSection, validate=False)
@ -48,7 +49,7 @@ def nickname_comand_chanstats(bot, trigger):
triggerargs = spicemanip.main(triggerargs, '2+', 'list') 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()) bot.osd("Received command from " + trigger.nick + " to update from Github and restart. Be Back Soon!", bot.channels.keys())
if commandused == 'nodeps': if commandused == 'nodeps':
@ -56,4 +57,28 @@ def nickname_comand_chanstats(bot, trigger):
if commandused == 'deps': if commandused == 'deps':
spicebot_update(bot, "True") 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 from __future__ import unicode_literals, absolute_import, division, print_function
import sopel.module import sopel.module
from sopel.tools import stderr
import spicemanip
import time import time
from sopel_modules.SpiceBot_SBTools import humanized_time from sopel_modules.SpiceBot_SBTools import humanized_time
from sopel_modules.SpiceBot_SBTools import bot_logging
def configure(config): def configure(config):
pass pass
def setup(bot): 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') @sopel.module.nickname_commands('uptime')

View File

@ -11,9 +11,11 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
import sopel.bot import sopel.bot
from sopel import tools, module 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.config.types import StaticSection, ValidatedAttribute
from sopel_modules.SpiceBot_SBTools import bot_logging
import time import time
from collections import abc from collections import abc
import sys import sys
@ -33,7 +35,7 @@ def configure(config):
def setup(bot): def setup(bot):
# Inject OSD # 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.osd = SopelOSD.osd
bot.SopelWrapper.osd = SopelOSD.SopelWrapper.osd bot.SopelWrapper.osd = SopelOSD.SopelWrapper.osd
tools.get_available_message_bytes = ToolsOSD.get_available_message_bytes 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 tools.get_message_recipientgroups = ToolsOSD.get_message_recipientgroups
# overwrite default bot messaging # 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.say = SopelOSD.SopelWrapper.say
bot.SopelWrapper.action = SopelOSD.SopelWrapper.action bot.SopelWrapper.action = SopelOSD.SopelWrapper.action
bot.SopelWrapper.notice = SopelOSD.SopelWrapper.notice bot.SopelWrapper.notice = SopelOSD.SopelWrapper.notice
bot.SopelWrapper.reply = SopelOSD.SopelWrapper.reply bot.SopelWrapper.reply = SopelOSD.SopelWrapper.reply
# verify config settings for server # 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) bot.config.define_section("MAXTARGCONFIG", MAXTARGCONFIG, validate=False)