From e3a0a901f0dc2975406c9494a713bc5340b4d821 Mon Sep 17 00:00:00 2001 From: Danny Garside Date: Wed, 1 Oct 2025 23:33:35 +0100 Subject: [PATCH 1/3] bot: add archive bot --- zulip_bots/zulip_bots/bots/archive/archive.py | 33 +++++++++++++++++++ .../zulip_bots/bots/archive/requirements.txt | 2 ++ 2 files changed, 35 insertions(+) create mode 100644 zulip_bots/zulip_bots/bots/archive/archive.py create mode 100644 zulip_bots/zulip_bots/bots/archive/requirements.txt diff --git a/zulip_bots/zulip_bots/bots/archive/archive.py b/zulip_bots/zulip_bots/bots/archive/archive.py new file mode 100644 index 000000000..8ce8bdb7c --- /dev/null +++ b/zulip_bots/zulip_bots/bots/archive/archive.py @@ -0,0 +1,33 @@ +""" +Note: this bot was written by Kimi K2. +""" + +import re +import waybackpy + +class ArchiveBotHandler: + def usage(self) -> str: + return """ + This bot listens for messages containing URLs, saves each URL to the + Internet Archive, and replies with the fresh archive.org link(s). + Mention the bot or send it a PM that contains a URL. + """ + + def handle_message(self, message: dict, bot_handler) -> None: + content = message["content"] + urls = re.findall(r"https?://[^\s]+", content) + if not urls: + return + + replies = [] + for url in urls: + try: + archive_url = waybackpy.Url(url).save() + replies.append(f"Archived: {archive_url}") + except Exception as exc: + replies.append(f"Failed to archive {url} – {exc}") + + if replies: + bot_handler.send_reply(message, "\n".join(replies)) + +handler_class = ArchiveBotHandler diff --git a/zulip_bots/zulip_bots/bots/archive/requirements.txt b/zulip_bots/zulip_bots/bots/archive/requirements.txt new file mode 100644 index 000000000..4e9b62e83 --- /dev/null +++ b/zulip_bots/zulip_bots/bots/archive/requirements.txt @@ -0,0 +1,2 @@ +re +waybackpy From 1e156387ceb2c89263583222c1c34ef1e16045cd Mon Sep 17 00:00:00 2001 From: Danny Garside Date: Wed, 1 Oct 2025 23:56:50 +0100 Subject: [PATCH 2/3] remove re as a requirement --- zulip_bots/zulip_bots/bots/archive/requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/zulip_bots/zulip_bots/bots/archive/requirements.txt b/zulip_bots/zulip_bots/bots/archive/requirements.txt index 4e9b62e83..48cec14e6 100644 --- a/zulip_bots/zulip_bots/bots/archive/requirements.txt +++ b/zulip_bots/zulip_bots/bots/archive/requirements.txt @@ -1,2 +1 @@ -re waybackpy From 632e00d922500417474edd53d4fb63f97bfee160 Mon Sep 17 00:00:00 2001 From: Danny Garside Date: Thu, 2 Oct 2025 00:03:24 +0100 Subject: [PATCH 3/3] make linter happy --- zulip_bots/zulip_bots/bots/archive/archive.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/zulip_bots/zulip_bots/bots/archive/archive.py b/zulip_bots/zulip_bots/bots/archive/archive.py index 8ce8bdb7c..e3dbc4c1c 100644 --- a/zulip_bots/zulip_bots/bots/archive/archive.py +++ b/zulip_bots/zulip_bots/bots/archive/archive.py @@ -3,8 +3,10 @@ """ import re + import waybackpy + class ArchiveBotHandler: def usage(self) -> str: return """ @@ -30,4 +32,5 @@ def handle_message(self, message: dict, bot_handler) -> None: if replies: bot_handler.send_reply(message, "\n".join(replies)) + handler_class = ArchiveBotHandler