Fixed formating in ?find and ?tunnel
parent
c25b2dad33
commit
87ca99f146
|
@ -146,16 +146,20 @@ class DatabaseInterface:
|
||||||
return player
|
return player
|
||||||
|
|
||||||
def search_all_fields(self, session, search):
|
def search_all_fields(self, session, search):
|
||||||
loc_string = '\n**Locations:**'
|
loc_string = ''
|
||||||
count = 0
|
|
||||||
limit = 10
|
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:
|
expr = Location.owner.has(Player.name.ilike('%{}%'.format(search))) | Location.name.ilike('%{}%'.format(search))
|
||||||
loc_string = loc_string + '\n**. . .**'
|
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
|
expr = Tunnel.owner.has(Player.name.ilike('%{}%'.format(search))) & Tunnel.location == None
|
||||||
tunnels = self.database.query_by_filter(session, Tunnel, expr)
|
tunnels = self.database.query_by_filter(session, Tunnel, expr)
|
||||||
|
@ -164,9 +168,11 @@ class DatabaseInterface:
|
||||||
loc_string = loc_string + '\n\n**Tunnels:**'
|
loc_string = loc_string + '\n\n**Tunnels:**'
|
||||||
for tunnel in tunnels:
|
for tunnel in tunnels:
|
||||||
loc_string = "{}\n{}".format(loc_string, tunnel.full_str())
|
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
|
raise LocationLookUpError
|
||||||
else:
|
else:
|
||||||
return loc_string
|
return loc_string
|
||||||
|
|
|
@ -157,7 +157,12 @@ class Tunnel(SQL_Base):
|
||||||
raise TunnelInitError
|
raise TunnelInitError
|
||||||
|
|
||||||
def full_str(self):
|
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):
|
def __str__(self):
|
||||||
return '{} {}'.format(self.tunnel_direction.value.title(), self.tunnel_number)
|
return '{} {}'.format(self.tunnel_direction.value.title(), self.tunnel_number)
|
||||||
|
|
|
@ -179,7 +179,7 @@ async def find(ctx, * args):
|
||||||
|
|
||||||
await bot.say('{}, The following entries match **{}**:\n{}'.format(ctx.message.author.mention, search, result))
|
await bot.say('{}, The following entries match **{}**:\n{}'.format(ctx.message.author.mention, search, result))
|
||||||
except LocationLookUpError:
|
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)
|
@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))
|
await bot.say('{}, **{}** owns the following tunnels: \n{}'.format(ctx.message.author.mention, player, result))
|
||||||
except LocationLookUpError:
|
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))
|
.format(ctx.message.author.mention, player))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue