move defaults to the separate module
This commit is contained in:
parent
abe38388b6
commit
df3a990614
4 changed files with 6 additions and 13 deletions
3
pgbot
3
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())
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue