From 11266bf4985f16b8e0b60a4869da87f3de7c9771 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sun, 22 Jul 2018 20:37:06 -0500 Subject: [PATCH] register now checks if a player is in the database --- BotErrors.py | 2 ++ Commands.py | 8 ++++++-- Geoffrey.py | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/BotErrors.py b/BotErrors.py index 23c31c7..82ca764 100644 --- a/BotErrors.py +++ b/BotErrors.py @@ -39,5 +39,7 @@ class InvalidDimError(DataBaseError): class InvalidTunnelError(DataBaseError): """Invalid tunnel name""" +class PlayerInDB(DataBaseError): + """Player already registered in database""" diff --git a/Commands.py b/Commands.py index c26baf9..9350d4f 100644 --- a/Commands.py +++ b/Commands.py @@ -21,8 +21,12 @@ class Commands: session = self.interface.database.Session() try: - player = self.interface.add_player(session, player_name, discord_uuid) - player_name = player.name + try: + self.interface.find_player(session, player_name) + raise PlayerInDB + except PlayerNotFound: + player = self.interface.add_player(session, player_name, discord_uuid) + player_name = player.name finally: session.close() diff --git a/Geoffrey.py b/Geoffrey.py index c5b8a47..6f69975 100644 --- a/Geoffrey.py +++ b/Geoffrey.py @@ -75,6 +75,9 @@ async def register(ctx): await bot.say('{}, run this command on 24CC whoever you are'.format(ctx.message.author.mention)) except LocationInitError: raise commands.UserInputError + except PlayerInDB: + await bot.say('{}, you are already in the database. Ding dong.'.format(ctx.message.author.mention)) + @bot.command(pass_context=True)