diff --git a/config.dist.yml b/configs/pgbot.dist.yml similarity index 100% rename from config.dist.yml rename to configs/pgbot.dist.yml diff --git a/sched.dist.yml b/configs/sched.dist.yml similarity index 100% rename from sched.dist.yml rename to configs/sched.dist.yml diff --git a/tokens.dist.yml b/configs/tokens.dist.yml similarity index 100% rename from tokens.dist.yml rename to configs/tokens.dist.yml diff --git a/pgbot b/pgbot index bf9ab03..752932a 100755 --- a/pgbot +++ b/pgbot @@ -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()) diff --git a/pgbotlib/cron.py b/pgbotlib/cron.py index 1959293..529cfa0 100644 --- a/pgbotlib/cron.py +++ b/pgbotlib/cron.py @@ -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 diff --git a/pgbotlib/misc.py b/pgbotlib/misc.py index 47eda4a..836dfd3 100644 --- a/pgbotlib/misc.py +++ b/pgbotlib/misc.py @@ -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 diff --git a/pgbotlib/response.py b/pgbotlib/response.py index 9c02643..0a67689 100644 --- a/pgbotlib/response.py +++ b/pgbotlib/response.py @@ -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