Added better error checking for find_player and add_player

doc_update
Joey Hines 2018-09-21 07:27:32 -05:00
parent 57ec4830cf
commit 3026b240f4
2 changed files with 15 additions and 9 deletions

View File

@ -377,18 +377,18 @@ class Commands:
try: try:
self.interface.find_player_by_discord_uuid(session, discord_uuid) self.interface.find_player_by_discord_uuid(session, discord_uuid)
out = "is already in database." raise PlayerInDBError
except PlayerNotFound: except PlayerNotFound:
player = Player(mc_name, discord_id=discord_uuid) player = Player(mc_name, discord_id=discord_uuid)
self.interface.database.add_object(session, player) self.interface.database.add_object(session, player)
player = self.interface.find_player_by_discord_uuid(session, discord_uuid) player = self.interface.find_player_by_discord_uuid(session, discord_uuid)
out = "has been added to the database with id {}".format(player.id) id = player.id
finally: finally:
session.close() session.close()
return out return id
def find_player(self, discord_uuid): def find_player(self, discord_uuid):
session = self.interface.database.Session() session = self.interface.database.Session()

View File

@ -134,9 +134,12 @@ class Admin_Commands:
""" """
Manually add a player to the database Manually add a player to the database
""" """
str = self.bot.bot_commands.add_player(discord_uuid, mc_name) try:
await ctx.send('{}, user **{}** {}.' db_id = self.bot.bot_commands.add_player(discord_uuid, mc_name)
.format(ctx.message.author.mention, mc_name, str)) await ctx.send('{}, user **{}** been added to the data base with id {}.'.format(ctx.message.author.mention,
mc_name, db_id))
except PlayerInDBError:
await ctx.send('{}, user **{}** is already in the database.'.format(ctx.message.author.mention, mc_name))
@add_player.error @add_player.error
async def add_player_error(self, ctx, error): async def add_player_error(self, ctx, error):
@ -147,9 +150,12 @@ class Admin_Commands:
""" """
Finds a player in the database Finds a player in the database
""" """
id, username, discord_uuid, minecraft_uuid = self.bot.bot_commands.find_player(discord_uuid) try:
db_id, username, discord_uuid, minecraft_uuid = self.bot.bot_commands.find_player(discord_uuid)
await ctx.send('Username: {}, id: {}, Discord UUID: {}, Minecraft UUID: {}' await ctx.send('Username: {}, id: {}, Discord UUID: {}, Minecraft UUID: {}'
.format(username, id, discord_uuid, minecraft_uuid)) .format(username, db_id, discord_uuid, minecraft_uuid))
except PlayerNotFound:
await ctx.send('That player is not in the database...')
@find_player.error @find_player.error
async def find_player_error(self, ctx, error): async def find_player_error(self, ctx, error):