adding @style and @font support to logbot

This commit is contained in:
manetta 2021-03-12 12:10:01 +01:00
parent 61346f03d4
commit 5d09d6bda4
8 changed files with 136 additions and 29 deletions

View File

@ -12,16 +12,34 @@ _work-in-progress_
*Oh dear, logbot is here!* *Oh dear, logbot is here!*
(You can speak to the bot using @logbot or logbot:) (You can speak to the bot using @logbot or logbot:)
<image>: Your image is added to the log. <image>: Your image is added to the log.
logbot @help: Print this message logbot @help: Print this message
logbot @add <message>: Add a message to the log. logbot @add <message>: Add a message to the log.
logbot @delete <num>: Delete posts from the log. For example: @logbot @delete 5 logbot @delete <num>: Delete posts from the log. For example: @logbot @delete 5
logbot @title <string>: Set the title of your log. logbot @title <string>: Set the title of your log.
logbot @style <element> <css-rule>: Edit the css of your log. For example: logbot @style body background-color: pink; [future-feature]
logbot @style <stylesheet>: Switch to another stylesheet. For example: logbot @style log. Available stylesheets include: log. See https://git.vvvvvvaria.org/varia/bots/ for examples.
logbot @font <font>: Switch to another font. For example: logbot @font font. Available fonts include: polsku, notcouriersans; or select None to switch back to default serif. See https://git.vvvvvvaria.org/varia/bots/ for examples.
logbot @uptime: To check how long @logbot has been around logbot @uptime: To check how long @logbot has been around
@bots: To see who is around :) @bots: To see who is around :)
``` ```
## Stylesheets
Examples soon.
## Fonts
Examples soon.
## Situated tails ## Situated tails
- Archive bot, Relearn 2017, <https://gitlab.com/relearn/relearn2017/-/tree/master/xmpp-bots/archive-bot> - Archive bot, Relearn 2017, <https://gitlab.com/relearn/relearn2017/-/tree/master/xmpp-bots/archive-bot>

3
LogBot/fonts/FONTS.txt Normal file
View File

@ -0,0 +1,3 @@
Polsku, by Open Source Publishing (OSP): http://osp.kitchen/foundry/polsku/
NotCourierSans, by Open Source Publishing (OSP): http://osp.kitchen/foundry/notcouriersans/

BIN
LogBot/fonts/notcouriersans.ttf Executable file

Binary file not shown.

BIN
LogBot/fonts/polsku.ttf Executable file

Binary file not shown.

View File

