|
|
@ -2,11 +2,13 @@ import os |
|
|
|
import re |
|
|
|
import shutil |
|
|
|
import urllib.request |
|
|
|
from urllib.parse import urlparse |
|
|
|
from datetime import datetime |
|
|
|
from urllib.parse import urlparse |
|
|
|
|
|
|
|
import jinja2 |
|
|
|
from xbotlib import Bot |
|
|
|
|
|
|
|
|
|
|
|
class Logbot(Bot): |
|
|
|
|
|
|
|
help = """Oh dear, logbot is here! |
|
|
@ -89,9 +91,7 @@ class Logbot(Bot): |
|
|
|
if message.url.lower().endswith(self.IMAGE_TYPES): |
|
|
|
media_post = f'<img src="{ media_path }">' |
|
|
|
elif message.url.lower().endswith(self.FILE_TYPES): |
|
|
|
media_post = ( |
|
|
|
f'<iframe src="{ media_path }"></iframe>' |
|
|
|
) |
|
|
|
media_post = f'<iframe src="{ media_path }"></iframe>' |
|
|
|
elif message.url.lower().endswith(self.AUDIO_TYPES): |
|
|
|
media_post = f'<audio controls src="{ media_path }"></audio>' |
|
|
|
elif message.url.lower().endswith(self.VIDEO_TYPES): |
|
|
@ -111,7 +111,7 @@ class Logbot(Bot): |
|
|
|
with open(log_path, "w") as out: |
|
|
|
html = template.render( |
|
|
|
title=self.db[message.room]["title"], |
|
|
|
db=self.db[message.room]["messages"] |
|
|
|
db=self.db[message.room]["messages"], |
|
|
|
) |
|
|
|
out.write(html) |
|
|
|
self.log.info(f"writing to: { log_path }") |
|
|
@ -125,10 +125,12 @@ class Logbot(Bot): |
|
|
|
date = datetime.now() |
|
|
|
with open(feed_path, "w") as out: |
|
|
|
feed = template.render( |
|
|
|
log_path=os.path.join("https://vvvvvvaria.org/logs/", folder_name, "index.html"), # hard-coding the URL for now |
|
|
|
log_path=os.path.join( |
|
|
|
"https://vvvvvvaria.org/logs/", folder_name, "index.html" |
|
|
|
), # hard-coding the URL for now |
|
|
|
title=self.db[message.room]["title"], |
|
|
|
db=self.db[message.room], |
|
|
|
date=date.strftime("%A, %d. %B %Y %I:%M%p") |
|
|
|
date=date.strftime("%A, %d. %B %Y %I:%M%p"), |
|
|
|
) |
|
|
|
out.write(feed) |
|
|
|
self.log.info(f"writing to: { feed_path }") |
|
|
@ -169,13 +171,15 @@ class Logbot(Bot): |
|
|
|
if "stylesheet" not in self.db[room]: |
|
|
|
self.db[room]["stylesheet"] = "timeline" # default stylesheet |
|
|
|
if "font" not in self.db[room]: |
|
|
|
self.db[room]["font"] = 'none' # default font |
|
|
|
self.db[room]["font"] = "none" # default font |
|
|
|
self.db._dumps() |
|
|
|
self.log.info(f"Added to the database: { room }") |
|
|
|
|
|
|
|
if not os.path.exists(room_path): |
|
|
|
os.mkdir(room_path) |
|
|
|
stylesheet_path = os.path.join("stylesheets", self.db[room]["stylesheet"] + ".css") |
|
|
|
stylesheet_path = os.path.join( |
|
|
|
"stylesheets", self.db[room]["stylesheet"] + ".css" |
|
|
|
) |
|
|
|
stylesheet_dest_path = os.path.join(room_path, "stylesheet.css") |
|
|
|
shutil.copy(stylesheet_path, stylesheet_dest_path) |
|
|
|
self.log.info(f"Created a folder for: { room }") |
|
|
@ -253,7 +257,7 @@ class Logbot(Bot): |
|
|
|
self.db[message.room]["folder"] = new_folder_name |
|
|
|
reply = f"The foldername of the log is changed to: { new_folder_name }. The URL of the log changed into: https://vvvvvvaria.org/logs/{ new_folder_name}" |
|
|
|
except: |
|
|
|
reply = f"Sorry i couldn\'t shange that foldername into: '{ new_folder_name }'. Try again with: 'logbot @folder newname'." |
|
|
|
reply = f"Sorry i couldn't shange that foldername into: '{ new_folder_name }'. Try again with: 'logbot @folder newname'." |
|
|
|
|
|
|
|
# Response to @style |
|
|
|
elif "@style" in message.text: |
|
|
@ -269,7 +273,9 @@ class Logbot(Bot): |
|
|
|
stylesheet_dest_path = os.path.join(room_path, "stylesheet.css") |
|
|
|
try: |
|
|
|
shutil.copy(stylesheet_path, stylesheet_dest_path) |
|
|
|
self.log.info(f"Stylesheet in room { room_name } switched to: { stylesheet }") |
|
|
|
self.log.info( |
|
|
|
f"Stylesheet in room { room_name } switched to: { stylesheet }" |
|
|
|
) |
|
|
|
reply = f"I'm switching the stylesheet of this log to: { stylesheet }." |
|
|
|
except: |
|
|
|
reply = f"The stylesheet '{ stylesheet }' is unknown to me. Check @help to see the available stylesheets." |
|
|
@ -286,7 +292,7 @@ class Logbot(Bot): |
|
|
|
room_path = self._parse_room_name(room_path) |
|
|
|
font_path = os.path.join("fonts", f"{ font }.ttf") |
|
|
|
font_dest_path = os.path.join(room_path, "font.ttf") |
|
|
|
if font == 'none': |
|
|
|
if font == "none": |
|
|
|
os.remove(font_dest_path) |
|
|
|
reply = "I removed the font and switched back to default serif." |
|
|
|
else: |
|
|
@ -309,4 +315,5 @@ class Logbot(Bot): |
|
|
|
# Reply to the groupchat |
|
|
|
self.reply(reply, room=message.room) |
|
|
|
|
|
|
|
|
|
|
|
Logbot() |
|
|
|