get rid of defaults, hardcode stuff instead, also use os.chdir into config dir
This commit is contained in:
parent
acc390ef11
commit
9eeabd8ae9
4 changed files with 7 additions and 17 deletions
7
pgbot
7
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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
''' module defaults '''
|
||||
|
||||
CONFDIR = '/etc/pgbot'
|
||||
CONFIG = CONFDIR + '/pgbot.yml'
|
||||
TOKENS = CONFDIR + '/tokens.yml'
|
||||
SCHEDULE = CONFDIR + '/sched.yml'
|
||||
TZ = 'UTC'
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue