From 796baaf3a635bda0e8789c1054c2838b08bd69f8 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Tue, 31 Jul 2018 20:44:06 -0500 Subject: [PATCH] add_tunnel now needs a location --- Commands.py | 10 +++++++++- Geoffrey.py | 8 +++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Commands.py b/Commands.py index 02f0bf7..3659d46 100644 --- a/Commands.py +++ b/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() diff --git a/Geoffrey.py b/Geoffrey.py index 8a89077..819b563 100644 --- a/Geoffrey.py +++ b/Geoffrey.py @@ -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))