Added market commands

master
Joey Hines 2019-05-11 11:45:55 -05:00
parent 7cb9cee9a0
commit c0f9b5e883
3 changed files with 120 additions and 4 deletions

View File

@ -31,6 +31,28 @@ def formatted_shop(shop, base_url):
return shop_info_list 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): def formatted_location_info(location, base_url):
info = [] info = []

View File

@ -29,8 +29,8 @@ class GeoffreyBot(commands.Bot):
self.base_url = base_url self.base_url = base_url
self.api_token = api_token self.api_token = api_token
settings_url = base_url + '/api/settings/' settings_url = base_url + '/GeoffreyApp/api/settings/'
command_list_url = base_url + '/api/command/commands' command_list_url = base_url + '/GeoffreyApp/api/command/commands'
logger.info("Connecting to the Geoffrey API... ") logger.info("Connecting to the Geoffrey API... ")
while True: while True:

View File

@ -9,7 +9,8 @@ default_error_messages = {
"NoLocationsInDatabase": "You have no locations in the database, you need to add some first!", "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 " "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", "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): 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 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, '{}, your base has been added to the database: \n{}'.format(ctx.message.author.mention,
formatted_location(base))) formatted_location(base)))
@commands.command(pass_context=True)
async def add_farm(self, ctx, x_pos: int, z_pos: int, *args):
"""
{}add_farm <X Coordinate> <Z Coordinate> <Farm Name>
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) @commands.command(pass_context=True)
async def add_item(self, ctx, item_name, quantity: int, diamond_price: int, *args): 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["item_name"],
item["shop"]["name"])) item["shop"]["name"]))
@commands.command(pass_context=True)
async def add_market(self, ctx, x_pos: int, z_pos: int, *args):
"""
{}add_market <X Coordinate> <Z Coordinate> <Name>
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) @commands.command(pass_context=True)
async def add_owner(self, ctx, new_owner_name, *args): 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( await ctx.send('{}, **{}** has been added as a resident to **{}**'.format(
ctx.message.author.mention, new_resident_name, location["name"])) 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 <Resource Name> <Farm Name>
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) @commands.command(pass_context=True)
async def add_shop(self, ctx, x_pos: int, z_pos: int, *args): 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( await ctx.send("{}, **{}** has been deleted from {}, no one bought it anyway.".format(
ctx.message.author.mention, item_name, shop["name"])) 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 <Resource Name> <Farm Name>
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) @commands.command(pass_conext=True)
async def edit_name(self, ctx, new_name: str, old_name: str): 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) info_list = formatted_shop(location, self.base_url)
elif location["type"] == "Town": elif location["type"] == "Town":
info_list = formatted_town(location, self.base_url) 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: else:
info_list = formatted_location_info(location, self.base_url) info_list = formatted_location_info(location, self.base_url)