forked from varia/bots
Let my auto-formatter do its thing
This commit is contained in:
parent
52a26d1646
commit
3fea24c46b
@ -2,11 +2,13 @@ import os
|
|||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from urllib.parse import urlparse
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import jinja2
|
import jinja2
|
||||||
from xbotlib import Bot
|
from xbotlib import Bot
|
||||||
|
|
||||||
|
|
||||||
class Logbot(Bot):
|
class Logbot(Bot):
|
||||||
|
|
||||||
help = """Oh dear, logbot is here!
|
help = """Oh dear, logbot is here!
|
||||||
@ -89,9 +91,7 @@ class Logbot(Bot):
|
|||||||
if message.url.lower().endswith(self.IMAGE_TYPES):
|
if message.url.lower().endswith(self.IMAGE_TYPES):
|
||||||
media_post = f'<img src="{ media_path }">'
|
media_post = f'<img src="{ media_path }">'
|
||||||
elif message.url.lower().endswith(self.FILE_TYPES):
|
elif message.url.lower().endswith(self.FILE_TYPES):
|
||||||
media_post = (
|
media_post = f'<iframe src="{ media_path }"></iframe>'
|
||||||
f'<iframe src="{ media_path }"></iframe>'
|
|
||||||
)
|
|
||||||
elif message.url.lower().endswith(self.AUDIO_TYPES):
|
elif message.url.lower().endswith(self.AUDIO_TYPES):
|
||||||
media_post = f'<audio controls src="{ media_path }"></audio>'
|
media_post = f'<audio controls src="{ media_path }"></audio>'
|
||||||
elif message.url.lower().endswith(self.VIDEO_TYPES):
|
elif message.url.lower().endswith(self.VIDEO_TYPES):
|
||||||
@ -111,7 +111,7 @@ class Logbot(Bot):
|
|||||||
with open(log_path, "w") as out:
|
with open(log_path, "w") as out:
|
||||||
html = template.render(
|
html = template.render(
|
||||||
title=self.db[message.room]["title"],
|
title=self.db[message.room]["title"],
|
||||||
db=self.db[message.room]["messages"]
|
db=self.db[message.room]["messages"],
|
||||||
)
|
)
|
||||||
out.write(html)
|
out.write(html)
|
||||||
self.log.info(f"writing to: { log_path }")
|
self.log.info(f"writing to: { log_path }")
|
||||||
@ -125,10 +125,12 @@ class Logbot(Bot):
|
|||||||
date = datetime.now()
|
date = datetime.now()
|
||||||
with open(feed_path, "w") as out:
|
with open(feed_path, "w") as out:
|
||||||
feed = template.render(
|
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"],
|
title=self.db[message.room]["title"],
|
||||||
db=self.db[message.room],
|
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)
|
out.write(feed)
|
||||||
self.log.info(f"writing to: { feed_path }")
|
self.log.info(f"writing to: { feed_path }")
|
||||||
@ -169,13 +171,15 @@ class Logbot(Bot):
|
|||||||
if "stylesheet" not in self.db[room]:
|
if "stylesheet" not in self.db[room]:
|
||||||
self.db[room]["stylesheet"] = "timeline" # default stylesheet
|
self.db[room]["stylesheet"] = "timeline" # default stylesheet
|
||||||
if "font" not in self.db[room]:
|
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.db._dumps()
|
||||||
self.log.info(f"Added to the database: { room }")
|
self.log.info(f"Added to the database: { room }")
|
||||||
|
|
||||||
if not os.path.exists(room_path):
|
if not os.path.exists(room_path):
|
||||||
os.mkdir(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")
|
stylesheet_dest_path = os.path.join(room_path, "stylesheet.css")
|
||||||
shutil.copy(stylesheet_path, stylesheet_dest_path)
|
shutil.copy(stylesheet_path, stylesheet_dest_path)
|
||||||
self.log.info(f"Created a folder for: { room }")
|
self.log.info(f"Created a folder for: { room }")
|
||||||
@ -253,7 +257,7 @@ class Logbot(Bot):
|
|||||||
self.db[message.room]["folder"] = new_folder_name
|
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}"
|
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:
|
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
|
# Response to @style
|
||||||
elif "@style" in message.text:
|
elif "@style" in message.text:
|
||||||
@ -269,7 +273,9 @@ class Logbot(Bot):
|
|||||||
stylesheet_dest_path = os.path.join(room_path, "stylesheet.css")
|
stylesheet_dest_path = os.path.join(room_path, "stylesheet.css")
|
||||||
try:
|
try:
|
||||||
shutil.copy(stylesheet_path, stylesheet_dest_path)
|
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 }."
|
reply = f"I'm switching the stylesheet of this log to: { stylesheet }."
|
||||||
except:
|
except:
|
||||||
reply = f"The stylesheet '{ stylesheet }' is unknown to me. Check @help to see the available stylesheets."
|
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)
|
room_path = self._parse_room_name(room_path)
|
||||||
font_path = os.path.join("fonts", f"{ font }.ttf")
|
font_path = os.path.join("fonts", f"{ font }.ttf")
|
||||||
font_dest_path = os.path.join(room_path, "font.ttf")
|
font_dest_path = os.path.join(room_path, "font.ttf")
|
||||||
if font == 'none':
|
if font == "none":
|
||||||
os.remove(font_dest_path)
|
os.remove(font_dest_path)
|
||||||
reply = "I removed the font and switched back to default serif."
|
reply = "I removed the font and switched back to default serif."
|
||||||
else:
|
else:
|
||||||
@ -309,4 +315,5 @@ class Logbot(Bot):
|
|||||||
# Reply to the groupchat
|
# Reply to the groupchat
|
||||||
self.reply(reply, room=message.room)
|
self.reply(reply, room=message.room)
|
||||||
|
|
||||||
|
|
||||||
Logbot()
|
Logbot()
|
||||||
|
Loading…
Reference in New Issue
Block a user