2023-04-25 11:25:53 +00:00
|
|
|
from classes.bot import GPTBot
|
2023-04-16 14:08:57 +00:00
|
|
|
|
2023-04-17 20:28:29 +00:00
|
|
|
from argparse import ArgumentParser
|
2023-04-25 11:25:53 +00:00
|
|
|
from configparser import ConfigParser
|
2023-04-23 13:26:46 +00:00
|
|
|
|
2023-04-25 11:25:53 +00:00
|
|
|
import signal
|
|
|
|
import asyncio
|
2023-04-23 13:26:46 +00:00
|
|
|
|
|
|
|
|
2023-04-25 11:25:53 +00:00
|
|
|
def sigterm_handler(_signo, _stack_frame):
|
|
|
|
exit()
|
2023-04-23 13:26:46 +00:00
|
|
|
|
|
|
|
|
2023-04-16 14:08:57 +00:00
|
|
|
if __name__ == "__main__":
|
2023-04-17 20:28:29 +00:00
|
|
|
# Parse command line arguments
|
|
|
|
parser = ArgumentParser()
|
|
|
|
parser.add_argument(
|
|
|
|
"--config", help="Path to config file (default: config.ini in working directory)", default="config.ini")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# Read config file
|
|
|
|
config = ConfigParser()
|
|
|
|
config.read(args.config)
|
|
|
|
|
2023-04-25 11:25:53 +00:00
|
|
|
# Create bot
|
|
|
|
bot = GPTBot.from_config(config)
|
|
|
|
|
|
|
|
# Listen for SIGTERM
|
|
|
|
signal.signal(signal.SIGTERM, sigterm_handler)
|
|
|
|
|
|
|
|
# Start bot
|
2023-04-16 14:08:57 +00:00
|
|
|
try:
|
2023-04-25 11:25:53 +00:00
|
|
|
asyncio.run(bot.run())
|
2023-04-17 20:28:29 +00:00
|
|
|
except KeyboardInterrupt:
|
2023-04-25 11:25:53 +00:00
|
|
|
print("Received KeyboardInterrupt - exiting...")
|
2023-04-19 06:11:28 +00:00
|
|
|
except SystemExit:
|
2023-04-25 11:25:53 +00:00
|
|
|
print("Received SIGTERM - exiting...")
|