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