diff options
| -rw-r--r-- | bot/cogs/filtering.py | 42 | ||||
| -rw-r--r-- | bot/constants.py | 73 | ||||
| -rw-r--r-- | config-default.yml | 102 | 
3 files changed, 157 insertions, 60 deletions
| diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py new file mode 100644 index 000000000..23b0d9e96 --- /dev/null +++ b/bot/cogs/filtering.py @@ -0,0 +1,42 @@ +import logging +import re + +from discord import Message +from discord.ext.commands import Bot + +from bot.constants import Channels + +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): + +        has_zalgo = await self._filter_zalgo(msg.content) + +        if has_zalgo: +            self.bot.get_channel(Channels.modlog).send( +                content="ZALGO!" +            ) + +    @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 adfd5d014..834c14fd8 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -191,6 +191,51 @@ class Bot(metaclass=YAMLGetter):      token: str +class Filtering(metaclass=YAMLGetter): +    section = "filtering" + +    filter_zalgo: bool +    filter_invites: bool +    filter_domain: bool +    watch_expressions: bool + +    domain_blacklist: List[str] +    watched_expressions: List[str] +    guild_invite_whitelist: List[str] + +    channel_whitelist: List[int] +    role_whitelist: List[int] + + +class Channels(metaclass=YAMLGetter): +    section = "guild" +    subsection = "channels" + +    admins: int +    announcements: int +    big_brother_logs: int +    bot: int +    checkpoint_test: int +    devalerts: int +    devlog: int +    devtest: int +    help_0: int +    help_1: int +    help_2: int +    help_3: int +    help_4: int +    help_5: int +    helpers: int +    message_log: int +    modlog: int +    off_topic_1: int +    off_topic_2: int +    off_topic_3: int +    python: int +    staff_lounge: int +    verification: int + +  class Cooldowns(metaclass=YAMLGetter):      section = "bot"      subsection = "cooldowns" @@ -245,34 +290,6 @@ class Icons(metaclass=YAMLGetter):      user_update: str -class Channels(metaclass=YAMLGetter): -    section = "guild" -    subsection = "channels" - -    admins: int -    announcements: int -    big_brother_logs: int -    bot: int -    checkpoint_test: int -    devalerts: int -    devlog: int -    devtest: int -    help_0: int -    help_1: int -    help_2: int -    help_3: int -    help_4: int -    help_5: int -    helpers: int -    message_log: int -    modlog: int -    off_topic_1: int -    off_topic_2: int -    off_topic_3: int -    python: int -    verification: int - -  class Roles(metaclass=YAMLGetter):      section = "guild"      subsection = "roles" diff --git a/config-default.yml b/config-default.yml index 84fa86a75..eeeb5fb34 100644 --- a/config-default.yml +++ b/config-default.yml @@ -51,42 +51,80 @@ guild:      id: 267624335836053506      channels: -        admins:          &ADMINS      365960823622991872 -        announcements:                354619224620138496 -        big_brother_logs:             468507907357409333 -        bot:                          267659945086812160 -        checkpoint_test:              422077681434099723 -        devalerts:                    460181980097675264 -        devlog:                       409308876241108992 -        devtest:                      414574275865870337 -        help_0:                       303906576991780866 -        help_1:                       303906556754395136 -        help_2:                       303906514266226689 -        help_3:                       439702951246692352 -        help_4:                       451312046647148554 -        help_5:                       454941769734422538 -        helpers:                      385474242440986624 -        message_log:     &MESSAGE_LOG 467752170159079424 -        modlog:          &MODLOG      282638479504965634 -        off_topic_0:                  291284109232308226 -        off_topic_1:                  463035241142026251 -        off_topic_2:                  463035268514185226 -        python:                       267624335836053506 -        verification:                 352442727016693763 +        admins:            &ADMINS        365960823622991872 +        announcements:                    354619224620138496 +        big_brother_logs:  &BBLOGS        468507907357409333 +        bot:                              267659945086812160 +        checkpoint_test:                  422077681434099723 +        devalerts:                        460181980097675264 +        devlog:            &DEVLOG        409308876241108992 +        devtest:           &DEVTEST       414574275865870337 +        help_0:                           303906576991780866 +        help_1:                           303906556754395136 +        help_2:                           303906514266226689 +        help_3:                           439702951246692352 +        help_4:                           451312046647148554 +        help_5:                           454941769734422538 +        helpers:                          385474242440986624 +        message_log:       &MESSAGE_LOG   467752170159079424 +        modlog:            &MODLOG        282638479504965634 +        off_topic_0:                      291284109232308226 +        off_topic_1:                      463035241142026251 +        off_topic_2:                      463035268514185226 +        python:                           267624335836053506 +        staff_lounge:      &STAFF_LOUNGE  464905259261755392 +        verification:                     352442727016693763      ignored: [*ADMINS, *MESSAGE_LOG, *MODLOG]      roles: -        admin: 267628507062992896 -        announcements: 463658397560995840 -        champion: 430492892331769857 -        contributor: 295488872404484098 -        devops: 409416496733880320 -        jammer: 423054537079783434 -        moderator: 267629731250176001 -        owner: 267627879762755584 -        verified: 352427296948486144 -        helpers: 267630620367257601 +        admin:             &ADMIN_ROLE    267628507062992896 +        announcements:                    463658397560995840 +        champion:                         430492892331769857 +        contributor:                      295488872404484098 +        devops:                           409416496733880320 +        jammer:                           423054537079783434 +        moderator:         &MOD_ROLE      267629731250176001 +        owner:             &OWNER_ROLE    267627879762755584 +        verified:                         352427296948486144 +        helpers:                          267630620367257601 + + +filtering: + +    # What do we filter? +    filter_zalgo:      true +    filter_invites:    true +    filter_domains:    true +    watch_expressions: true + +    # Filter configuration +    domain_blacklist: +        - pornhub.com + +    watched_expressions: +        - .*ni[g]*er.* + +    guild_invite_whitelist: +        - vywQPxd            # Code Monkeys +        - kWJYurV            # Functional Programming +        - 010z0Kw1A9ql5c1Qe  # Programming: Meme Edition +        - XBGetGp            # STEM + +    # Censor doesn't apply to these +    channel_whitelist: +        - *ADMINS +        - *MODLOG +        - *MESSAGE_LOG +        - *DEVLOG +        - *BBLOGS +        - *STAFF_LOUNGE +        - *DEVTEST + +    role_whitelist: +        - *ADMIN_ROLE +        - *MOD_ROLE +        - *OWNER_ROLE  keys: | 
