register now checks if a player is in the database

doc_update
Joey Hines 2018-07-22 20:37:06 -05:00
parent 847e33ed6e
commit 11266bf498
3 changed files with 11 additions and 2 deletions

View File

@ -39,5 +39,7 @@ class InvalidDimError(DataBaseError):
class InvalidTunnelError(DataBaseError): class InvalidTunnelError(DataBaseError):
"""Invalid tunnel name""" """Invalid tunnel name"""
class PlayerInDB(DataBaseError):
"""Player already registered in database"""

View File

@ -21,6 +21,10 @@ class Commands:
session = self.interface.database.Session() session = self.interface.database.Session()
try: try:
try:
self.interface.find_player(session, player_name)
raise PlayerInDB
except PlayerNotFound:
player = self.interface.add_player(session, player_name, discord_uuid) player = self.interface.add_player(session, player_name, discord_uuid)
player_name = player.name player_name = player.name
finally: finally:

View File

@ -75,6 +75,9 @@ async def register(ctx):
await bot.say('{}, run this command on 24CC whoever you are'.format(ctx.message.author.mention)) await bot.say('{}, run this command on 24CC whoever you are'.format(ctx.message.author.mention))
except LocationInitError: except LocationInitError:
raise commands.UserInputError 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) @bot.command(pass_context=True)