This commit is contained in:
deathbybandaid 2022-02-09 15:38:51 -05:00
parent fd73177035
commit 8d5ac44fee
5 changed files with 60 additions and 29 deletions

View File

@ -6,19 +6,17 @@ from .logger import Logger
class SpiceBotCore_OBJ(): class SpiceBotCore_OBJ():
def __init__(self): def __init__(self, script_dir):
self.script_dir = None
self.increment = 1
self.bot = None
self.config = None # Set directory for the plugin
self.versions = None
self.logger = None
def setup(self, script_dir, bot):
self.script_dir = script_dir self.script_dir = script_dir
self.bot = bot
self.config = Config(script_dir, bot) # Allow SpiceBot to interact with Sopel Logger
self.logger = Logger(self.config) self.logger = Logger()
self.versions = Versions(self.config, self.logger)
# Parse Version Information for the ENV
self.versions = Versions(self.logger)
# def setup(self, script_dir, bot):
# self.bot = bot
# self.config = Config(script_dir, bot)

View File

@ -1,3 +1,10 @@
# coding=utf8
from __future__ import unicode_literals, absolute_import, division, print_function
import sys
import os
from sopel.cli.run import build_parser, get_configuration
class Config(): class Config():
@ -10,16 +17,44 @@ class Config():
self.core_setup() self.core_setup()
def core_setup(self): self.dict = {}
self.internal["paths"] = { self.internal["paths"] = {
"script_dir": self.script_dir "script_dir": self.script_dir
} }
def __getattr__(self, name): # opts input
""" self.opts = self.get_opts()
Quick and dirty shortcuts. Will only get called for undefined attributes.
"""
if hasattr(self.bot.config, name): # Load config
return eval("self.bot.config.%s" % name) self.config = get_configuration(self.opts)
self.setup_config()
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)
def get_opts(self):
parser = build_parser()
if not len(sys.argv[1:]):
argv = ['legacy']
else:
argv = sys.argv[1:]
return parser.parse_args(argv)
def __getattr__(self, name):
''' will only get called for undefined attributes '''
"""We will try to find a core value, or return None"""
if hasattr(self.config.core, name):
return eval("self.config.core." + name)
elif hasattr(self.config, name):
return eval("self.config." + name)
else:
return None

View File

@ -3,8 +3,7 @@ from sopel import tools
class Logger(): class Logger():
def __init__(self, config): def __init__(self):
self.config = config
self.logger = tools.get_logger('SpiceBot') self.logger = tools.get_logger('SpiceBot')
def __getattr__(self, name): def __getattr__(self, name):

View File

@ -8,8 +8,7 @@ import re
class Versions(): class Versions():
def __init__(self, config, logger): def __init__(self, logger):
self.config = config
self.logger = logger self.logger = logger
self.dict = {} self.dict = {}
@ -42,8 +41,7 @@ class Versions():
Register core version items. Register core version items.
""" """
script_dir = self.config.internal["paths"]["script_dir"] version_file = pathlib.Path(self.script_dir).joinpath("version.json")
version_file = pathlib.Path(script_dir).joinpath("version.json")
with open(version_file, 'r') as jsonversion: with open(version_file, 'r') as jsonversion:
versions = json.load(jsonversion) versions = json.load(jsonversion)

View File

@ -10,13 +10,14 @@ import pathlib
from sopel import plugin from sopel import plugin
from .SpiceBotCore import SpiceBotCore_OBJ from .SpiceBotCore import SpiceBotCore_OBJ
sbcore = SpiceBotCore_OBJ()
SCRIPT_DIR = pathlib.Path(os.path.dirname(os.path.abspath(__file__))) SCRIPT_DIR = pathlib.Path(os.path.dirname(os.path.abspath(__file__)))
sbcore = SpiceBotCore_OBJ(SCRIPT_DIR)
def setup(bot):
sbcore.setup(SCRIPT_DIR, bot) # def setup(bot):
# sbcore.setup(bot)
@plugin.nickname_command('test') @plugin.nickname_command('test')