nsfw filters

This commit is contained in:
Klemek
2021-05-18 18:13:37 +02:00
parent a01414dce7
commit b2858cca95
4 changed files with 42 additions and 4 deletions
+22 -1
View File
@@ -15,6 +15,7 @@ from utils import (
RELATIVE_REGEX,
parse_time,
command_cache,
FilterLevel,
)
from logs import (
GuildLogs,
@@ -27,7 +28,7 @@ from logs import (
class Scanner(ABC):
VALID_ARGS = ["me", "here", "fast", "fresh", "mobile", "mention"]
VALID_ARGS = ["me", "here", "fast", "fresh", "mobile", "mention", "nsfw", "nsfw:allow", "nsfw:only"]
def __init__(
self,
@@ -139,6 +140,26 @@ class Scanner(ABC):
self.mention_users = "mention" in args or "mobile" in args
# nsfw filter
if "nsfw" in args or "nsfw:allow" in args:
self.nsfw = FilterLevel.ALLOW
elif "nsfw:only" in args:
self.nsfw = FilterLevel.ONLY
else:
self.nsfw = FilterLevel.NONE
# fix nsfw filter if channel specified
if not self.full and any(channel.nsfw for channel in self.channels):
self.nsfw = FilterLevel.ALLOW
elif all(channel.nsfw for channel in self.channels):
self.nsfw = FilterLevel.ONLY
# filter nsfw channels
if self.nsfw == FilterLevel.NONE:
self.channels = list(filter(lambda channel:not channel.nsfw, self.channels))
elif self.nsfw == FilterLevel.ONLY:
self.channels = list(filter(lambda channel:channel.nsfw, self.channels))
if not await self.init(message, *args):
return