add_tunnel now needs a location
parent
a1aca02e27
commit
796baaf3a6
10
Commands.py
10
Commands.py
|
@ -76,15 +76,23 @@ class Commands:
|
|||
|
||||
return shop_name
|
||||
|
||||
def add_tunnel(self, tunnel_color, tunnel_number, location_name, discord_uuid=None, mc_uuid=None):
|
||||
def add_tunnel(self, tunnel_color, tunnel_number, location_name=None, discord_uuid=None, mc_uuid=None):
|
||||
|
||||
session = self.interface.database.Session()
|
||||
try:
|
||||
|
||||
player = self.get_player(session, discord_uuid, mc_uuid)
|
||||
if location_name is None:
|
||||
location_list = self.interface.find_location_by_owner(session, player)
|
||||
|
||||
if len(location_list) > 1:
|
||||
raise EntryNameNotUniqueError
|
||||
|
||||
location_name = location_list[0].name
|
||||
|
||||
tunnel = self.interface.add_tunnel(session, player, tunnel_color, tunnel_number, location_name)
|
||||
tunnel_info = tunnel.__str__()
|
||||
|
||||
finally:
|
||||
session.close()
|
||||
|
||||
|
|
|
@ -139,7 +139,6 @@ async def add_shop(ctx, x_pos: int, z_pos: int, *args):
|
|||
async def add_tunnel(ctx, tunnel_color: str, tunnel_number: int, *args):
|
||||
'''
|
||||
Adds your tunnel to the database.
|
||||
The location name is optional.
|
||||
?tunnel [Tunnel Color] [Tunnel Number] [Location Name]
|
||||
'''
|
||||
|
||||
|
@ -147,10 +146,6 @@ async def add_tunnel(ctx, tunnel_color: str, tunnel_number: int, *args):
|
|||
try:
|
||||
bot_commands.add_tunnel(tunnel_color, tunnel_number, discord_uuid=ctx.message.author.id, location_name=loc_name)
|
||||
await bot.say('{}, your tunnel has been added to the database'.format(ctx.message.author.mention))
|
||||
except EntryNameNotUniqueError:
|
||||
await bot.say('{}, you already have one tunnel in the database, please specify a location.'.format(
|
||||
ctx.message.author.mention))
|
||||
return
|
||||
except LocationLookUpError:
|
||||
await bot.say('{}, you do not have a location called **{}**.'.format(
|
||||
ctx.message.author.mention, loc_name))
|
||||
|
@ -158,6 +153,9 @@ async def add_tunnel(ctx, tunnel_color: str, tunnel_number: int, *args):
|
|||
await bot.say('{}, **{}** already has a tunnel.'.format(ctx.message.author.mention, loc_name))
|
||||
except TunnelInitError:
|
||||
await bot.say('{}, invalid tunnel color.'.format(ctx.message.author.mention))
|
||||
except EntryNameNotUniqueError:
|
||||
await bot.say('{}, you have more than one location, you need to specify a location.'
|
||||
.format(ctx.message.author.mention))
|
||||
except InvalidTunnelError:
|
||||
await bot.say('{}, **{}** is an invalid tunnel color.'.format(ctx.message.author.mention, tunnel_color))
|
||||
|
||||
|
|
Loading…
Reference in New Issue