spoiler filtering

This commit is contained in:
Klemek
2021-05-19 15:11:29 +02:00
parent da5e3fdb35
commit a8b1ede962
6 changed files with 69 additions and 10 deletions
+19
View File
@@ -100,6 +100,25 @@ class FakeMessage:
self.id = id
def is_image_spoiler(message: discord.Message) -> bool:
if len(message.attachments) > 0:
return message.attachments[0].is_spoiler()
elif len(message.embeds) > 0:
return re.match(r"||[^|]*http[^|]||", message.content.lower()) is not None
else:
return False
def should_allow_spoiler(message: discord.Message, spoiler: FilterLevel) -> bool:
is_spoiler = is_image_spoiler(message)
return (
not is_spoiler
and spoiler <= FilterLevel.ALLOW
or is_spoiler
and spoiler >= FilterLevel.ALLOW
)
# FILE