add_tunnel now needs a location

doc_update
Joey Hines 2018-07-31 20:44:06 -05:00
parent a1aca02e27
commit 796baaf3a6
2 changed files with 12 additions and 6 deletions

View File

@ -76,15 +76,23 @@ class Commands:
return shop_name 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() session = self.interface.database.Session()
try: try:
player = self.get_player(session, discord_uuid, mc_uuid) 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 = self.interface.add_tunnel(session, player, tunnel_color, tunnel_number, location_name)
tunnel_info = tunnel.__str__() tunnel_info = tunnel.__str__()
finally: finally:
session.close() session.close()

View File

@ -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): async def add_tunnel(ctx, tunnel_color: str, tunnel_number: int, *args):
''' '''
Adds your tunnel to the database. Adds your tunnel to the database.
The location name is optional.
?tunnel [Tunnel Color] [Tunnel Number] [Location Name] ?tunnel [Tunnel Color] [Tunnel Number] [Location Name]
''' '''
@ -147,10 +146,6 @@ async def add_tunnel(ctx, tunnel_color: str, tunnel_number: int, *args):
try: try:
bot_commands.add_tunnel(tunnel_color, tunnel_number, discord_uuid=ctx.message.author.id, location_name=loc_name) 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)) 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: except LocationLookUpError:
await bot.say('{}, you do not have a location called **{}**.'.format( await bot.say('{}, you do not have a location called **{}**.'.format(
ctx.message.author.mention, loc_name)) 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)) await bot.say('{}, **{}** already has a tunnel.'.format(ctx.message.author.mention, loc_name))
except TunnelInitError: except TunnelInitError:
await bot.say('{}, invalid tunnel color.'.format(ctx.message.author.mention)) 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: except InvalidTunnelError:
await bot.say('{}, **{}** is an invalid tunnel color.'.format(ctx.message.author.mention, tunnel_color)) await bot.say('{}, **{}** is an invalid tunnel color.'.format(ctx.message.author.mention, tunnel_color))