File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
zulip_bots/zulip_bots/bots/archive Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ Note: this bot was written by Kimi K2.
3+ """
4+
5+ import re
6+ import waybackpy
7+
8+ class ArchiveBotHandler :
9+ def usage (self ) -> str :
10+ return """
11+ This bot listens for messages containing URLs, saves each URL to the
12+ Internet Archive, and replies with the fresh archive.org link(s).
13+ Mention the bot or send it a PM that contains a URL.
14+ """
15+
16+ def handle_message (self , message : dict , bot_handler ) -> None :
17+ content = message ["content" ]
18+ urls = re .findall (r"https?://[^\s]+" , content )
19+ if not urls :
20+ return
21+
22+ replies = []
23+ for url in urls :
24+ try :
25+ archive_url = waybackpy .Url (url ).save ()
26+ replies .append (f"Archived: { archive_url } " )
27+ except Exception as exc :
28+ replies .append (f"Failed to archive { url } – { exc } " )
29+
30+ if replies :
31+ bot_handler .send_reply (message , "\n " .join (replies ))
32+
33+ handler_class = ArchiveBotHandler
Original file line number Diff line number Diff line change 1+ re
2+ waybackpy
You can’t perform that action at this time.
0 commit comments