diff --git a/LogBot/README.md b/LogBot/README.md index 1a4f3bd..f8e4e60 100644 --- a/LogBot/README.md +++ b/LogBot/README.md @@ -12,16 +12,34 @@ _work-in-progress_ *Oh dear, logbot is here!* (You can speak to the bot using @logbot or logbot:) + : Your image is added to the log. + logbot @help: Print this message + logbot @add : Add a message to the log. + logbot @delete : Delete posts from the log. For example: @logbot @delete 5 + logbot @title : Set the title of your log. -logbot @style : Edit the css of your log. For example: logbot @style body background-color: pink; [future-feature] + +logbot @style : Switch to another stylesheet. For example: logbot @style log. Available stylesheets include: log. See https://git.vvvvvvaria.org/varia/bots/ for examples. + +logbot @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 + @bots: To see who is around :) ``` +## Stylesheets + +Examples soon. + +## Fonts + +Examples soon. + ## Situated tails - Archive bot, Relearn 2017, diff --git a/LogBot/fonts/FONTS.txt b/LogBot/fonts/FONTS.txt new file mode 100644 index 0000000..f198d74 --- /dev/null +++ b/LogBot/fonts/FONTS.txt @@ -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/ diff --git a/LogBot/fonts/notcouriersans.ttf b/LogBot/fonts/notcouriersans.ttf new file mode 100755 index 0000000..9fff7fd Binary files /dev/null and b/LogBot/fonts/notcouriersans.ttf differ diff --git a/LogBot/fonts/polsku.ttf b/LogBot/fonts/polsku.ttf new file mode 100755 index 0000000..35c7d9c Binary files /dev/null and b/LogBot/fonts/polsku.ttf differ diff --git a/LogBot/logbot.py b/LogBot/logbot.py index 20edd5d..f25e14e 100644 --- a/LogBot/logbot.py +++ b/LogBot/logbot.py @@ -22,7 +22,9 @@ class Logbot(Bot): logbot @title : Set the title of your log. - logbot @style : Edit the css of your log. For example: logbot @style body background-color: pink; [future-feature] + logbot @style : Switch to another stylesheet. For example: logbot @style log. Available stylesheets include: log. See https://git.vvvvvvaria.org/varia/bots/ for examples. + + logbot @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 @@ -117,8 +119,7 @@ class Logbot(Bot): date = datetime.now() with open(feed_path, "w") as out: feed = template.render( - # hard-coding the URL for now - log_path=os.path.join("https://vvvvvvaria.org/logs/", room_name, "index.html"), + log_path=os.path.join("https://vvvvvvaria.org/logs/", room_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") @@ -157,14 +158,20 @@ class Logbot(Bot): self.db[room]["messages"] = {} if "title" not in self.db[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.log.info(f"Added to the database: { room }") if not os.path.exists(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"Copied stylesheet.css to: { room }") + self.log.info(f"Added stylesheet.css to: { room }") def setup(self): """Setup a log for all the rooms LogBot is subscribed to.""" @@ -219,13 +226,47 @@ class Logbot(Bot): # Response to @title elif "@title" in message.text: match = re.findall("@title .*", message.content)[0] - title = match.replace("@title", "") + title = match.replace("@title ", "") self.db[message.room]["title"] = title reply = f"The title of the log is changed to: { title }" # Response to @style 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: reply = "Hmm ... not sure what you want to do?" diff --git a/LogBot/stylesheet.css b/LogBot/stylesheet.css deleted file mode 100644 index a5cc991..0000000 --- a/LogBot/stylesheet.css +++ /dev/null @@ -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; -} diff --git a/LogBot/stylesheets/float.css b/LogBot/stylesheets/float.css new file mode 100644 index 0000000..724f2af --- /dev/null +++ b/LogBot/stylesheets/float.css @@ -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; +} diff --git a/LogBot/stylesheets/linear.css b/LogBot/stylesheets/linear.css new file mode 100644 index 0000000..9ac83b1 --- /dev/null +++ b/LogBot/stylesheets/linear.css @@ -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; +}