move stuff under main()

This commit is contained in:
Cyberes 2024-04-08 00:46:12 -06:00
parent bf0a3bde6a
commit 27616867f5
1 changed files with 16 additions and 25 deletions

21
main.py
View File

@ -22,11 +22,8 @@ SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
logging.basicConfig() logging.basicConfig()
logger = logging.getLogger('MatrixGPT') logger = logging.getLogger('MatrixGPT')
parser = argparse.ArgumentParser(description='MatrixGPT Bot')
parser.add_argument('--config', default=Path(SCRIPT_DIR, 'config.yaml'), help='Path to config.yaml if it is not located next to this executable.')
args = parser.parse_args()
# Load config async def main(args):
args.config = Path(args.config) args.config = Path(args.config)
if not args.config.exists(): if not args.config.exists():
logger.critical('Config file does not exist:', args.config) logger.critical('Config file does not exist:', args.config)
@ -39,16 +36,6 @@ except SchemeValidationError as e:
logger.critical(f'Config validation error: {e}') logger.critical(f'Config validation error: {e}')
sys.exit(1) sys.exit(1)
def retry(msg=None):
if msg:
logger.warning(f'{msg}, retrying in 15s...')
else:
logger.warning(f'Retrying in 15s...')
time.sleep(15)
async def main():
if global_config['logging']['log_level'] == 'info': if global_config['logging']['log_level'] == 'info':
log_level = logging.INFO log_level = logging.INFO
elif global_config['logging']['log_level'] == 'debug': elif global_config['logging']['log_level'] == 'debug':
@ -148,9 +135,13 @@ async def main():
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(description='MatrixGPT Bot')
parser.add_argument('--config', default=Path(SCRIPT_DIR, 'config.yaml'), help='Path to config.yaml if it is not located next to this executable.')
args = parser.parse_args()
while True: while True:
try: try:
asyncio.run(main()) asyncio.run(main(args))
except KeyboardInterrupt: except KeyboardInterrupt:
os.kill(os.getpid(), signal.SIGTERM) os.kill(os.getpid(), signal.SIGTERM)
except Exception: except Exception: