blacken url module

This commit is contained in:
Tatu Wikman 2020-10-10 20:19:30 +03:00
parent 4bad8fe66d
commit 8187bb5478
No known key found for this signature in database
GPG Key ID: BF214F789950B74E
1 changed files with 13 additions and 16 deletions

View File

@ -54,8 +54,8 @@ class MatrixModule(BotModule):
return
# skip edited content to prevent spamming the same thing multiple times
if('content' in event.source):
if('m.new_content' in event.source['content']):
if "content" in event.source:
if "m.new_content" in event.source["content"]:
self.logger.debug(f"Skipping edited event to prevent spam")
return
@ -78,11 +78,10 @@ class MatrixModule(BotModule):
# fix for #98 a bit ugly, but skip all matrix.to urls
# those are 99.99% pills and should not
# spam the channel with matrix.to titles
if(url.startswith("https://matrix.to/#/")):
if url.startswith("https://matrix.to/#/"):
self.logger.debug(f"Skipping matrix.to url (#98): {url}")
continue
try:
title, description = self.get_content_from_url(url)
except Exception as e:
@ -123,7 +122,9 @@ class MatrixModule(BotModule):
return (title, description)
if r.status_code != 200:
self.logger.warning(f"Failed fetching url {url}. Status code: {r.status_code}")
self.logger.warning(
f"Failed fetching url {url}. Status code: {r.status_code}"
)
return (title, description)
# try parse and get the title
@ -145,8 +146,8 @@ class MatrixModule(BotModule):
# Issue 63 patch - Title should not contain newlines or tabs
if title is not None:
assert isinstance(title, str)
title = title.replace('\n', '')
title = title.replace('\t', '')
title = title.replace("\n", "")
title = title.replace("\t", "")
return (title, description)
async def matrix_message(self, bot, room, event):
@ -179,9 +180,7 @@ class MatrixModule(BotModule):
bot.must_be_owner(event)
self.type = "m.notice"
bot.save_settings()
await bot.send_text(
room, "Sending titles as notices from now on."
)
await bot.send_text(room, "Sending titles as notices from now on.")
return
# show status
@ -189,9 +188,7 @@ class MatrixModule(BotModule):
bot.must_be_owner(event)
self.type = "m.text"
bot.save_settings()
await bot.send_text(
room, "Sending titles as text from now on."
)
await bot.send_text(room, "Sending titles as text from now on.")
return
# invalid command
@ -204,8 +201,8 @@ class MatrixModule(BotModule):
def get_settings(self):
data = super().get_settings()
data['status'] = self.status
data['type'] = self.type
data["status"] = self.status
data["type"] = self.type
return data
def set_settings(self, data):