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