From ab5319768ca27d876366983cacc696ab4c0383b1 Mon Sep 17 00:00:00 2001 From: manetta Date: Thu, 6 May 2021 22:21:58 +0200 Subject: [PATCH] the changing foldername feature is there! yiuhu! speaking back to #5 --- LogBot/logbot.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/LogBot/logbot.py b/LogBot/logbot.py index 4862639..c260fb1 100644 --- a/LogBot/logbot.py +++ b/LogBot/logbot.py @@ -102,8 +102,8 @@ class Logbot(Bot): def _write_log(self, message): """Write new log to the file system.""" template = jinja2.Template(open("template.html").read()) - room_name = self._parse_room_name(message.room) - log_path = os.path.join(self.output, room_name, "index.html") + folder_name = self.db[message.room]["folder"] + log_path = os.path.join(self.output, folder_name, "index.html") with open(log_path, "w") as out: html = template.render( title=self.db[message.room]["title"], @@ -114,12 +114,12 @@ class Logbot(Bot): def _generate_feed(self, message): template = jinja2.Template(open("feed.rss").read()) - room_name = self._parse_room_name(message.room) - feed_path = os.path.join(self.output, room_name, "feed.rss") + folder_name = self.db[message.room]["folder"] + feed_path = os.path.join(self.output, folder_name, "feed.rss") date = datetime.now() with open(feed_path, "w") as out: feed = template.render( - 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/", 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") @@ -158,16 +158,18 @@ class Logbot(Bot): self.db[room]["messages"] = {} if "title" not in self.db[room]: self.db[room]["title"] = room + if "folder" not in self.db[room]: + self.db[room]["folder"] = room if "stylesheet" not in self.db[room]: - self.db[room]["stylesheet"] = room + self.db[room]["stylesheet"] = "timeline" # default stylesheet if "font" not in self.db[room]: - self.db[room]["font"] = room + 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","timeline.css") # default stylesheet + 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 }") @@ -230,6 +232,16 @@ class Logbot(Bot): self.db[message.room]["title"] = title reply = f"The title of the log is changed to: { title }" + # Response to @folder + # https://git.vvvvvvaria.org/varia/bots/issues/5 + elif "@folder" in message.text: + match = re.findall("@folder .*", message.content)[0] + newfoldername = match.replace("@folder ", "") + currentfoldername = self.db[message.room]["folder"] + os.rename(currentfoldername, newfoldername) + self.db[message.room]["folder"] = newfoldername + reply = f"The foldername of the log is changed to: { newfoldername }. The URL of the log changed into: https://vvvvvvaria.org/logs/{ newfoldername}" + # Response to @style elif "@style" in message.text: match = re.findall("@style .*", message.content)[0]