config building and ext loading
This commit is contained in:
parent
d9aa1df130
commit
113ed159a0
28
main.py
28
main.py
|
@ -1,21 +1,23 @@
|
||||||
from configparser import ConfigParser
|
|
||||||
import logging
|
import logging
|
||||||
from discord import Client
|
|
||||||
import sys
|
import sys
|
||||||
|
from os import listdir
|
||||||
|
|
||||||
# read config at default location
|
from discord.ext.commands import Bot
|
||||||
# ./config.ini
|
from src.utils.config import build_config
|
||||||
config = ConfigParser()
|
|
||||||
try:
|
|
||||||
config.read_file(open("config.ini"))
|
|
||||||
except FileNotFoundError:
|
|
||||||
logging.critical("Unable to locate the configuration file.")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# spawn discord client instance
|
# read config at configured location \\ default to 'config.ini'
|
||||||
|
config = build_config()
|
||||||
|
|
||||||
|
# spawn discord bot instance
|
||||||
# init token from config
|
# init token from config
|
||||||
bot = Client()
|
bot = Bot(command_prefix="~ak ")
|
||||||
token = config['AUTH']['token']
|
token = config['AUTH']['token']
|
||||||
|
|
||||||
|
# load extensions
|
||||||
|
for file in os.listdir("src/cogs"):
|
||||||
|
if file.endswith(".py"):
|
||||||
|
name = file[:-3]
|
||||||
|
bot.load_extension(f"src.cogs.{name}")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
bot.run()
|
bot.run(token)
|
|
@ -0,0 +1 @@
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
import os
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from configparser import ConfigParser
|
||||||
|
|
||||||
|
|
||||||
|
def build_config():
|
||||||
|
config_path = os.getenv("AKWAH_CONFIG_PATH")
|
||||||
|
if config_path == None:
|
||||||
|
config_path = "config.ini"
|
||||||
|
|
||||||
|
try:
|
||||||
|
config_file = open(config_path)
|
||||||
|
except FileNotFoundError:
|
||||||
|
logging.critical("Unable to locate the configuration file.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
config = ConfigParser()
|
||||||
|
config.read_file(config_file)
|
||||||
|
logging.info("Finished building configuration.")
|
||||||
|
|
||||||
|
return config
|
||||||
|
|
Loading…
Reference in New Issue