mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-12 06:29:54 -05:00
commit
9c964e287c
@ -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_SBTools 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()
|
||||
|
||||
|
||||
@ -3,8 +3,8 @@
|
||||
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
|
||||
from sopel_modules.SpiceBot_SBTools import bot_logging
|
||||
|
||||
import time
|
||||
|
||||
@ -22,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")
|
||||
|
||||
@ -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_SBTools 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")
|
||||
|
||||
@ -4,16 +4,18 @@ 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, ListAttribute
|
||||
|
||||
from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, startup_bot_event
|
||||
|
||||
import time
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -4,7 +4,6 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
|
||||
|
||||
import sopel
|
||||
import sopel.module
|
||||
from sopel.tools import stderr
|
||||
|
||||
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
|
||||
from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, check_bot_events, bot_logging
|
||||
|
||||
import spicemanip
|
||||
|
||||
@ -22,17 +21,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 +63,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 +134,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']['counts'][comtype] += 1
|
||||
|
||||
# default command to filename
|
||||
if "validcoms" not in dict_from_file.keys():
|
||||
@ -139,13 +146,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 +175,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 +249,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 +271,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 +297,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}
|
||||
|
||||
@ -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_SBTools 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
|
||||
|
||||
@ -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_SBTools 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()
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel.module
|
||||
from sopel.tools import stderr
|
||||
|
||||
import spicemanip
|
||||
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -3,14 +3,13 @@
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel.module
|
||||
from sopel.tools import stderr
|
||||
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_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
|
||||
|
||||
@ -39,7 +38,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 +52,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 +61,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 +74,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,14 +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]
|
||||
|
||||
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.")
|
||||
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")
|
||||
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -4,19 +4,46 @@ 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_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match, bot_logging
|
||||
|
||||
|
||||
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]), channel)
|
||||
del bot.memory['SpiceBot_Logs_queue'][0]
|
||||
|
||||
|
||||
@sopel.module.nickname_commands('logs')
|
||||
@ -42,16 +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' 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]
|
||||
|
||||
@ -4,10 +4,9 @@ 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_SBTools import service_manip, bot_logging
|
||||
|
||||
|
||||
@sopel.module.nickname_commands('restart')
|
||||
@ -16,7 +15,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')
|
||||
|
||||
@ -87,6 +87,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("\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
|
||||
"""
|
||||
@ -195,7 +221,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 +252,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 +279,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 +290,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 +305,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
|
||||
|
||||
@ -3,11 +3,11 @@
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
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_CommandsQuery.CommandsQuery import commandsquery_register
|
||||
from sopel_modules.SpiceBot_SBTools import humanized_time, bot_logging
|
||||
import time
|
||||
|
||||
|
||||
def configure(config):
|
||||
@ -35,7 +35,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 +44,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"])
|
||||
startupcomplete.append("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 +75,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')
|
||||
|
||||
@ -4,12 +4,13 @@ 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
|
||||
|
||||
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, bot_logging
|
||||
|
||||
|
||||
class SpiceBot_Update_MainSection(StaticSection):
|
||||
@ -24,7 +25,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 +49,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 +57,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)
|
||||
|
||||
@ -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_SBTools 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')
|
||||
|
||||
@ -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_SBTools 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)
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user