gptbot.py 882 B

12345678910111213141516171819202122232425262728293031323334353637
  1. from classes.bot import GPTBot
  2. from argparse import ArgumentParser
  3. from configparser import ConfigParser
  4. import signal
  5. import asyncio
  6. def sigterm_handler(_signo, _stack_frame):
  7. exit()
  8. if __name__ == "__main__":
  9. # Parse command line arguments
  10. parser = ArgumentParser()
  11. parser.add_argument(
  12. "--config", help="Path to config file (default: config.ini in working directory)", default="config.ini")
  13. args = parser.parse_args()
  14. # Read config file
  15. config = ConfigParser()
  16. config.read(args.config)
  17. # Create bot
  18. bot = GPTBot.from_config(config)
  19. # Listen for SIGTERM
  20. signal.signal(signal.SIGTERM, sigterm_handler)
  21. # Start bot
  22. try:
  23. asyncio.run(bot.run())
  24. except KeyboardInterrupt:
  25. print("Received KeyboardInterrupt - exiting...")
  26. except SystemExit:
  27. print("Received SIGTERM - exiting...")