url module: don't spam matrix.to urls and skip edited messages, fixes #98
Also change a few log levels and skip edited messages completely
This commit is contained in:
parent
a87b8b5934
commit
4bad8fe66d
|
@ -53,6 +53,12 @@ class MatrixModule(BotModule):
|
|||
if len(event.body) < 1:
|
||||
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']):
|
||||
self.logger.debug(f"Skipping edited event to prevent spam")
|
||||
return
|
||||
|
||||
# are we on in this room?
|
||||
status = self.status.get(room.room_id, "OFF")
|
||||
if status not in self.STATUSES:
|
||||
|
@ -69,10 +75,18 @@ class MatrixModule(BotModule):
|
|||
|
||||
# fetch the urls and if we can see a title spit it out
|
||||
for url in urls:
|
||||
# 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/#/")):
|
||||
self.logger.debug(f"Skipping matrix.to url (#98): {url}")
|
||||
continue
|
||||
|
||||
|
||||
try:
|
||||
title, description = self.get_content_from_url(url)
|
||||
except Exception as e:
|
||||
self.logger.info(f"could not fetch url: {e}")
|
||||
self.logger.warning(f"could not fetch url: {e}")
|
||||
# failed fetching, give up
|
||||
continue
|
||||
|
||||
|
@ -105,11 +119,11 @@ class MatrixModule(BotModule):
|
|||
try:
|
||||
r = httpx.get(url, timeout=timeout)
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed fetching url {url}. Error: {e}")
|
||||
self.logger.warning(f"Failed fetching url {url}. Error: {e}")
|
||||
return (title, description)
|
||||
|
||||
if r.status_code != 200:
|
||||
self.logger.info(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
|
||||
|
@ -125,7 +139,7 @@ class MatrixModule(BotModule):
|
|||
if descr_tag:
|
||||
description = descr_tag.get("content", None)
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed parsing response from url {url}. Error: {e}")
|
||||
self.logger.warning(f"Failed parsing response from url {url}. Error: {e}")
|
||||
return (title, description)
|
||||
|
||||
# Issue 63 patch - Title should not contain newlines or tabs
|
||||
|
|
Loading…
Reference in New Issue