From 21eb7f513cd463a51d4b079723859a09eecf573f Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Mon, 13 May 2019 21:05:37 -0500 Subject: [PATCH 1/3] Fixed send_list and register command + send_list was updated to track the raw msg size + register was missing a format --- GeoffreyBot/geoffrey.py | 5 +---- GeoffreyBot/geoffrey_api.py | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/GeoffreyBot/geoffrey.py b/GeoffreyBot/geoffrey.py index f5eae1c..ba86c6c 100644 --- a/GeoffreyBot/geoffrey.py +++ b/GeoffreyBot/geoffrey.py @@ -129,17 +129,14 @@ class GeoffreyBot(commands.Bot): @staticmethod async def send_list(ctx, send_list): - size = 0 msg = "" for s in send_list: - if (size + len(s)) > 2000: + if (len(msg) + len(s)) > 2000: await ctx.send(msg) msg = s - size = len(s) else: msg = msg + '\n' + s - size = size + len(s) if len(msg) > 0: await ctx.send(msg) diff --git a/GeoffreyBot/geoffrey_api.py b/GeoffreyBot/geoffrey_api.py index 83ed2f0..eac53c7 100644 --- a/GeoffreyBot/geoffrey_api.py +++ b/GeoffreyBot/geoffrey_api.py @@ -543,9 +543,9 @@ class GeoffreyCommands(commands.Cog): await run_command(ctx, self.base_url, self.api_token, "POST", "register", errors=errors, player_name=ctx.message.author.display_name, discord_uuid=ctx.message.author.id) - await ctx.send("{}, you have been added to the database. Do {}help to see what this bot can do.", + await ctx.send("{}, you have been added to the database. Do {}help to see what this bot can do.".format( ctx.message.author.mention, - self.bot.prefix) + self.bot.prefix)) @commands.command(pass_context=True) async def remove_resident(self, ctx, resident_name, *args): From 3911daa4302efa10b948ddcb996d426edccb0d29 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Tue, 14 May 2019 08:02:14 -0500 Subject: [PATCH 2/3] Fixed missing parameters not being handled on on_command_error --- GeoffreyBot/geoffrey.py | 8 ++++++++ GeoffreyBot/geoffrey_api.py | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/GeoffreyBot/geoffrey.py b/GeoffreyBot/geoffrey.py index ba86c6c..2f91c57 100644 --- a/GeoffreyBot/geoffrey.py +++ b/GeoffreyBot/geoffrey.py @@ -88,6 +88,14 @@ class GeoffreyBot(commands.Bot): elif hasattr(error, "original") and isinstance(error.original, request_exception.ConnectionError): error_str = "Unable to connect to the database. Hopefully someone is working on this..." await self.send_error_message("Can't connect to the GeoffreyAPI, is it offline?") + elif hasattr(error, "original"): + e = error.original.args[0] + + if e == "TypeError": + error_str = "Well bud, you got this far. Good job! But you still h*cked up the syntax:" + + for line in self.help_dict[ctx.command.name]: + error_str += line if error_str is '': await self.send_error_message( diff --git a/GeoffreyBot/geoffrey_api.py b/GeoffreyBot/geoffrey_api.py index eac53c7..17b112d 100644 --- a/GeoffreyBot/geoffrey_api.py +++ b/GeoffreyBot/geoffrey_api.py @@ -353,7 +353,7 @@ class GeoffreyCommands(commands.Cog): "ItemNotFound": "your farm does not produce **{}**. Try again buddy boy.".format(resource_name) } - farm = await run_command(ctx, self.base_url, self.api_token, "POST", "delete_item", errors=errors, + farm = await run_command(ctx, self.base_url, self.api_token, "POST", "delete_resource", errors=errors, resource=resource_name, farm_name=farm_name, discord_uuid=ctx.message.author.id) @@ -413,7 +413,7 @@ class GeoffreyCommands(commands.Cog): "InvalidLookUpError": "{} is not a valid tunnel direction ya gub".format(new_tunnel_direction) } - location = run_command(ctx, self.base_url, self.api_token, "POST", "edit_tunnel", errors=errors, + location = await run_command(ctx, self.base_url, self.api_token, "POST", "edit_tunnel", errors=errors, tunnel_direction=new_tunnel_direction, tunnel_number=new_tunnel_number, loc_name=loc_name, discord_uuid=ctx.message.author.id) @@ -537,7 +537,7 @@ class GeoffreyCommands(commands.Cog): {}register """ errors = { - "PlayerinDBError": "you are already registered with Geoffrey you ding dong." + "PlayerInDBError": "you are already registered with Geoffrey you ding dong." } await run_command(ctx, self.base_url, self.api_token, "POST", "register", errors=errors, From a346cb3eb94cc0d852da78ae451301b738a2f400 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Tue, 14 May 2019 17:38:39 -0500 Subject: [PATCH 3/3] Added find_farm command --- GeoffreyBot/geoffrey_api.py | 57 ++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/GeoffreyBot/geoffrey_api.py b/GeoffreyBot/geoffrey_api.py index 17b112d..92cd948 100644 --- a/GeoffreyBot/geoffrey_api.py +++ b/GeoffreyBot/geoffrey_api.py @@ -179,13 +179,11 @@ class GeoffreyCommands(commands.Cog): async def add_owner(self, ctx, new_owner_name, *args): """ {}add_owner - WARNING: The new owner had just as much power as you to edit or delete this location. + WARNING: The new owner has just as much power as you to edit or delete this location. """ errors = { - "OwnerNotFoundError": "ain't no one in this darn database named **{}** you goob".format( - ctx.message.author.mention, new_owner_name), - "IsOwnerError": "**{}** is already an owner, stop having amosia.".format( - ctx.message.author.mention, new_owner_name), + "OwnerNotFoundError": "ain't no one in this darn database named **{}** you goob".format(new_owner_name), + "IsOwnerError": "**{}** is already an owner, stop having amosia.".format(new_owner_name), "LocationLookUpError": "you do not have a location by that name you ding dong goober." } @@ -207,7 +205,7 @@ class GeoffreyCommands(commands.Cog): "ResidentNotFoundError": "ain't no one in this darn database named **{}** you goob".format( new_resident_name), "IsResidentError": "**{}** is already a resident, stop having amosia.".format(new_resident_name), - "LocationLookupError": "you do not have a town by that name you ding dong goober." + "LocationLookUpError": "you do not have a town by that name you ding dong goober." } town_name = get_name(args) @@ -263,7 +261,7 @@ class GeoffreyCommands(commands.Cog): @commands.command(pass_context=True) async def add_town(self, ctx, x_pos: int, z_pos: int, *args): """ - {}add_town + {}add_town The Town Name parameter is optional if this is your first town """ errors = { @@ -283,15 +281,15 @@ class GeoffreyCommands(commands.Cog): @commands.command(pass_context=True) async def add_tunnel(self, ctx, tunnel_direction, tunnel_number: int, *args): """ - {}add_tunnel + {}add_tunnel The Name parameter is optional if you only have one location """ - errors = { - "InvalidTunnelError": "{} is not a valid tunnel direction ya gub".format(tunnel_direction), - "LocationLookUpError": "you do not have a location by the name you ding dong goober." - } name = get_name(args) + errors = { + "InvalidTunnelError": "{} is not a valid tunnel direction ya gub".format(tunnel_direction), + "LocationLookUpError": "you do not have a location by the name **{}** you ding dong goober.".format(name) + } tunnel = await run_command(ctx, self.base_url, self.api_token, "POST", "add_tunnel", errors=errors, tunnel_direction=tunnel_direction, @@ -369,7 +367,7 @@ class GeoffreyCommands(commands.Cog): errors = { "EntryNameNotUniqueError": "a location is already called **{}** you ding dong goober".format(old_name), - "LocationLookupError": "you do not have a location by the name **{}** you ding dong goober.".format( + "LocationLookUpError": "you do not have a location by the name **{}** you ding dong goober.".format( old_name) } @@ -383,7 +381,7 @@ class GeoffreyCommands(commands.Cog): @commands.command(pass_conext=True) async def edit_pos(self, ctx, new_x: int, new_z: int, *args): """ - {}edit_post + {}edit_pos """ loc_name = get_name(args) @@ -409,8 +407,8 @@ class GeoffreyCommands(commands.Cog): errors = { "LocationLookUpError": "you do not have a location by the name **{}** you ding dong goober.".format( - "loc_name"), - "InvalidLookUpError": "{} is not a valid tunnel direction ya gub".format(new_tunnel_direction) + loc_name), + "InvalidTunnelError": "{} is not a valid tunnel direction ya gub".format(new_tunnel_direction) } location = await run_command(ctx, self.base_url, self.api_token, "POST", "edit_tunnel", errors=errors, @@ -438,7 +436,7 @@ class GeoffreyCommands(commands.Cog): radius = 200 locations = await run_command(ctx, self.base_url, self.api_token, "GET", "find_around", errors=errors, - x_pos=x_pos, z_pos=z_pos) + x_pos=x_pos, z_pos=z_pos, radius=radius) message = ["{}, the following locations are within **{}** blocks of (x={}, z={}):".format( ctx.message.author.mention, radius, x_pos, z_pos)] @@ -448,6 +446,27 @@ class GeoffreyCommands(commands.Cog): await self.bot.send_list(ctx, message) + @commands.command(pass_context=True) + async def find_farm(self, ctx, *args): + """ + {}find_farm + """ + + search = get_name(args) + + errors = { + "ResourceNotFoundError": "there are no farms that match **{}**.".format(search) + } + locations = await run_command(ctx, self.base_url, self.api_token, "GET", "find_farm", errors=errors, + resource_name=search) + + message = ["{}, the following farms produce **{}**:".format(ctx.message.author.mention, search)] + + for location in locations: + message.append(formatted_location(location)) + + await self.bot.send_list(ctx, message) + @commands.command(pass_context=True, aliases=["find"]) async def find_location(self, ctx, *args): """ @@ -557,7 +576,7 @@ class GeoffreyCommands(commands.Cog): town_name = get_name(args) errors = { - "ResidentNotFoundError": "ain't no one your town named {} you goob".format(resident_name), + "ResidentNotFoundError": "ain't no one in your town named {} you goob".format(resident_name), "LocationLookUpError": "you do not have a town called **{}** you ding dong goober.".format(town_name) } @@ -595,7 +614,7 @@ class GeoffreyCommands(commands.Cog): @commands.command(pass_context=True) async def selling_price(self, ctx, *args): """ - {}selling_rpice + {}selling_price Sorts by best price """ item = get_name(args)