@ -22,7 +22,9 @@ class Logbot(Bot):
logbot @title <string>: Set the title of your log. logbot @title <string>: Set the title of your log.
logbot @style <element> <css-rule>: Edit the css of your log. For example: logbot @style body background-color: pink; [future-feature] logbot @style <stylesheet>: Switch to another stylesheet. For example: logbot @style log. Available stylesheets include: log. See https://git.vvvvvvaria.org/varia/bots/ for examples.
logbot @font <font>: Switch to another font. For example: logbot @font font. Available fonts include: polsku, notcouriersans; or select None to switch back to default serif. See https://git.vvvvvvaria.org/varia/bots/ for examples.
logbot @uptime: To check how long @logbot has been around logbot @uptime: To check how long @logbot has been around
@ -117,8 +119,7 @@ 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(
# hard-coding the URL for now log_path=os.path.join("https://vvvvvvaria.org/logs/", room_name, "index.html"), # hard-coding the URL for now
log_path=os.path.join("https://vvvvvvaria.org/logs/", room_name, "index.html"),
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")
@ -157,14 +158,20 @@ class Logbot(Bot):
self.db[room]["messages"] = {} self.db[room]["messages"] = {}
if "title" not in self.db[room]: if "title" not in self.db[room]:
self.db[room]["title"] = room self.db[room]["title"] = room
if "stylesheet" not in self.db[room]:
self.db[room]["stylesheet"] = room
if "font" not in self.db[room]:
self.db[room]["font"] = room
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)
shutil.copy("stylesheet.css", room_path) stylesheet_path = os.path.join("stylesheets","linear.css") # default stylesheet
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 }") self.log.info(f"Created a folder for: { room }")
self.log.info(f"Copied stylesheet.css to: { room }") self.log.info(f"Added stylesheet.css to: { room }")
def setup(self): def setup(self):
"""Setup a log for all the rooms LogBot is subscribed to.""" """Setup a log for all the rooms LogBot is subscribed to."""
@ -219,13 +226,47 @@ class Logbot(Bot):
# Response to @title # Response to @title
elif "@title" in message.text: elif "@title" in message.text:
match = re.findall("@title .*", message.content)[0] match = re.findall("@title .*", message.content)[0]
title = match.replace("@title", "") title = match.replace("@title ", "")
self.db[message.room]["title"] = title self.db[message.room]["title"] = title
reply = f"The title of the log is changed to: { title }" reply = f"The title of the log is changed to: { title }"
# Response to @style # Response to @style
elif "@style" in message.text: elif "@style" in message.text:
reply = "This is a future-feature ..." match = re.findall("@style .*", message.content)[0]
stylesheet = match.replace("@style ", "")
stylesheet = stylesheet.lower()
self.db[message.room]["stylesheet"] = stylesheet
room_name = self._parse_room_name(message.room)
room_path = os.path.join(self.output, room_name)
stylesheet_path = os.path.join("stylesheets", f"{ stylesheet }.css")
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 }")
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."
# Response to @font
elif "@font" in message.text:
match = re.findall("@font .*", message.content)[0]
font = match.replace("@font ", "")
font = font.lower()
self.db[message.room]["font"] = font
room_name = self._parse_room_name(message.room)
room_path = os.path.join(self.output, room_name)
font_path = os.path.join("fonts", f"{ font }.ttf")
font_dest_path = os.path.join(room_path, "font.ttf")
if font == 'none':
os.remove(font_dest_path)
reply = "I removed the font and switched back to default serif."
else:
try:
shutil.copy(font_path, font_dest_path)
self.log.info(f"font in room { room_name } switched to: { font }")
reply = f"I'm switching the font of this log to: { font }."
except:
reply = f"The font '{ font }' is unknown to me. Check @help to see the available fonts."
else: else:
reply = "Hmm ... not sure what you want to do?" reply = "Hmm ... not sure what you want to do?"

View File

@ -1,21 +0,0 @@
body {
margin: 1em;
max-width: 800px;
}
.post {
margin: 1em 0;
clear: both;
}
.post p.key {
float: left;
margin: 0 1em 1em;
}
.post p.message {
}
img,
iframe,
audio,
video {
max-width: calc(100% - 100px);
height: auto;
}

View File

@ -0,0 +1,35 @@
@font-face{
font-family: "font";
src: url("font.ttf") format("truetype");
}
body {
margin: 1em 1em 3em 1em;
background-color: #eeebeb;
font-family: "font", serif;
font-size: 16px;
line-height: 1.6;
}
.post {
margin: 1.5em 2em;
float: left;
}
.post p.key {
float: left;
margin: 0 1em;
font-size: 10px;
line-height: 1px;
}
.post p.message {
float: left;
max-width: 350px;
margin: -0.6em 0;
}
img,
iframe,
audio,
video {
max-width: 350px;
height: auto;
clear: both;
margin: 0.4em 0;
}

View File

@ -0,0 +1,31 @@
@font-face{
font-family: "font";
src: url("font.ttf") format("truetype");
}
body {
margin: 1em;
max-width: 800px;
background-color: lightyellow;
font-family: "font", serif;
font-size: 16px;
line-height: 1.6;
}
.post {
margin: 1em 0;
clear: both;
}
.post p.key {
float: left;
margin: 0 1em 1em;
font-size: 10px;
}
.post p.message {
}
img,
iframe,
audio,
video {
max-width: calc(100% - 100px);
height: auto;
margin: 0.6em 0;
}