diff options
| author | 2019-01-12 18:14:00 +0100 | |
|---|---|---|
| committer | 2019-01-12 18:14:00 +0100 | |
| commit | f7c33a5817598359964731702a1c2d19753ab12c (patch) | |
| tree | 2d19963fd63acc7d052bdd7e7eed761bfadea3a0 | |
| parent | Merge branch 'master' into bigbrother-add-watch-message-to-header-embed (diff) | |
| parent | Merge pull request #269 from python-discord/disable-rich-embed-filter (diff) | |
Merge branch 'master' into bigbrother-add-watch-message-to-header-embed
| -rw-r--r-- | bot/cogs/events.py | 32 | ||||
| -rw-r--r-- | bot/cogs/token_remover.py | 5 | ||||
| -rw-r--r-- | config-default.yml | 2 |
3 files changed, 36 insertions, 3 deletions
diff --git a/bot/cogs/events.py b/bot/cogs/events.py index edfc6e579..f0baecd4b 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 not infraction_list: + # Short circuit + return False + + return any( + infraction["active"] for infraction in infraction_list if infraction["type"].lower() == "mute" + ) + async def on_command_error(self, ctx: Context, e: CommandError): command = ctx.command parent = None @@ -236,6 +260,14 @@ 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)): + log.debug( + f"User {member.id} has no active mute infraction, " + "their leftover muted role will not be persisted" + ) + continue + new_roles.append(Object(int(role))) for role in new_roles: diff --git a/bot/cogs/token_remover.py b/bot/cogs/token_remover.py index 8277513a7..c1a0e18ba 100644 --- a/bot/cogs/token_remover.py +++ b/bot/cogs/token_remover.py @@ -16,8 +16,9 @@ log = logging.getLogger(__name__) DELETION_MESSAGE_TEMPLATE = ( "Hey {mention}! I noticed you posted a seemingly valid Discord API " - "token in your message and have removed your message to prevent abuse. " - "We recommend regenerating your token regardless, which you can do here: " + "token in your message and have removed your message. " + "We **strongly recommend** regenerating your token as it's probably " + "been compromised. You can do that here: " "<https://discordapp.com/developers/applications/me>\n" "Feel free to re-post it with the token removed. " "If you believe this was a mistake, please let us know!" diff --git a/config-default.yml b/config-default.yml index 1a5a63c6a..4cc2ff5d5 100644 --- a/config-default.yml +++ b/config-default.yml @@ -137,7 +137,7 @@ filter: filter_zalgo: false filter_invites: true filter_domains: true - filter_rich_embeds: true + filter_rich_embeds: false watch_words: true watch_tokens: true |