From 9eeabd8ae9522acc0b17efe06b1810edb4e784ec Mon Sep 17 00:00:00 2001 From: Von Random Date: Sun, 10 Nov 2024 00:37:41 +0200 Subject: [PATCH] get rid of defaults, hardcode stuff instead, also use os.chdir into config dir --- pgbot | 7 ++++--- pgbotlib/cron.py | 5 ++--- pgbotlib/defaults.py | 7 ------- pgbotlib/response.py | 5 +---- 4 files changed, 7 insertions(+), 17 deletions(-) delete mode 100644 pgbotlib/defaults.py diff --git a/pgbot b/pgbot index 7cb36ca..e1052d9 100755 --- a/pgbot +++ b/pgbot @@ -1,12 +1,12 @@ #!/usr/bin/env python3 import asyncio +import os import sys import telethon import yaml -import pgbotlib.defaults import pgbotlib.dbstuff import pgbotlib.commands import pgbotlib.cron @@ -15,9 +15,10 @@ import pgbotlib.response def init(args: list) -> tuple: - conf_path = args[0] if args else pgbotlib.defaults.CONFIG + conf_dir = args[0] if args else '/etc/pgbot' + os.chdir(conf_dir) try: - with open(conf_path, 'r', encoding='utf-8') as data: + with open('pgbot.yml', 'r', encoding='utf-8') as data: config = yaml.safe_load(data.read()) except FileNotFoundError as err: sys.exit(err) diff --git a/pgbotlib/cron.py b/pgbotlib/cron.py index de84104..3d80275 100644 --- a/pgbotlib/cron.py +++ b/pgbotlib/cron.py @@ -4,7 +4,6 @@ import sys import aiocron import telethon -import pgbotlib.defaults import pgbotlib.response import pgbotlib.misc import pytz @@ -16,8 +15,8 @@ class Cron: config: dict, client: telethon.TelegramClient, responder: pgbotlib.response.Responder) -> None: - schedule_conf = config.get('schedule', pgbotlib.defaults.SCHEDULE) - local_tz = config.get('timezone', pgbotlib.defaults.TZ) + schedule_conf = config.get('schedule', 'sched.yml') + local_tz = config.get('timezone', 'UTC') try: self.tz = pytz.timezone(local_tz) except pytz.exceptions.UnknownTimeZoneError as e: diff --git a/pgbotlib/defaults.py b/pgbotlib/defaults.py deleted file mode 100644 index 51e171c..0000000 --- a/pgbotlib/defaults.py +++ /dev/null @@ -1,7 +0,0 @@ -''' module defaults ''' - -CONFDIR = '/etc/pgbot' -CONFIG = CONFDIR + '/pgbot.yml' -TOKENS = CONFDIR + '/tokens.yml' -SCHEDULE = CONFDIR + '/sched.yml' -TZ = 'UTC' diff --git a/pgbotlib/response.py b/pgbotlib/response.py index 8a4e9d4..9e25b23 100644 --- a/pgbotlib/response.py +++ b/pgbotlib/response.py @@ -4,7 +4,6 @@ import telethon import yaml import pgbotlib.api import pgbotlib.dbstuff -import pgbotlib.defaults import pgbotlib.misc @@ -31,9 +30,7 @@ class Responder: self.enabled = True self.apiregex = re.compile(r'^\{(\w+)\}(.+)?$') self.namegen = pgbotlib.misc.NameGenerator(config, db_connection) - self.tokens = get_tokens( - config.get('response_tokens', pgbotlib.defaults.TOKENS) - ) + self.tokens = get_tokens(config.get('response_tokens', 'tokens.yml')) self.chats = config['chats'] self.api = pgbotlib.api.ApiWrapper(self.tokens, db_connection) self.db_connection = db_connection