From c0f9b5e8837d3d54dca907e2a1f33f2375767c89 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sat, 11 May 2019 11:45:55 -0500 Subject: [PATCH] Added market commands --- GeoffreyBot/GeoffreyApiHelper.py | 22 +++++++ GeoffreyBot/geoffrey.py | 4 +- GeoffreyBot/geoffrey_api.py | 98 +++++++++++++++++++++++++++++++- 3 files changed, 120 insertions(+), 4 deletions(-) diff --git a/GeoffreyBot/GeoffreyApiHelper.py b/GeoffreyBot/GeoffreyApiHelper.py index ddfcb23..5d120bc 100644 --- a/GeoffreyBot/GeoffreyApiHelper.py +++ b/GeoffreyBot/GeoffreyApiHelper.py @@ -31,6 +31,28 @@ def formatted_shop(shop, base_url): return shop_info_list +def formatted_farm(farm, base_url): + farm_info_list = formatted_location_info(farm, base_url) + + if len(farm["resources"]) > 0: + farm_info_list.append("**Produces:**") + for resource in farm["resources"]: + farm_info_list.append(resource["name"]) + + return farm_info_list + + +def formatted_market(market, base_url): + market_info_list = formatted_location_info(market, base_url) + + if len(market["shops"]) > 0: + market_info_list.append("**Shops:**") + for shop in market["shops"]: + market_info_list.append(formatted_location(shop)) + + return market_info_list + + def formatted_location_info(location, base_url): info = [] diff --git a/GeoffreyBot/geoffrey.py b/GeoffreyBot/geoffrey.py index fd43463..a80f167 100644 --- a/GeoffreyBot/geoffrey.py +++ b/GeoffreyBot/geoffrey.py @@ -29,8 +29,8 @@ class GeoffreyBot(commands.Bot): self.base_url = base_url self.api_token = api_token - settings_url = base_url + '/api/settings/' - command_list_url = base_url + '/api/command/commands' + settings_url = base_url + '/GeoffreyApp/api/settings/' + command_list_url = base_url + '/GeoffreyApp/api/command/commands' logger.info("Connecting to the Geoffrey API... ") while True: diff --git a/GeoffreyBot/geoffrey_api.py b/GeoffreyBot/geoffrey_api.py index a8d77a9..a89d4e2 100644 --- a/GeoffreyBot/geoffrey_api.py +++ b/GeoffreyBot/geoffrey_api.py @@ -9,7 +9,8 @@ default_error_messages = { "NoLocationsInDatabase": "You have no locations in the database, you need to add some first!", "DataError": "Slow down their slugger, that's a long word or number you are trying to cram into me, try again with " "something smaller, please", - "LocationHasTunnelError": "that location already has a tunnel you goober." + "LocationHasTunnelError": "that location already has a tunnel you goober.", + "EntryNameNotUniqueError": "that name has already been used, be more creative dingus kong" } @@ -24,7 +25,7 @@ class CommandError: async def run_command(ctx, base_url, api_token, request_type, command, errors=None, **kwargs): - URL = base_url + '/api/command/{}/' + URL = base_url + '/GeoffreyApp/api/command/{}/' kwargs["api"] = api_token @@ -81,6 +82,28 @@ class GeoffreyCommands(commands.Cog): '{}, your base has been added to the database: \n{}'.format(ctx.message.author.mention, formatted_location(base))) + @commands.command(pass_context=True) + async def add_farm(self, ctx, x_pos: int, z_pos: int, *args): + """ + {}add_farm + The Name parameter is optional if this is your first farm + + """ + + errors = { + "LocationLookUpError": "you have more than one location. Please specify a name." + } + + name = get_name(args) + + farm = await run_command(ctx, self.base_url, self.api_token, "POST", "add_farm", x_pos=x_pos, z_pos=z_pos, + name=name, + discord_uuid=ctx.message.author.id, errors=errors) + + await ctx.send( + '{}, your farm has been added to the database: \n{}'.format(ctx.message.author.mention, + formatted_location(farm))) + @commands.command(pass_context=True) async def add_item(self, ctx, item_name, quantity: int, diamond_price: int, *args): """ @@ -109,6 +132,28 @@ class GeoffreyCommands(commands.Cog): item["item_name"], item["shop"]["name"])) + @commands.command(pass_context=True) + async def add_market(self, ctx, x_pos: int, z_pos: int, *args): + """ + {}add_market + The Name parameter is optional if this is your first market + + """ + + errors = { + "LocationLookUpError": "you have more than one location. Please specify a name." + } + + name = get_name(args) + + market = await run_command(ctx, self.base_url, self.api_token, "POST", "add_market", x_pos=x_pos, z_pos=z_pos, + name=name, + discord_uuid=ctx.message.author.id, errors=errors) + + await ctx.send( + '{}, your market has been added to the database: \n{}'.format(ctx.message.author.mention, + formatted_location(market))) + @commands.command(pass_context=True) async def add_owner(self, ctx, new_owner_name, *args): """ @@ -152,6 +197,29 @@ class GeoffreyCommands(commands.Cog): await ctx.send('{}, **{}** has been added as a resident to **{}**'.format( ctx.message.author.mention, new_resident_name, location["name"])) + @commands.command(pass_context=True) + async def add_resource(self, ctx, resource_name, *args): + """ + {}add_item + If resource name contains spaces, it must be wrapped in quotes. eg "Rotten Flesh" + The Farm Name parameter is optional if this is your first farm + + """ + errors = { + "LocationLookUpError": "You do not have a farm by that name, goober.", + "EntryNameNotUniqueError": "You have more than one farm. Please specify a name, dingus." + + } + + farm_name = get_name(args) + + resource = await run_command(ctx, self.base_url, self.api_token, "POST", "add_resource", errors=errors, + resource_name=resource_name, + farm_name=farm_name, + discord_uuid=ctx.message.author.id) + + await ctx.send('{}, **{}** has been added to the farm.'.format(ctx.message.author.mention, resource["name"])) + @commands.command(pass_context=True) async def add_shop(self, ctx, x_pos: int, z_pos: int, *args): """ @@ -249,6 +317,28 @@ class GeoffreyCommands(commands.Cog): await ctx.send("{}, **{}** has been deleted from {}, no one bought it anyway.".format( ctx.message.author.mention, item_name, shop["name"])) + @commands.command(pass_context=True) + async def delete_resource(self, ctx, resource_name: str, *args): + """ + {}delete_resource + The Farm Name parameter is optional if you only have one location. + """ + + farm_name = get_name(args) + + errors = { + "LocationLookUpError": "you do not have a farm by that name you ding dong goober.", + "EntryNameNotUniqueError": "you have more than one location. Please specify a name, dingus.", + "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, + resource=resource_name, + farm_name=farm_name, discord_uuid=ctx.message.author.id) + + await ctx.send("{}, **{}** has been deleted from {}, Hythe's farm is better anyway.".format( + ctx.message.author.mention, resource_name, farm["name"])) + @commands.command(pass_conext=True) async def edit_name(self, ctx, new_name: str, old_name: str): """ @@ -394,6 +484,10 @@ class GeoffreyCommands(commands.Cog): info_list = formatted_shop(location, self.base_url) elif location["type"] == "Town": info_list = formatted_town(location, self.base_url) + elif location["type"] == "PublicFarm": + info_list = formatted_farm(location, self.base_url) + elif location["type"] == "Market": + info_list = formatted_market(location, self.base_url) else: info_list = formatted_location_info(location, self.base_url)