New logging
This commit is contained in:
34
main.py
34
main.py
@@ -1,8 +1,9 @@
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
import bot
|
||||
import argparse
|
||||
from BotResources import check_if_config_exists, write_config_file, read_config_file
|
||||
import BotResources
|
||||
|
||||
# Jorn
|
||||
#token = 'OTE1MDY0OTk2OTk0NjMzNzI5.YaWKsA.Y9yaCGg_VXRL_qQVbs05vo7gSAc'
|
||||
@@ -15,26 +16,28 @@ from BotResources import check_if_config_exists, write_config_file, read_config_
|
||||
|
||||
#name = "VoiceMeeter Output"
|
||||
|
||||
LOGGER = logging.getLogger("Discord_Radio_Bot.Main")
|
||||
|
||||
|
||||
class BotDeviceNotFound(Exception):
|
||||
def __init__(self, device):
|
||||
print(f"Unable to find the device: {device}")
|
||||
LOGGER.debug(f"Unable to find the device: {device}")
|
||||
try:
|
||||
os.remove('./config.ini')
|
||||
except OSError:
|
||||
print("Config file not found, restarting.")
|
||||
LOGGER.warning("Config file not found, restarting.")
|
||||
#os.execv(__file__, sys.argv)
|
||||
|
||||
|
||||
def main(**passed_config):
|
||||
# Don't create a config if the user passed parameters
|
||||
if len(passed_config.keys()) == 0:
|
||||
print('Checking config file...')
|
||||
if not check_if_config_exists():
|
||||
print("No config file exists, please enter this information now")
|
||||
write_config_file(init=True)
|
||||
LOGGER.info('Checking config file...')
|
||||
if not BotResources.check_if_config_exists():
|
||||
LOGGER.warning("No config file exists, please enter this information now")
|
||||
BotResources.write_config_file(init=True)
|
||||
|
||||
config = read_config_file()
|
||||
config = BotResources.read_config_file()
|
||||
|
||||
# Overwrite config options if they were passed
|
||||
if len(passed_config.keys()) == 0:
|
||||
@@ -43,13 +46,13 @@ def main(**passed_config):
|
||||
if sub in passed_config and passed_config[sub]:
|
||||
config[sub] = passed_config[sub]
|
||||
|
||||
print('Starting Bot...')
|
||||
LOGGER.info('Starting Bot...')
|
||||
|
||||
discord_bot_client = bot.Bot(Token=config['Bot Token'], Device_ID=config['Device ID'],
|
||||
Device_Name=config['Device Name'], Mention_Group=config['Mention Group'],
|
||||
Channel_ID=config['Channel ID'], Handler=config['Handler'])
|
||||
|
||||
print(f"Verifying audio device:\t{config['Device Name']}")
|
||||
LOGGER.debug(f"Verifying audio device:\t{config['Device Name']}")
|
||||
|
||||
if not discord_bot_client.check_device(_override=bool("Device ID" in passed_config.keys())):
|
||||
raise BotDeviceNotFound(config['Device Name'])
|
||||
@@ -112,20 +115,21 @@ def cmd_arguments():
|
||||
|
||||
if __name__ == '__main__':
|
||||
cmd_args = cmd_arguments()
|
||||
BotResources.init_global_logger()
|
||||
|
||||
if not all(cmd_args.values()):
|
||||
print("Passed arguments:")
|
||||
LOGGER.debug("Passed arguments:")
|
||||
for arg in cmd_args:
|
||||
if cmd_args[arg]:
|
||||
print(f"\t{arg}:\t{cmd_args[arg]}")
|
||||
LOGGER.debug(f"\t{arg}:\t{cmd_args[arg]}")
|
||||
|
||||
try:
|
||||
print('Starting...')
|
||||
LOGGER.info('Starting...')
|
||||
while True:
|
||||
try:
|
||||
main(**cmd_args)
|
||||
except BotDeviceNotFound:
|
||||
print("Restarting...")
|
||||
LOGGER.info("Restarting...")
|
||||
time.sleep(2)
|
||||
except KeyboardInterrupt:
|
||||
print("Exiting...")
|
||||
LOGGER.error("Exiting...")
|
||||
|
||||
Reference in New Issue
Block a user