forked from varia/bots
38 lines
934 B
Python
38 lines
934 B
Python
|
from os.path import basename
|
||
|
from urllib.parse import urlparse
|
||
|
|
||
|
from xbotlib import Bot
|
||
|
|
||
|
|
||
|
class LogsBot(Bot):
|
||
|
"""Collaborative log writing."""
|
||
|
|
||
|
help = """Logging to https://logsbot.bots.varia.zone"""
|
||
|
|
||
|
def group(self, message):
|
||
|
"""Move group messages into the log."""
|
||
|
if not message.url:
|
||
|
return
|
||
|
|
||
|
if message.room not in self.db.keys():
|
||
|
self.db[message.room] = []
|
||
|
|
||
|
self.db[message.room].append(message.url)
|
||
|
|
||
|
filename = basename(urlparse(message.url).path)
|
||
|
return self.reply(f"Added {filename} 🤩️", room=message.room)
|
||
|
|
||
|
def serve(self, request):
|
||
|
"""Serve the log."""
|
||
|
payload = {"rooms": []}
|
||
|
|
||
|
for room in self.db.keys():
|
||
|
payload["rooms"].append(room)
|
||
|
payload[room] = {"urls": self.db[room]}
|
||
|
|
||
|
rendered = self.template.render(payload=payload)
|
||
|
return self.respond(rendered)
|
||
|
|
||
|
|
||
|
LogsBot()
|