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 telethon
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
import pgbotlib.defaults
|
||||||
import pgbotlib.dbstuff
|
import pgbotlib.dbstuff
|
||||||
import pgbotlib.commands
|
import pgbotlib.commands
|
||||||
import pgbotlib.cron
|
import pgbotlib.cron
|
||||||
|
@ -15,7 +16,7 @@ import pgbotlib.response
|
||||||
|
|
||||||
|
|
||||||
def init(args: list) -> tuple:
|
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:
|
try:
|
||||||
with open(conf_path, 'r', encoding='utf-8') as data:
|
with open(conf_path, 'r', encoding='utf-8') as data:
|
||||||
config = yaml.safe_load(data.read())
|
config = yaml.safe_load(data.read())
|
||||||
|
|
|
@ -4,6 +4,7 @@ import random
|
||||||
import yaml
|
import yaml
|
||||||
import aiocron
|
import aiocron
|
||||||
import telethon
|
import telethon
|
||||||
|
import pgbotlib.defaults
|
||||||
import pgbotlib.response
|
import pgbotlib.response
|
||||||
import pgbotlib.misc
|
import pgbotlib.misc
|
||||||
|
|
||||||
|
@ -13,7 +14,7 @@ class Cron:
|
||||||
config: dict,
|
config: dict,
|
||||||
client: telethon.TelegramClient,
|
client: telethon.TelegramClient,
|
||||||
responder: pgbotlib.response.Responder) -> None:
|
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:
|
with open(schedule_conf, 'r', encoding='utf-8') as data:
|
||||||
self.sched = yaml.safe_load(data.read())
|
self.sched = yaml.safe_load(data.read())
|
||||||
self.responder = responder
|
self.responder = responder
|
||||||
|
|
|
@ -1,17 +1,7 @@
|
||||||
import enum
|
|
||||||
import os
|
|
||||||
|
|
||||||
import telethon
|
import telethon
|
||||||
import pgbotlib.dbstuff
|
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:
|
class NameGenerator:
|
||||||
def __init__(self, config: dict, db: pgbotlib.dbstuff.DBConn) -> None:
|
def __init__(self, config: dict, db: pgbotlib.dbstuff.DBConn) -> None:
|
||||||
self.db = db
|
self.db = db
|
||||||
|
|
|
@ -4,6 +4,7 @@ import telethon
|
||||||
import yaml
|
import yaml
|
||||||
import pgbotlib.api
|
import pgbotlib.api
|
||||||
import pgbotlib.dbstuff
|
import pgbotlib.dbstuff
|
||||||
|
import pgbotlib.defaults
|
||||||
import pgbotlib.misc
|
import pgbotlib.misc
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,7 +32,7 @@ class Responder:
|
||||||
self.apiregex = re.compile(r'^\{(\w+)\}(.+)?$')
|
self.apiregex = re.compile(r'^\{(\w+)\}(.+)?$')
|
||||||
self.namegen = pgbotlib.misc.NameGenerator(config, db_connection)
|
self.namegen = pgbotlib.misc.NameGenerator(config, db_connection)
|
||||||
self.tokens = get_tokens(
|
self.tokens = get_tokens(
|
||||||
config.get('response_tokens', pgbotlib.misc.Paths.TOKENS)
|
config.get('response_tokens', pgbotlib.defaults.TOKENS)
|
||||||
)
|
)
|
||||||
self.chats = config['chats']
|
self.chats = config['chats']
|
||||||
self.api = pgbotlib.api.ApiWrapper(self.tokens, db_connection)
|
self.api = pgbotlib.api.ApiWrapper(self.tokens, db_connection)
|
||||||
|
|
Loading…
Reference in a new issue