From 03f5c87334758da51ae266eadb4e49ca530069be Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Mon, 10 Dec 2018 12:44:31 -0600 Subject: [PATCH] Added a check to register to check for username changes and if the player is banned If the username is not found in the applications, players is queried to find a matching player is_banned property is now checked before adding them to the server --- api/bot.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/api/bot.py b/api/bot.py index df6a1e3..9275d34 100644 --- a/api/bot.py +++ b/api/bot.py @@ -64,22 +64,31 @@ class Discord(discord.Client): search = match.group(1) count = Application.objects.filter(username__iexact=search, accepted__exact=True).count() + if count == 0: + count = Player.objects.filter(username__iexact=search, application__accepted__exact=True).count() + if count > 0: if count == 1: - player = Application.objects.filter(username__iexact=search, accepted__exact=True).all().values()[0] - nickname = player["username"] + player = Player.objects.filter(username__iexact=search, application__accepted__exact=True).all()[0] + nickname = player.username - role = discord.utils.get(message.server.roles, name=self.member_role) - msg = "Successfully added {0} as a {1}.".format(nickname, self.member_role) + if not player.is_banned: + role = discord.utils.get(message.server.roles, name=self.member_role) + msg = "Successfully added {0} as a {1}.".format(nickname, self.member_role) - yield from self.change_nickname(message.author, nickname) - yield from self.add_roles(message.author, role) - yield from self.discord_message(message.channel, msg) + yield from self.change_nickname(message.author, nickname) + yield from self.add_roles(message.author, role) + yield from self.discord_message(message.channel, msg) + else: + msg = "{0} You are currently banned, appeal on the subreddit.".format(message.author.mention) + + yield from self.discord_message(message.channel, msg) return else: msg = "An application for {0} could not be found, please apply first.".format(search) yield from self.discord_message(message.channel, msg) + return # IF MEMBER IS NOT AUTHORIZED, IGNORE if not any(role in self.auth_roles for role in member_roles):