Fixed formating in ?find and ?tunnel

doc_update
Joey Hines 2018-07-29 10:50:24 -05:00
parent c25b2dad33
commit 87ca99f146
3 changed files with 24 additions and 13 deletions

View File

@ -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

View File

@ -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)

View File

@ -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))