From c42f80871566f08e5358795953f0406e66353749 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Tue, 26 Sep 2017 03:52:46 +0000 Subject: [PATCH] Guild member duplicate checking in the database --- discordbot/titanembeds/database/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/discordbot/titanembeds/database/__init__.py b/discordbot/titanembeds/database/__init__.py index fe4ef23..aa30e16 100644 --- a/discordbot/titanembeds/database/__init__.py +++ b/discordbot/titanembeds/database/__init__.py @@ -158,7 +158,8 @@ class DatabaseInterface(object): with self.get_session() as session: dbmember = session.query(GuildMembers) \ .filter(GuildMembers.guild_id == member.server.id) \ - .filter(GuildMembers.user_id == member.id).first() + .filter(GuildMembers.user_id == member.id) \ + .order_by(GuildMembers.id).all() if not dbmember: dbmember = GuildMembers( member.server.id, @@ -173,6 +174,10 @@ class DatabaseInterface(object): ) session.add(dbmember) else: + if len(dbmember) > 1: + for mem in dbmember[1:]: + session.delete(mem) + dbmember = dbmember[0] dbmember.banned = banned dbmember.active = active dbmember.username = member.name