Initial commit
This commit is contained in:
52
main.py
Normal file
52
main.py
Normal file
@@ -0,0 +1,52 @@
|
||||
"""
|
||||
2026-matrix-downloader entry point
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import traceback
|
||||
import signal
|
||||
|
||||
import config
|
||||
import util
|
||||
import bot
|
||||
import logic
|
||||
from datatypes import AppConfig
|
||||
|
||||
async def main() -> None:
|
||||
"""Entry point"""
|
||||
# setup signal handler
|
||||
util.setup_app_stop_event()
|
||||
loop = asyncio.get_running_loop()
|
||||
for sig in (signal.SIGINT, signal.SIGTERM):
|
||||
loop.add_signal_handler(sig, lambda: util.request_app_stop("Signal caught"))
|
||||
|
||||
# setup
|
||||
util.setup_logging()
|
||||
util.log_info("2026-matrix-csonac")
|
||||
|
||||
# load the config
|
||||
cfg: AppConfig = await config.load_config("config.json") # type: ignore
|
||||
if cfg is None:
|
||||
util.log_error("Could't load config")
|
||||
return
|
||||
|
||||
# start the bot
|
||||
if not await bot.start(cfg):
|
||||
util.log_error("Could't start the bot")
|
||||
return
|
||||
await logic.setup(bot.get_client())
|
||||
|
||||
# wait for stop
|
||||
await util.get_app_stop_event().wait()
|
||||
|
||||
# stop
|
||||
await logic.stop()
|
||||
await bot.stop()
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
asyncio.run(main())
|
||||
except SystemExit:
|
||||
raise
|
||||
except:
|
||||
traceback.print_exc()
|
||||
Reference in New Issue
Block a user