Files
2026-matrix-csonac/main.py
nikita 4194f3da48 mab update, !short command, last_access fix
- Updated mab to v0.5.0
- Added `!short` command to add named tokens
- Fixed `last_access_at` field not being updated
2026-09-13 00:12:00 +03:00

76 lines
1.8 KiB
Python

"""
2026-matrix-downloader entry point
"""
import asyncio
import traceback
import signal
from pathlib import Path
from mab import MatrixBot, MatrixBotConfig
from datatypes import AppConfig
import database
import config
import util
import bot_callbacks
import web
bot: MatrixBot = None # type: ignore
async def main() -> None:
"""Entry point"""
global bot
# 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
# setup the bot
matrix_bot_config = MatrixBotConfig(
matrix_homeserver_url=cfg.matrix_homeserver,
matrix_username_localpart=cfg.matrix_user,
storage_directory=Path(cfg.store_dir)
)
bot = MatrixBot(matrix_bot_config)
# setup the database
db = database.Database(Path("database.sqlite"))
# setup the callbacks
bot_callbacks.setup(bot, db)
# setup the web server
web_server = web.Web(cfg, bot, db)
# start the app
if not await db.connect():
util.log_error("Can't connect to the database!")
return
await bot.start()
await web_server.start()
# wait for Ctrl+C
await util.get_app_stop_event().wait()
# stop the app
await web_server.stop()
await bot.stop()
await db.disconnect()
if __name__ == "__main__":
try:
asyncio.run(main())
except SystemExit:
raise
except:
traceback.print_exc()