configs and defaults

This commit is contained in:
Von Random 2024-10-23 14:26:09 +03:00
parent f7d9afbd43
commit abe38388b6
7 changed files with 17 additions and 3 deletions

2
pgbot
View file

@ -15,7 +15,7 @@ import pgbotlib.response
def init(args: list) -> tuple:
conf_path = args[0] if args else 'config.yml'
conf_path = args[0] if args else pgbotlib.misc.Paths.CONFIG
try:
with open(conf_path, 'r', encoding='utf-8') as data:
config = yaml.safe_load(data.read())

View file

@ -5,6 +5,7 @@ import yaml
import aiocron
import telethon
import pgbotlib.response
import pgbotlib.misc
class Cron:
@ -12,7 +13,8 @@ class Cron:
config: dict,
client: telethon.TelegramClient,
responder: pgbotlib.response.Responder) -> None:
with open(config['schedule'], 'r', encoding='utf-8') as data:
schedule_conf = config.get('schedule', pgbot.misc.Paths.SCHEDULE)
with open(schedule_conf, 'r', encoding='utf-8') as data:
self.sched = yaml.safe_load(data.read())
self.responder = responder
self.client = client

View file

@ -1,7 +1,17 @@
import enum
import os
import telethon
import pgbotlib.dbstuff
class Paths(enum.Enum):
CONFDIR = '/etc/pgbot'
CONFIG = os.path.join(CONFDIR, 'pgbot.yml')
TOKENS = os.path.join(CONFDIR, 'tokens.yml')
SCHEDULE = os.path.join(CONFDIR, '/sched.yml')
class NameGenerator:
def __init__(self, config: dict, db: pgbotlib.dbstuff.DBConn) -> None:
self.db = db

View file

@ -30,7 +30,9 @@ class Responder:
self.enabled = True
self.apiregex = re.compile(r'^\{(\w+)\}(.+)?$')
self.namegen = pgbotlib.misc.NameGenerator(config, db_connection)
self.tokens = get_tokens(config['response_tokens'])
self.tokens = get_tokens(
config.get('response_tokens', pgbotlib.misc.Paths.TOKENS)
)
self.chats = config['chats']
self.api = pgbotlib.api.ApiWrapper(self.tokens, db_connection)
self.db_connection = db_connection