maubot-media/media_bot/db.py
Maddox bb29db6f32 v0.4.2: SQLite, subscriptions, Sonarr webhook, daily digest
- Enable maubot's bundled SQLite (database: true, webapp: true)
- Schema: subscriptions(mxid, sonarr_series_id, title, added_at) +
  digest_state for once-daily idempotency
- Commands: !media subscribe / unsubscribe / subscriptions / digest
- @web.post(/sonarr-webhook): on Download events, mention subscribers
  in notifications_room (Bearer auth via sonarr_webhook_secret)
- Daily digest loop: fires at digest_hour (Indianapolis), summarises
  Emby recently-added, NZBGet+qBt 24h completions, queue depth.
  Approximate EST/EDT calc since maubot container ships without tzdata.
2026-04-28 19:13:19 -04:00

29 lines
936 B
Python

"""SQLite schema for the media bot — subscriptions + digest state."""
from mautrix.util.async_db import Connection, UpgradeTable
upgrade_table = UpgradeTable()
@upgrade_table.register(description="Initial schema: subscriptions + digest_state")
async def upgrade_v1(conn: Connection) -> None:
await conn.execute(
"""
CREATE TABLE subscriptions (
mxid TEXT NOT NULL,
sonarr_series_id INTEGER NOT NULL,
title TEXT NOT NULL,
added_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (mxid, sonarr_series_id)
)
"""
)
await conn.execute(
"""
CREATE TABLE digest_state (
id INTEGER PRIMARY KEY CHECK (id = 1),
last_run_date TEXT
)
"""
)
await conn.execute("INSERT INTO digest_state (id, last_run_date) VALUES (1, NULL)")