aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-07-23 12:55:03 +0000
committerGravatar Gareth Coles <[email protected]>2018-07-23 12:55:03 +0000
commitd7e0d530514f832b873fcbc00b7b133edeb0ddc6 (patch)
tree2ff249fd5a07fbc4f457782e474c17db17c3d862
parent[Modlog] Suppress channel position changes (diff)
parentRemove banned users from BigBrother's prying eyes. (diff)
Merge branch 'enhancement/detect-bans-in-bigbrother-cog' into 'master'
Remove banned users from BigBrother's prying eyes. See merge request python-discord/projects/bot!34
-rw-r--r--bot/cogs/bigbrother.py27
1 files changed, 24 insertions, 3 deletions
diff --git a/bot/cogs/bigbrother.py b/bot/cogs/bigbrother.py
index ef7a62853..4d0996122 100644
--- a/bot/cogs/bigbrother.py
+++ b/bot/cogs/bigbrother.py
@@ -1,10 +1,10 @@
import logging
-from typing import List
+from typing import List, Union
-from discord import Color, Embed, Message, TextChannel, User
+from discord import Color, Embed, Guild, Member, Message, TextChannel, User
from discord.ext.commands import Bot, Context, command
-from bot.constants import Channels, Emojis, Keys, Roles, URLs
+from bot.constants import Channels, Emojis, Guild as GuildConfig, Keys, Roles, URLs
from bot.decorators import with_role
from bot.pagination import LinePaginator
@@ -48,6 +48,27 @@ class BigBrother:
data = await response.json()
self.update_cache(data)
+ async def on_member_ban(self, guild: Guild, user: Union[User, Member]):
+ if guild.id == GuildConfig.id and user.id in self.watched_users:
+ url = f"{URLs.site_bigbrother_api}?user_id={user.id}"
+ channel = self.watched_users[user.id]
+
+ async with self.bot.http_session.delete(url, headers=self.HEADERS) as response:
+ del self.watched_users[user.id]
+ if response.status == 204:
+ await channel.send(
+ f"{Emojis.lemoneye2}:hammer: {user} got banned, so "
+ f"`BigBrother` will no longer relay their messages to {channel}"
+ )
+
+ else:
+ data = await response.json()
+ reason = data.get('error_message', "no message provided")
+ await channel.send(
+ f"{Emojis.lemoneye2}:x: {user} got banned, but trying to remove them from"
+ f"BigBrother's user dictionary on the API returned an error: {reason}"
+ )
+
async def on_message(self, msg: Message):
if msg.author.id in self.watched_users:
channel = self.watched_users[msg.author.id]