aboutsummaryrefslogtreecommitdiff
path: root/code/global_variables.py
blob: 1bb4a7ac97323ae2195ba1f5821887f0cb930973 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import configparser
import logging
from colorlog import ColoredFormatter
import discord


log_level = logging.DEBUG
log_format = (
    "  %(log_color)s%(levelname)-8s%(reset)s | %(log_color)s%(message)s%(reset)s"
)

logging.root.setLevel(log_level)
formatter = ColoredFormatter(log_format)

stream = logging.StreamHandler()
stream.setLevel(log_level)
stream.setFormatter(formatter)

LOG = logging.getLogger("pythonConfig")
LOG.setLevel(log_level)
LOG.addHandler(stream)

try:
    with open("config.ini", "r") as f:
        file_contents = f.read()
except FileNotFoundError:
    config = configparser.ConfigParser()
    config["BOT_INFO"] = {
        "TOKEN": "",
        "BOT_COLOR": "",
    }

    config["LAVALINK"] = {
        "HOST": "",
        "PORT": "",
        "PASSWORD": ""
    }

    with open("config.ini", "w") as configfile:
        config.write(configfile)

    LOG.error(
        "Configuration file `config.ini` has been generated. Please fill out all of the necessary information. Refer to the docs for information on what a specific configuration option is."
    )
    exit()


config = configparser.ConfigParser()
config.read_string(file_contents)

BOT_TOKEN = config["BOT_INFO"]["TOKEN"]
BOT_COLOR = discord.Color(int((config["BOT_INFO"]["BOT_COLOR"]).replace("#", ""), 16))

LAVALINK_HOST = config["LAVALINK"]["HOST"]
LAVALINK_PORT = config["LAVALINK"]["PORT"]
LAVALINK_PASSWORD = config["LAVALINK"]["PASSWORD"]