diff --git a/base-config.yaml b/base-config.yaml index 4307ea0..04b1038 100644 --- a/base-config.yaml +++ b/base-config.yaml @@ -28,6 +28,11 @@ sonarr_webhook_secret: "" digest_enabled: true digest_hour: 8 # local hour (Indianapolis), 0-23 +# Sunday digest also pulls the emby-cleaner recap from ntfy. +# The cleaner runs Sunday 4:20 AM (cron on control); digest fires after. +ntfy_url: "https://ntfy.3ddbrewery.com" +emby_cleaner_topic: "emby-cleaner" + # --- Service endpoints --- seerr: diff --git a/maubot.yaml b/maubot.yaml index 932bf74..ca6270e 100644 --- a/maubot.yaml +++ b/maubot.yaml @@ -1,6 +1,6 @@ maubot: 0.3.1 id: com.3ddbrewery.media -version: 0.4.2 +version: 0.4.3 license: MIT modules: - media_bot diff --git a/media_bot/bot.py b/media_bot/bot.py index 4ea1048..6c50e41 100644 --- a/media_bot/bot.py +++ b/media_bot/bot.py @@ -102,6 +102,8 @@ class Config(BaseProxyConfig): helper.copy("sonarr_webhook_secret") helper.copy("digest_enabled") helper.copy("digest_hour") + helper.copy("ntfy_url") + helper.copy("emby_cleaner_topic") helper.copy("seerr") helper.copy("sonarr") helper.copy("radarr") @@ -1258,7 +1260,9 @@ class MediaBot(Plugin): s_q = sonarr_q if not isinstance(sonarr_q, Exception) else [] r_q = radarr_q if not isinstance(radarr_q, Exception) else [] - today_str = _local_now().strftime("%A, %b %d") + local = _local_now() + is_sunday = local.weekday() == 6 # Mon=0..Sun=6 + today_str = local.strftime("%A, %b %d") lines = [f"**๐Ÿ“ฐ Daily digest โ€” {today_str}**", ""] lines.append(f"**๐Ÿ†• Recently added ({len(added)}):**") for it in added[:8]: @@ -1277,7 +1281,50 @@ class MediaBot(Plugin): lines.append(f"- *{t.get('name','?')}* โ€” {_human_bytes(t.get('size') or 0)}") lines.append("") lines.append(f"**๐Ÿ“ฅ Queued: {len(s_q)} TV ยท {len(r_q)} movies**") + + if is_sunday: + cleaner_lines = await self._fetch_emby_cleaner_recap() + if cleaner_lines: + lines.append("") + lines.append("**๐Ÿงน Weekly cleanup (emby-cleaner):**") + lines.extend(cleaner_lines) + await self.client.send_message( RoomID(room), TextMessageEventContent(msgtype=MessageType.NOTICE, body="\n".join(lines)), ) + + async def _fetch_emby_cleaner_recap(self) -> list[str]: + """Pull the last 12h of messages from the emby-cleaner ntfy topic.""" + ntfy = (self.config["ntfy_url"] or "").rstrip("/") + topic = self.config["emby_cleaner_topic"] or "emby-cleaner" + if not ntfy: + return [] + url = f"{ntfy}/{topic}/json?poll=1&since=12h" + try: + async with self.session.get(url) as r: + if r.status >= 400: + self.log.info("ntfy fetch %s โ†’ %s", url, r.status) + return [] + text = await r.text() + except Exception as ex: + self.log.warning("ntfy fetch failed: %s", ex) + return [] + out: list[str] = [] + for raw in text.splitlines(): + raw = raw.strip() + if not raw: + continue + try: + msg = __import__("json").loads(raw) + except Exception: + continue + title = msg.get("title") or "" + body = (msg.get("message") or "").strip() + if title: + out.append(f"- *{title}*") + for line in body.splitlines()[:6]: + line = line.strip() + if line: + out.append(f" {line}") + return out[:25]