From 930c0261086dcdf305d4b6804fcd49c59fa4ef44 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Sat, 24 Mar 2018 08:02:03 +0000 Subject: [PATCH] Fix handling discord user ban --- discordbot/titanembeds/bot.py | 6 +++--- discordbot/titanembeds/database/__init__.py | 16 +++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/discordbot/titanembeds/bot.py b/discordbot/titanembeds/bot.py index dc8d71a..047c952 100644 --- a/discordbot/titanembeds/bot.py +++ b/discordbot/titanembeds/bot.py @@ -180,10 +180,10 @@ class Titan(discord.AutoShardedClient): await self.database.update_guild_member(memberafter) await self.socketio.on_guild_member_update(memberafter) - async def on_member_ban(self, member): - if self.user.id == member.id: + async def on_member_ban(self, guild, user): + if self.user.id == user.id: return - await self.database.update_guild_member(member, active=False, banned=True) + await self.database.update_guild_member(user, active=False, banned=True, guild=guild) async def on_member_unban(self, guild, user): await self.database.unban_server_user(user, guild) diff --git a/discordbot/titanembeds/database/__init__.py b/discordbot/titanembeds/database/__init__.py index 659e127..353588a 100644 --- a/discordbot/titanembeds/database/__init__.py +++ b/discordbot/titanembeds/database/__init__.py @@ -158,13 +158,19 @@ class DatabaseInterface(object): session.delete(gui) session.commit() - async def update_guild_member(self, member, active=True, banned=False): + async def update_guild_member(self, member, active=True, banned=False, guild=None): async with threadpool(): with self.get_session() as session: - dbmember = session.query(GuildMembers) \ - .filter(GuildMembers.guild_id == int(member.guild.id)) \ - .filter(GuildMembers.user_id == int(member.id)) \ - .order_by(GuildMembers.id).all() + if guild: + dbmember = session.query(GuildMembers) \ + .filter(GuildMembers.guild_id == int(guild.id)) \ + .filter(GuildMembers.user_id == int(member.id)) \ + .order_by(GuildMembers.id).all() + else: + dbmember = session.query(GuildMembers) \ + .filter(GuildMembers.guild_id == int(member.guild.id)) \ + .filter(GuildMembers.user_id == int(member.id)) \ + .order_by(GuildMembers.id).all() if not dbmember: dbmember = GuildMembers( int(member.guild.id),