diff options
| author | 2020-10-06 00:15:20 +0100 | |
|---|---|---|
| committer | 2020-10-06 00:15:20 +0100 | |
| commit | 233f63551bf1945d83f0418e506f9ec9a9381ac6 (patch) | |
| tree | 947d89850f78fb0bcc040f11ffba7ffc165f757b | |
| parent | Merge pull request #1211 from python-discord/Den4200/fix/rules (diff) | |
Support users with alternate gating methods
| -rw-r--r-- | bot/exts/moderation/verification.py | 42 | 
1 files changed, 42 insertions, 0 deletions
| diff --git a/bot/exts/moderation/verification.py b/bot/exts/moderation/verification.py index 206556483..1d1dacb37 100644 --- a/bot/exts/moderation/verification.py +++ b/bot/exts/moderation/verification.py @@ -53,6 +53,23 @@ If you'd like to unsubscribe from the announcement notifications, simply send `!  <#{constants.Channels.bot_commands}>.  """ +ALTERNATE_VERIFIED_MESSAGE = f""" +Thanks for accepting our rules! + +You can find a copy of our rules for reference at <https://pythondiscord.com/pages/rules>. + +Additionally, if you'd like to receive notifications for the announcements \ +we post in <#{constants.Channels.announcements}> +from time to time, you can send `!subscribe` to <#{constants.Channels.bot_commands}> at any time \ +to assign yourself the **Announcements** role. We'll mention this role every time we make an announcement. + +If you'd like to unsubscribe from the announcement notifications, simply send `!unsubscribe` to \ +<#{constants.Channels.bot_commands}>. + +To introduce you to our community, we've made the following video: +https://youtu.be/ZH26PuX3re0 +""" +  # Sent via DMs to users kicked for failing to verify  KICKED_MESSAGE = f"""  Hi! You have been automatically kicked from Python Discord as you have failed to accept our rules \ @@ -156,6 +173,9 @@ class Verification(Cog):      # ]      task_cache = RedisCache() +    # Cache who needs to receive an alternate verified DM. +    member_gating_cache = RedisCache() +      def __init__(self, bot: Bot) -> None:          """Start internal tasks."""          self.bot = bot @@ -519,6 +539,13 @@ class Verification(Cog):          if member.guild.id != constants.Guild.id:              return  # Only listen for PyDis events +        raw_member = await self.bot.http.get_member(member.guild.id, member.id) + +        # Only send the message to users going through our gating system +        if raw_member["is_pending"]: +            await self.member_gating_cache.set(raw_member.id, True) +            return +          log.trace(f"Sending on join message to new member: {member.id}")          try:              await safe_dm(member.send(ON_JOIN_MESSAGE)) @@ -526,6 +553,21 @@ class Verification(Cog):              log.exception("DM dispatch failed on unexpected error code")      @Cog.listener() +    async def on_member_update(self, before: discord.Member, after: discord.Member): +        """Check if we need to send a verification DM to a gated user.""" +        before_roles = [r.id for r in before.roles] +        after_roles = [r.id for r in after.roles] + +        if constants.Roles.verified not in before_roles and constants.Roles.verified in after_roles: +            if await self.member_gating_cache.get(after.id): +                try: +                    await safe_dm(after.send(ALTERNATE_VERIFIED_MESSAGE)) +                except discord.HTTPException: +                    log.exception("DM dispatch failed on unexpected error code") +                finally: +                    self.member_gating_cache.pop(after.id) + +    @Cog.listener()      async def on_message(self, message: discord.Message) -> None:          """Check new message event for messages to the checkpoint channel & process."""          if message.channel.id != constants.Channels.verification: | 
