move stuff under main()
This commit is contained in:
parent
bf0a3bde6a
commit
27616867f5
31
main.py
31
main.py
|
@ -22,33 +22,20 @@ 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)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
global_config.load(args.config)
|
global_config.load(args.config)
|
||||||
try:
|
try:
|
||||||
global_config.validate()
|
global_config.validate()
|
||||||
except SchemeValidationError as e:
|
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:
|
||||||
|
|
Loading…
Reference in New Issue