From 87ca99f1467ad23691169d01dd44fd133cc3322c Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sun, 29 Jul 2018 10:50:24 -0500 Subject: [PATCH] Fixed formating in ?find and ?tunnel --- DatabaseInterface.py | 26 ++++++++++++++++---------- DatabaseModels.py | 7 ++++++- Geoffrey.py | 4 ++-- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/DatabaseInterface.py b/DatabaseInterface.py index 36126f7..ae006f9 100644 --- a/DatabaseInterface.py +++ b/DatabaseInterface.py @@ -146,16 +146,20 @@ class DatabaseInterface: return player def search_all_fields(self, session, search): - loc_string = '\n**Locations:**' - count = 0 + loc_string = '' limit = 10 - expr = Location.owner.has(Player.name.ilike('%{}%'.format(search))) | Location.name.ilike('%{}%'.format(search)) - for loc in self.database.query_by_filter(session, Location, expr, limit=limit): - loc_string = "{}\n{}".format(loc_string, loc) - count += 1 - if count == limit: - loc_string = loc_string + '\n**. . .**' + expr = Location.owner.has(Player.name.ilike('%{}%'.format(search))) | Location.name.ilike('%{}%'.format(search)) + locations = self.database.query_by_filter(session, Location, expr, limit=limit) + + if len(locations) > 0: + loc_string = loc_string + '\n**Locations:**' + + for loc in locations: + loc_string = "{}\n{}".format(loc_string, loc) + + if len(locations) == limit: + loc_string = loc_string + '\n**. . .**' expr = Tunnel.owner.has(Player.name.ilike('%{}%'.format(search))) & Tunnel.location == None tunnels = self.database.query_by_filter(session, Tunnel, expr) @@ -164,9 +168,11 @@ class DatabaseInterface: loc_string = loc_string + '\n\n**Tunnels:**' for tunnel in tunnels: loc_string = "{}\n{}".format(loc_string, tunnel.full_str()) - count += 1 - if count == 0: + if len(tunnels) == limit: + loc_string = loc_string + '\n**. . .**' + + if len(tunnels) + len(locations) == 0: raise LocationLookUpError else: return loc_string diff --git a/DatabaseModels.py b/DatabaseModels.py index b354343..62fbf69 100644 --- a/DatabaseModels.py +++ b/DatabaseModels.py @@ -157,7 +157,12 @@ class Tunnel(SQL_Base): raise TunnelInitError def full_str(self): - return 'Owner: **{}** Tunnel: **{}**'.format(self.owner.name, self.__str__()) + if self.location is None: + string = 'Tunnel: **{}**'.format(self.__str__()) + else: + string = 'Location: **{}** Tunnel: **{}**'.format(self.location.name, self.__str__()) + + return string def __str__(self): return '{} {}'.format(self.tunnel_direction.value.title(), self.tunnel_number) diff --git a/Geoffrey.py b/Geoffrey.py index cb14f99..84e361b 100644 --- a/Geoffrey.py +++ b/Geoffrey.py @@ -179,7 +179,7 @@ async def find(ctx, * args): await bot.say('{}, The following entries match **{}**:\n{}'.format(ctx.message.author.mention, search, result)) except LocationLookUpError: - await bot.say('{}, no matches to **{}** were found in the database'.format(ctx.message.author.mention, search)) + await bot.say('{}, no matches to **{}** were found in the database.'.format(ctx.message.author.mention, search)) @commands.cooldown(5, 60, commands.BucketType.user) @@ -194,7 +194,7 @@ async def tunnel(ctx, player: str): await bot.say('{}, **{}** owns the following tunnels: \n{}'.format(ctx.message.author.mention, player, result)) except LocationLookUpError: - await bot.say('{}, no tunnels for the player **{}** were found in the database' + await bot.say('{}, no tunnels for the player **{}** were found in the database/' .format(ctx.message.author.mention, player))