Files
omnibot22/omnibot/__main__.py
Alek Ratzloff 82e50f86d6 Add graceful exits
This sets up a set of ropes and pulleys that signal the `Bot.keepalive`
function to clean things up after a quit signal has been sent. This
allows plugins to define an `on_unload` function to save any important
datas on intentional exit.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-05-24 19:16:15 -07:00

30 lines
630 B
Python

import asyncio
from functools import partial
import logging
import signal
from .config import ServerConfig
from .bot import Bot
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s - %(name)-12s - %(levelname)-8s - %(message)s",
)
log = logging.getLogger(__name__)
log.debug("Loading config")
config = ServerConfig()
config.load("config.toml")
log.debug("Using configuration: %s", config)
bot = Bot(config)
try:
asyncio.run(bot.run())
except KeyboardInterrupt:
log.info("Got ctrl-c")
finally:
log.info("Quitting, press ctrl-c to quit immediately")
bot.quit()
asyncio.run(bot.keepalive())