From df3a990614539ce6d3f300b97c037c4d052ce9d4 Mon Sep 17 00:00:00 2001 From: Von Random Date: Wed, 23 Oct 2024 14:35:36 +0300 Subject: [PATCH] move defaults to the separate module --- pgbot | 3 ++- pgbotlib/cron.py | 3 ++- pgbotlib/misc.py | 10 ---------- pgbotlib/response.py | 3 ++- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/pgbot b/pgbot index 752932a..f206df0 100755 --- a/pgbot +++ b/pgbot @@ -7,6 +7,7 @@ import threading import telethon import yaml +import pgbotlib.defaults import pgbotlib.dbstuff import pgbotlib.commands import pgbotlib.cron @@ -15,7 +16,7 @@ import pgbotlib.response def init(args: list) -> tuple: - conf_path = args[0] if args else pgbotlib.misc.Paths.CONFIG + conf_path = args[0] if args else pgbotlib.defaults.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 529cfa0..45482ba 100644 --- a/pgbotlib/cron.py +++ b/pgbotlib/cron.py @@ -4,6 +4,7 @@ import random import yaml import aiocron import telethon +import pgbotlib.defaults import pgbotlib.response import pgbotlib.misc @@ -13,7 +14,7 @@ class Cron: config: dict, client: telethon.TelegramClient, responder: pgbotlib.response.Responder) -> None: - schedule_conf = config.get('schedule', pgbot.misc.Paths.SCHEDULE) + schedule_conf = config.get('schedule', pgbotlib.defaults.SCHEDULE) with open(schedule_conf, 'r', encoding='utf-8') as data: self.sched = yaml.safe_load(data.read()) self.responder = responder diff --git a/pgbotlib/misc.py b/pgbotlib/misc.py index 836dfd3..47eda4a 100644 --- a/pgbotlib/misc.py +++ b/pgbotlib/misc.py @@ -1,17 +1,7 @@ -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 0a67689..8a4e9d4 100644 --- a/pgbotlib/response.py +++ b/pgbotlib/response.py @@ -4,6 +4,7 @@ import telethon import yaml import pgbotlib.api import pgbotlib.dbstuff +import pgbotlib.defaults import pgbotlib.misc @@ -31,7 +32,7 @@ class Responder: self.apiregex = re.compile(r'^\{(\w+)\}(.+)?$') self.namegen = pgbotlib.misc.NameGenerator(config, db_connection) self.tokens = get_tokens( - config.get('response_tokens', pgbotlib.misc.Paths.TOKENS) + config.get('response_tokens', pgbotlib.defaults.TOKENS) ) self.chats = config['chats'] self.api = pgbotlib.api.ApiWrapper(self.tokens, db_connection)