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