Fix handling discord user ban

This commit is contained in:
Jeremy Zhang 2018-03-24 08:02:03 +00:00
parent 05697402df
commit 930c026108
2 changed files with 14 additions and 8 deletions

View File

@ -180,10 +180,10 @@ class Titan(discord.AutoShardedClient):
await self.database.update_guild_member(memberafter) await self.database.update_guild_member(memberafter)
await self.socketio.on_guild_member_update(memberafter) await self.socketio.on_guild_member_update(memberafter)
async def on_member_ban(self, member): async def on_member_ban(self, guild, user):
if self.user.id == member.id: if self.user.id == user.id:
return 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): async def on_member_unban(self, guild, user):
await self.database.unban_server_user(user, guild) await self.database.unban_server_user(user, guild)

View File

@ -158,13 +158,19 @@ class DatabaseInterface(object):
session.delete(gui) session.delete(gui)
session.commit() 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(): async with threadpool():
with self.get_session() as session: with self.get_session() as session:
dbmember = session.query(GuildMembers) \ if guild:
.filter(GuildMembers.guild_id == int(member.guild.id)) \ dbmember = session.query(GuildMembers) \
.filter(GuildMembers.user_id == int(member.id)) \ .filter(GuildMembers.guild_id == int(guild.id)) \
.order_by(GuildMembers.id).all() .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: if not dbmember:
dbmember = GuildMembers( dbmember = GuildMembers(
int(member.guild.id), int(member.guild.id),