Added better error checking for find_player and add_player
parent
57ec4830cf
commit
3026b240f4
|
@ -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()
|
||||||
|
|
|
@ -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:
|
||||||
await ctx.send('Username: {}, id: {}, Discord UUID: {}, Minecraft UUID: {}'
|
db_id, username, discord_uuid, minecraft_uuid = self.bot.bot_commands.find_player(discord_uuid)
|
||||||
.format(username, id, discord_uuid, minecraft_uuid))
|
await ctx.send('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):
|
||||||
|
|
Loading…
Reference in New Issue