mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-10 21:50:59 -05:00
update setup procedures for configuration
This commit is contained in:
parent
3bb35eb46a
commit
d241ceb787
@ -23,9 +23,7 @@ class SpiceBot_AI_MainSection(StaticSection):
|
||||
class SpiceBot_AI():
|
||||
|
||||
def __init__(self):
|
||||
|
||||
botconfig.define_section("SpiceBot_AI", SpiceBot_AI_MainSection, validate=False)
|
||||
|
||||
self.setup_ai()
|
||||
self.braindirs = []
|
||||
self.dict = {
|
||||
"counts": 0,
|
||||
@ -52,6 +50,10 @@ class SpiceBot_AI():
|
||||
# Load bot values
|
||||
self.load_bot_values()
|
||||
|
||||
def setup_ai(self):
|
||||
botconfig.define_section("SpiceBot_AI", SpiceBot_AI_MainSection, validate=False)
|
||||
botconfig.aibrain = os.path.join(botconfig.homedir, botconfig.basename + '.aibrain.brn')
|
||||
|
||||
def load_saved_brain(self):
|
||||
if os.path.isfile(botconfig.config.aibrain):
|
||||
self.aiml_kernel.bootstrap(brainFile=botconfig.config.aibrain)
|
||||
|
||||
@ -10,7 +10,6 @@ import re
|
||||
import threading
|
||||
|
||||
from .Config import config as botconfig
|
||||
from .Logs import logs
|
||||
|
||||
|
||||
class SpiceBot_Channels_MainSection(StaticSection):
|
||||
@ -23,10 +22,7 @@ class SpiceBot_Channels_MainSection(StaticSection):
|
||||
class BotChannels():
|
||||
"""This Logs all channels known to the server"""
|
||||
def __init__(self):
|
||||
|
||||
# SpiceBot
|
||||
logs.log('SpiceBot_Channels', "Setting Up BotChannels class")
|
||||
botconfig.define_section("SpiceBot_Channels", SpiceBot_Channels_MainSection, validate=False)
|
||||
self.setup_channels()
|
||||
|
||||
self.lock = threading.Lock()
|
||||
self.channel_lock = False
|
||||
@ -35,6 +31,9 @@ class BotChannels():
|
||||
"InitialProcess": False
|
||||
}
|
||||
|
||||
def setup_channels(self):
|
||||
botconfig.define_section("SpiceBot_Channels", SpiceBot_Channels_MainSection, validate=False)
|
||||
|
||||
def channel_list_request(self, bot):
|
||||
bot.write(['LIST'])
|
||||
|
||||
|
||||
@ -5,7 +5,10 @@ This is the SpiceBot Commands system.
|
||||
|
||||
This Class stores commands in an easy to access manner
|
||||
"""
|
||||
|
||||
import sopel
|
||||
from sopel.config.types import StaticSection, ValidatedAttribute
|
||||
|
||||
import os
|
||||
import threading
|
||||
|
||||
@ -16,9 +19,14 @@ from .Config import config as botconfig
|
||||
from .Database import db as botdb
|
||||
|
||||
|
||||
class SpiceBot_Commands_MainSection(StaticSection):
|
||||
query_prefix = ValidatedAttribute('query_prefix', default="?")
|
||||
|
||||
|
||||
class BotCommands():
|
||||
"""This Logs all commands known to the bot"""
|
||||
def __init__(self):
|
||||
self.setup_commands()
|
||||
self.lock = threading.Lock()
|
||||
self.dict = {
|
||||
"counts": 0,
|
||||
@ -36,6 +44,11 @@ class BotCommands():
|
||||
for comtype in ['module', 'nickname', 'rule']:
|
||||
logs.log('SpiceBot_Commands', "Found " + str(len(self.dict['commands'][comtype].keys())) + " " + comtype + " commands.", True)
|
||||
|
||||
def setup_commands(self):
|
||||
botconfig.define_section("SpiceBot_Commands", SpiceBot_Commands_MainSection, validate=False)
|
||||
botconfig.core.query_list = str(botconfig.SpiceBot_Commands.query_prefix).replace("\\", '').split("|")
|
||||
botconfig.core.prefix_list.extend(botconfig.SpiceBot_Commands.query_prefix)
|
||||
|
||||
def nickrules(self):
|
||||
for command in self.dict['commands']['rule'].keys():
|
||||
if command.startswith("$nickname"):
|
||||
|
||||
@ -24,18 +24,7 @@ class BotConfig():
|
||||
opts = parser.parse_args(argv)
|
||||
self.config = get_configuration(opts)
|
||||
|
||||
self.config.core.prefix_list = str(self.config.core.prefix).replace("\\", '').split("|")
|
||||
self.config.core.prefix_list.append("?")
|
||||
|
||||
self.config.basename = os.path.basename(self.config.filename).rsplit('.', 1)[0]
|
||||
self.config.core.logs_stdio = os.path.join(self.config.core.logdir, 'stdio.log')
|
||||
# self.config.core.logs_stdio = os.path.os.path.join(self.config.core.logdir, self.config.basename + '.stdio.log')
|
||||
self.config.core.logs_exceptions = os.path.join(self.config.core.logdir, 'exceptions.log')
|
||||
# self.config.core.logs_exceptions = os.path.os.path.join(self.config.core.logdir, self.config.basename + '.exceptions.log')
|
||||
self.config.core.logs_raw = os.path.join(self.config.core.logdir, 'raw.log')
|
||||
# self.config.core.logs_raw = os.path.os.path.join(self.config.core.logdir, self.config.basename + '.raw.log')
|
||||
|
||||
self.config.aibrain = os.path.join(self.config.homedir, self.config.basename + '.aibrain.brn')
|
||||
self.setup_config()
|
||||
|
||||
# load as dict
|
||||
config = configparser.ConfigParser()
|
||||
@ -47,6 +36,10 @@ class BotConfig():
|
||||
if each_key.lower() not in self.dict[each_section.lower()].keys():
|
||||
self.dict[each_section.lower()][each_key.lower()] = each_val
|
||||
|
||||
def setup_config(self):
|
||||
self.config.core.basename = os.path.basename(self.config.filename).rsplit('.', 1)[0]
|
||||
self.config.core.prefix_list = str(self.config.core.prefix).replace("\\", '').split("|")
|
||||
|
||||
def define_section(self, name, cls_, validate=True):
|
||||
return self.config.define_section(name, cls_, validate)
|
||||
|
||||
|
||||
@ -6,9 +6,9 @@ This is the SpiceBot Logs system.
|
||||
This Class stores logs in an easy to access manner
|
||||
"""
|
||||
|
||||
import sopel
|
||||
import threading
|
||||
import os
|
||||
import sys
|
||||
import spicemanip
|
||||
|
||||
from .Config import config as botconfig
|
||||
@ -19,12 +19,24 @@ from .Config import config as botconfig
|
||||
class BotLogs():
|
||||
"""This Is a contained source of log information"""
|
||||
def __init__(self):
|
||||
self.setup_logs()
|
||||
self.lock = threading.Lock()
|
||||
self.dict = {
|
||||
"list": {"Sopel_systemd": [], "Sopel_stdio": []},
|
||||
"queue": []
|
||||
}
|
||||
|
||||
def setup_logs(self):
|
||||
botconfig.core.logs_stdio = os.path.join(botconfig.core.logdir, 'stdio.log')
|
||||
# botconfig.core.logs_stdio = os.path.os.path.join(botconfig.core.logdir, botconfig.basename + '.stdio.log')
|
||||
botconfig.core.logs_exceptions = os.path.join(botconfig.core.logdir, 'exceptions.log')
|
||||
# botconfig.core.logs_exceptions = os.path.os.path.join(botconfig.core.logdir, botconfig.basename + '.exceptions.log')
|
||||
botconfig.core.logs_raw = os.path.join(botconfig.core.logdir, 'raw.log')
|
||||
# botconfig.core.logs_raw = os.path.os.path.join(botconfig.core.logdir, botconfig.basename + '.raw.log')
|
||||
|
||||
def botstderr(self, logmessage):
|
||||
sys.stderr.write(logmessage)
|
||||
|
||||
def log(self, logtype, logentry, stdio=False):
|
||||
|
||||
self.lock.acquire()
|
||||
@ -36,7 +48,7 @@ class BotLogs():
|
||||
self.dict["queue"].append(logmessage)
|
||||
|
||||
if stdio:
|
||||
sopel.tools.stderr(logmessage)
|
||||
self.botstderr(logmessage)
|
||||
|
||||
if logtype not in self.dict["list"].keys():
|
||||
self.dict["list"][logtype] = []
|
||||
|
||||
@ -12,6 +12,7 @@ from .Logs import logs
|
||||
from .Events import events
|
||||
|
||||
from .Channels import SpiceBot_Channels_MainSection
|
||||
from .Commands import SpiceBot_Commands_MainSection
|
||||
from .Update import SpiceBot_Update_MainSection
|
||||
from .osd import SopelWrapperOSD, ToolsOSD, SopelOSD, SpiceBot_OSD
|
||||
from .Kick import SopelWrapperKICK, SopelKICK, SpiceBot_Kick
|
||||
@ -20,10 +21,88 @@ from .AI import SpiceBot_AI_MainSection
|
||||
|
||||
def setup(bot):
|
||||
|
||||
# basic config settings
|
||||
setup_config(bot)
|
||||
|
||||
# Logs
|
||||
setup_logs(bot)
|
||||
|
||||
# Commands
|
||||
setup_commands(bot)
|
||||
|
||||
# OSD
|
||||
setup_osd(bot)
|
||||
|
||||
# kick
|
||||
setup_kick(bot)
|
||||
|
||||
# update
|
||||
setup_update(bot)
|
||||
|
||||
# channels
|
||||
setup_channels(bot)
|
||||
|
||||
# AI
|
||||
setup_ai(bot)
|
||||
|
||||
# startupmonologue
|
||||
setup_startupmonologue(bot)
|
||||
|
||||
|
||||
def setup_config(bot):
|
||||
logs.log('SpiceBot_Config', "Setting Up Configuration")
|
||||
bot.config.core.basename = os.path.basename(bot.config.filename).rsplit('.', 1)[0]
|
||||
bot.config.core.prefix_list = str(bot.config.core.prefix).replace("\\", '').split("|")
|
||||
|
||||
|
||||
def setup_logs(bot):
|
||||
logs.log('SpiceBot_Logs', "Starting Setup Procedure")
|
||||
events.startup_add([events.BOT_LOGS])
|
||||
bot.config.core.logs_stdio = os.path.join(bot.config.core.logdir, 'stdio.log')
|
||||
# bot.config.core.logs_stdio = os.path.os.path.join(bot.config.core.logdir, bot.config.basename + '.stdio.log')
|
||||
bot.config.core.logs_exceptions = os.path.join(bot.config.core.logdir, 'exceptions.log')
|
||||
# bot.config.core.logs_exceptions = os.path.os.path.join(bot.config.core.logdir, bot.config.basename + '.exceptions.log')
|
||||
bot.config.core.logs_raw = os.path.join(bot.config.core.logdir, 'raw.log')
|
||||
# bot.config.core.logs_raw = os.path.os.path.join(bot.config.core.logdir, bot.config.basename + '.raw.log')
|
||||
events.trigger(bot, events.BOT_LOGS, "SpiceBot_Logs")
|
||||
|
||||
|
||||
def setup_commands(bot):
|
||||
logs.log('SpiceBot_Commands', "Setting Up Configuration")
|
||||
events.startup_add([events.BOT_COMMANDS])
|
||||
bot.config.define_section("SpiceBot_Commands", SpiceBot_Commands_MainSection, validate=False)
|
||||
bot.config.core.query_list = str(bot.config.SpiceBot_Commands.query_prefix).replace("\\", '').split("|")
|
||||
bot.config.core.prefix_list.extend(bot.config.SpiceBot_Commands.query_prefix)
|
||||
|
||||
|
||||
def setup_startupmonologue(bot):
|
||||
logs.log('SpiceBot_StartupMonologue', "Initial Setup processing")
|
||||
events.startup_add([
|
||||
events.BOT_STARTUPMONOLOGUE_CONNECTED,
|
||||
events.BOT_STARTUPMONOLOGUE_CHANNELS,
|
||||
events.BOT_STARTUPMONOLOGUE_COMMANDS
|
||||
])
|
||||
|
||||
|
||||
def setup_channels(bot):
|
||||
logs.log('SpiceBot_Channels', "Setting Up Configuration")
|
||||
events.startup_add([events.BOT_CHANNELS])
|
||||
bot.config.define_section("SpiceBot_Channels", SpiceBot_Channels_MainSection, validate=False)
|
||||
|
||||
|
||||
def setup_update(bot):
|
||||
logs.log('SpiceBot_Update', "Initial Setup processing")
|
||||
bot.config.define_section("SpiceBot_Update", SpiceBot_Update_MainSection, validate=False)
|
||||
botconfig.define_section("SpiceBot_Update", SpiceBot_Update_MainSection, validate=False)
|
||||
|
||||
|
||||
def setup_ai(bot):
|
||||
logs.log('SpiceBot_AI', "Setting Up Configuration")
|
||||
bot.config.define_section("SpiceBot_AI", SpiceBot_AI_MainSection, validate=False)
|
||||
bot.config.aibrain = os.path.join(bot.config.homedir, bot.config.basename + '.aibrain.brn')
|
||||
|
||||
|
||||
def setup_osd(bot):
|
||||
# Inject OSD
|
||||
logs.log('SpiceBot_OSD', "Implanting OSD function into bot")
|
||||
bot.osd = SopelOSD.osd
|
||||
@ -37,6 +116,8 @@ def setup(bot):
|
||||
bot.config.define_section("SpiceBot_OSD", SpiceBot_OSD, validate=False)
|
||||
botconfig.define_section("SpiceBot_OSD", SpiceBot_OSD, validate=False)
|
||||
|
||||
|
||||
def setup_kick(bot):
|
||||
# Inject KICK
|
||||
logs.log('SpiceBot_Kick', "Implanting Kick function into bot")
|
||||
bot.kick = SopelKICK.kick
|
||||
@ -46,38 +127,3 @@ def setup(bot):
|
||||
logs.log('SpiceBot_Kick', "Checking for config settings")
|
||||
bot.config.define_section("SpiceBot_Kick", SpiceBot_Kick, validate=False)
|
||||
botconfig.define_section("SpiceBot_Kick", SpiceBot_Kick, validate=False)
|
||||
|
||||
bot.config.core.prefix_list = str(bot.config.core.prefix).replace("\\", '').split("|")
|
||||
bot.config.core.prefix_list.append("?")
|
||||
|
||||
logs.log('SpiceBot_Config', "Setting Up Configuration")
|
||||
bot.config.core.basename = os.path.basename(bot.config.filename).rsplit('.', 1)[0]
|
||||
bot.config.core.logs_stdio = os.path.join(bot.config.core.logdir, 'stdio.log')
|
||||
# bot.config.core.logs_stdio = os.path.os.path.join(bot.config.core.logdir, bot.config.basename + '.stdio.log')
|
||||
bot.config.core.logs_exceptions = os.path.join(bot.config.core.logdir, 'exceptions.log')
|
||||
# bot.config.core.logs_exceptions = os.path.os.path.join(bot.config.core.logdir, bot.config.basename + '.exceptions.log')
|
||||
bot.config.core.logs_raw = os.path.join(bot.config.core.logdir, 'raw.log')
|
||||
# bot.config.core.logs_raw = os.path.os.path.join(bot.config.core.logdir, bot.config.basename + '.raw.log')
|
||||
|
||||
bot.config.aibrain = os.path.join(bot.config.homedir, bot.config.basename + '.aibrain.brn')
|
||||
|
||||
logs.log('SpiceBot_Channels', "Setting Up Configuration")
|
||||
events.startup_add([events.BOT_CHANNELS])
|
||||
bot.config.define_section("SpiceBot_Channels", SpiceBot_Channels_MainSection, validate=False)
|
||||
|
||||
logs.log('SpiceBot_Commands', "Setting Up Configuration")
|
||||
events.startup_add([events.BOT_COMMANDS])
|
||||
|
||||
logs.log('SpiceBot_Update', "Initial Setup processing")
|
||||
bot.config.define_section("SpiceBot_Update", SpiceBot_Update_MainSection, validate=False)
|
||||
botconfig.define_section("SpiceBot_Update", SpiceBot_Update_MainSection, validate=False)
|
||||
|
||||
logs.log('SpiceBot_StartupMonologue', "Initial Setup processing")
|
||||
events.startup_add([
|
||||
events.BOT_STARTUPMONOLOGUE_CONNECTED,
|
||||
events.BOT_STARTUPMONOLOGUE_CHANNELS,
|
||||
events.BOT_STARTUPMONOLOGUE_COMMANDS
|
||||
])
|
||||
|
||||
logs.log('SpiceBot_AI', "Setting Up Configuration")
|
||||
bot.config.define_section("SpiceBot_AI", SpiceBot_AI_MainSection, validate=False)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user