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.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)

View File

@ -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),