diff options
| author | 2019-01-07 17:51:00 -0500 | |
|---|---|---|
| committer | 2019-01-07 17:51:00 -0500 | |
| commit | 71eac59a69b36e21efb0bcf165ad8cd41ccaa1fb (patch) | |
| tree | 11175562f7c0b77b849912ab30ddc0cbeed1f166 | |
| parent | Merge pull request #251 from python-discord/invite-filter-dm (diff) | |
Add mute infraction check to role restoration
| -rw-r--r-- | bot/cogs/events.py | 28 | 
1 files changed, 28 insertions, 0 deletions
diff --git a/bot/cogs/events.py b/bot/cogs/events.py index edfc6e579..c604169c0 100644 --- a/bot/cogs/events.py +++ b/bot/cogs/events.py @@ -25,6 +25,7 @@ class Events:      def __init__(self, bot: Bot):          self.bot = bot +        self.headers = {"X-API-KEY": Keys.site_api}      @property      def mod_log(self) -> ModLog: @@ -103,6 +104,29 @@ class Events:          resp = await response.json()          return resp["data"] +    async def has_active_mute(self, user_id: str) -> bool: +        """ +        Check whether a user has any active mute infractions +        """ +        response = await self.bot.http_session.get( +            URLs.site_infractions_user.format( +                user_id=user_id +            ), +            params={"hidden": "True"}, +            headers=self.headers +        ) +        infraction_list = await response.json() + +        # Check for active mute infractions +        if len(infraction_list) == 0: +            # Short circuit +            return False + +        muted_check = any( +            [infraction["active"] for infraction in infraction_list if infraction["type"].lower() == "mute"] +        ) +        return muted_check +      async def on_command_error(self, ctx: Context, e: CommandError):          command = ctx.command          parent = None @@ -236,6 +260,10 @@ class Events:                  for role in RESTORE_ROLES:                      if role in old_roles: +                        # Check for mute roles that were not able to be removed and skip if present +                        if role == str(Roles.muted) and not await self.has_active_mute(str(member.id)): +                            continue +                          new_roles.append(Object(int(role)))                  for role in new_roles:  |