Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions zulip_bots/zulip_bots/bots/archive/archive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
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
1 change: 1 addition & 0 deletions zulip_bots/zulip_bots/bots/archive/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
waybackpy