diff options
| author | 2018-07-25 23:54:07 +0200 | |
|---|---|---|
| committer | 2018-07-25 23:54:07 +0200 | |
| commit | 17113bfd26d7d64f8ac3310e61baac18a7f26454 (patch) | |
| tree | 048d0121fe6193df67b0619c002f3ad88e8a9cb4 | |
| parent | Adding all the constants to the dataclass. (diff) | |
Created the Filtering cog and implemented a filter for zalgo.
| -rw-r--r-- | bot/cogs/filtering.py | 34 | ||||
| -rw-r--r-- | bot/constants.py | 8 | ||||
| -rw-r--r-- | config-default.yml | 9 |
3 files changed, 43 insertions, 8 deletions
diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py new file mode 100644 index 000000000..ccd270924 --- /dev/null +++ b/bot/cogs/filtering.py @@ -0,0 +1,34 @@ +import logging +import re + +from discord import Message +from discord.ext.commands import Bot + +log = logging.getLogger(__name__) + + +class Filtering: + """ + Filtering out invites, blacklisting domains, + and preventing certain expressions""" + + def __init__(self, bot: Bot): + self.bot = bot + + async def on_message(self, msg: Message): + self._filter_zalgo(msg.content) + + @staticmethod + async def _has_zalgo(text): + """ + Returns True if the text contains zalgo characters. + + Zalgo range is \u0300 – \u036F and \u0489. + """ + + return bool(re.search(r"[\u0300-\u036F\u0489]", text)) + + +def setup(bot: Bot): + bot.add_cog(Filtering(bot)) + log.info("Cog loaded: Filtering") diff --git a/bot/constants.py b/bot/constants.py index 3cb9849aa..2abdcfca9 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -191,16 +191,16 @@ class Bot(metaclass=YAMLGetter): token: str -class Censor(metaclass=YAMLGetter): - section = "censor" +class Filtering(metaclass=YAMLGetter): + section = "filtering" filter_zalgo: bool filter_invites: bool filter_domain: bool - filter_expression: bool + watch_expressions: bool domain_blacklist: List[str] - blocked_expressions: List[str] + watched_expressions: List[str] guild_invite_whitelist: List[str] channel_whitelist: List[int] diff --git a/config-default.yml b/config-default.yml index ce2600c61..cf42568e5 100644 --- a/config-default.yml +++ b/config-default.yml @@ -81,18 +81,19 @@ guild: helpers: 267630620367257601 -censor: +filtering: + # What do we filter? filter_zalgo: true filter_invites: true filter_domains: true - filter_expression: true + watch_expressions: true # Filter configuration domain_blacklist: - pornhub.com - blocked_expressions: + watched_expressions: - .*ni[g]*er.* guild_invite_whitelist: @@ -109,7 +110,7 @@ censor: - *DEVLOG - *BBLOGS - *STAFF_LOUNGE -# - *DEVTEST + - *DEVTEST role_whitelist: - *ADMIN_ROLE |