Made the add_player() function is DatabaseInterface more robust.

doc_update
Joey Hines 2018-09-27 11:25:32 -05:00
parent 20ebd0bc62
commit 43743d59f5
1 changed files with 8 additions and 3 deletions

View File

@ -53,8 +53,13 @@ class DatabaseInterface:
def add_player(self, session, player_name, discord_uuid=None): def add_player(self, session, player_name, discord_uuid=None):
try: try:
self.find_player(session, player_name) player = self.find_player(session, player_name)
if (discord_uuid is not None) and (discord_uuid == player.discord_uuid):
raise PlayerInDBError raise PlayerInDBError
else:
raise PlayerNotFound
except PlayerNotFound: except PlayerNotFound:
mc_uuid = grab_UUID(player_name) mc_uuid = grab_UUID(player_name)
try: try:
@ -145,7 +150,7 @@ class DatabaseInterface:
return self.database.query_by_filter(session, ItemListing, expr, limit=5, sort=ItemListing.normalized_price) return self.database.query_by_filter(session, ItemListing, expr, limit=5, sort=ItemListing.normalized_price)
def find_player(self, session, player_name): def find_player(self, session, player_name):
expr = Player.name.ilike(player_name) expr = func.lower(Player.name) == func.lower(player_name)
try: try:
player = self.database.query_by_filter(session, Player, expr)[0] player = self.database.query_by_filter(session, Player, expr)[0]