support config from files as well as env vars
This commit is contained in:
parent
8b3740ce0c
commit
7b9c639393
9
bot.py
9
bot.py
@ -12,12 +12,11 @@ import lib
|
||||
import heavynode
|
||||
|
||||
|
||||
DISCORD_TOKEN = os.environ['discord_token']
|
||||
DISCORD_TOKEN = lib.getconfig('DISCORD_TOKEN')
|
||||
DISCORD_SERVER_ID = 530446700058509323
|
||||
HEAVYNODE_TOKEN = os.environ['heavynode_token']
|
||||
# SESSION_COOKIE = os.environ['pterodactyl_session_cookie']
|
||||
COOKIE_NAME = 'remember_web_59ba36addc2b2f9401580f014c7f58ea4e30989d'
|
||||
COOKIE_VALUE = os.environ[COOKIE_NAME]
|
||||
HEAVYNODE_TOKEN = lib.getconfig('HEAVYNODE_TOKEN')
|
||||
COOKIE_NAME = lib.getconfig('HEAVYNODE_COOKIE_NAME')
|
||||
COOKIE_VALUE = lib.getconfig('HEAVYNODE_COOKIE_VALUE')
|
||||
|
||||
|
||||
logging.basicConfig()
|
||||
|
18
lib.py
18
lib.py
@ -1,8 +1,14 @@
|
||||
import inspect
|
||||
import os
|
||||
import pathlib
|
||||
|
||||
from discord.ext import commands
|
||||
|
||||
|
||||
class ConfigError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class MineBot(commands.Bot):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.cleanup = []
|
||||
@ -17,4 +23,14 @@ class MineBot(commands.Bot):
|
||||
# coroutines etc. return an awaitable object
|
||||
if inspect.isawaitable(r):
|
||||
await r
|
||||
await super().close()
|
||||
await super().close()
|
||||
|
||||
|
||||
def getconfig(key):
|
||||
if key in os.environ:
|
||||
return os.environ[key]
|
||||
elif f'{key}_FILE' in os.environ:
|
||||
p = os.environ[f'{key}_FILE']
|
||||
return pathlib.Path(p).read_text()
|
||||
else:
|
||||
raise ConfigError('Missing config:', key)
|
Loading…
x
Reference in New Issue
Block a user