|
@ -9,6 +9,14 @@ import jinja2 |
|
|
from xbotlib import Bot |
|
|
from xbotlib import Bot |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _href_wrap(post): |
|
|
|
|
|
"""Wrap links in a tags as a Jinja template filter.""" |
|
|
|
|
|
for url in re.findall(r"http\S+", post): |
|
|
|
|
|
url_with_href = f"<a href='{url}'>{url}</a>" |
|
|
|
|
|
post.replace(url, url_with_href) |
|
|
|
|
|
return post |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Logbot(Bot): |
|
|
class Logbot(Bot): |
|
|
|
|
|
|
|
|
help = """Oh dear, logbot is here! |
|
|
help = """Oh dear, logbot is here! |
|
@ -103,7 +111,9 @@ class Logbot(Bot): |
|
|
|
|
|
|
|
|
def _write_log(self, message): |
|
|
def _write_log(self, message): |
|
|
"""Write new log to the file system.""" |
|
|
"""Write new log to the file system.""" |
|
|
template = jinja2.Template(open("template.html").read()) |
|
|
jinja_env = jinja2.Environment() |
|
|
|
|
|
jinja_env.filters["href_wrap"] = _href_wrap |
|
|
|
|
|
template = jinja_env.from_string(open("template.html").read()) |
|
|
folder_name = self.db[message.room]["folder"] |
|
|
folder_name = self.db[message.room]["folder"] |
|
|
if "@" in folder_name: # hacky |
|
|
if "@" in folder_name: # hacky |
|
|
folder_name = self._parse_room_name(folder_name) |
|
|
folder_name = self._parse_room_name(folder_name) |
|
@ -147,9 +157,6 @@ class Logbot(Bot): |
|
|
self.db[message.room]["messages"][new_key] = media_post |
|
|
self.db[message.room]["messages"][new_key] = media_post |
|
|
else: |
|
|
else: |
|
|
post = message.content.replace("@add ", "") |
|
|
post = message.content.replace("@add ", "") |
|
|
for url in re.findall(r"http\S+", post): |
|
|
|
|
|
url_with_href = f"<a href='{url}'>{url}</a>" |
|
|
|
|
|
post.replace(url, url_with_href) |
|
|
|
|
|
self.db[message.room]["messages"][new_key] = post |
|
|
self.db[message.room]["messages"][new_key] = post |
|
|
self.db._dumps() |
|
|
self.db._dumps() |
|
|
|
|
|
|
|
|