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)