diff --git a/GeoffreyBot/bot.py b/GeoffreyBot/bot.py index 6171d02..0f81dbd 100644 --- a/GeoffreyBot/bot.py +++ b/GeoffreyBot/bot.py @@ -14,13 +14,13 @@ def setup_logging(): bot_info_logger.addHandler(console) -def start_bot(discord_token, geoffrey_api_token, geoffrey_base_url): +def start_bot(discord_token, geoffrey_app_url, geoffrey_api_url, geoffrey_api_token): setup_logging() loop = None bot = None try: - bot = GeoffreyBot(geoffrey_base_url, geoffrey_api_token) + bot = GeoffreyBot(geoffrey_app_url, geoffrey_api_url, geoffrey_api_token) loop = asyncio.get_event_loop() loop.run_until_complete(bot.start(discord_token)) diff --git a/GeoffreyBot/geoffrey.py b/GeoffreyBot/geoffrey.py index 6be3633..0f87099 100644 --- a/GeoffreyBot/geoffrey.py +++ b/GeoffreyBot/geoffrey.py @@ -26,20 +26,21 @@ bad_error_message = 'OOPSIE WOOPSIE!! Uwu We made a fucky wucky!! A wittle fucko class GeoffreyBot(commands.Bot): - def __init__(self, base_url, api_token): - self.base_url = base_url - self.api_token = api_token + def __init__(self, geoffrey_app_url, geoffrey_api_url, geoffrey_api_token): + self.api_url = geoffrey_api_url + self.geoffrey_app_url = geoffrey_app_url + self.api_token = geoffrey_api_token - settings_url = base_url + 'api/settings/' - command_list_url = base_url + 'api/command/commands' + self.settings_url = self.api_url + 'settings/' + self.command_list_url = self.api_url + 'command/commands' logger.info("Connecting to the Geoffrey API... ") fail_count = 0 while True: try: - setting = requests.get(url=settings_url, params={"api": self.api_token}).json() - self.command_list = requests.get(url=command_list_url, params={"api": self.api_token}).json() + setting = requests.get(url=self.settings_url, params={"api": self.api_token}).json() + self.command_list = requests.get(url=self.command_list_url, params={"api": self.api_token}).json() break except Exception: if fail_count > 20: diff --git a/GeoffreyBot/geoffrey_api.py b/GeoffreyBot/geoffrey_api.py index b57170f..7113371 100644 --- a/GeoffreyBot/geoffrey_api.py +++ b/GeoffreyBot/geoffrey_api.py @@ -7,7 +7,8 @@ from GeoffreyBot.util import run_command, HandledError class GeoffreyCommands(commands.Cog): def __init__(self, bot): self.bot = bot - self.base_url = bot.base_url + self.api_url = bot.api_url + self.geoffrey_app_url = bot.geoffrey_app_url self.api_token = bot.api_token @commands.command(pass_context=True) @@ -24,7 +25,7 @@ class GeoffreyCommands(commands.Cog): name = get_name(args) - attraction = await run_command(ctx, self.base_url, self.api_token, "POST", "add_attraction", x_pos=x_pos, + attraction = await run_command(ctx, self.api_url, self.api_token, "POST", "add_attraction", x_pos=x_pos, z_pos=z_pos, name=name, discord_uuid=ctx.message.author.id, errors=errors) await ctx.send( @@ -45,7 +46,7 @@ class GeoffreyCommands(commands.Cog): name = get_name(args) - base = await run_command(ctx, self.base_url, self.api_token, "POST", "add_base", x_pos=x_pos, z_pos=z_pos, + base = await run_command(ctx, self.api_url, self.api_token, "POST", "add_base", x_pos=x_pos, z_pos=z_pos, name=name, discord_uuid=ctx.message.author.id, errors=errors) @@ -67,7 +68,7 @@ class GeoffreyCommands(commands.Cog): 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, + farm = await run_command(ctx, self.api_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) @@ -91,7 +92,7 @@ class GeoffreyCommands(commands.Cog): shop_name = get_name(args) - item = await run_command(ctx, self.base_url, self.api_token, "POST", "add_item", + item = await run_command(ctx, self.api_url, self.api_token, "POST", "add_item", item_name=item_name, quantity=quantity, diamond_price=diamond_price, @@ -117,9 +118,9 @@ class GeoffreyCommands(commands.Cog): 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) + market = await run_command(ctx, self.api_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, @@ -139,7 +140,7 @@ class GeoffreyCommands(commands.Cog): location_name = get_name(args) - location = await run_command(ctx, self.base_url, self.api_token, "POST", "add_owner", errors=errors, + location = await run_command(ctx, self.api_url, self.api_token, "POST", "add_owner", errors=errors, new_owner_name=new_owner_name, location_name=location_name, discord_uuid=ctx.message.author.id) @@ -159,7 +160,7 @@ class GeoffreyCommands(commands.Cog): } town_name = get_name(args) - location = await run_command(ctx, self.base_url, self.api_token, "POST", "add_resident", errors=errors, + location = await run_command(ctx, self.api_url, self.api_token, "POST", "add_resident", errors=errors, new_resident_name=new_resident_name, town_name=town_name, discord_uuid=ctx.message.author.id) @@ -182,7 +183,7 @@ class GeoffreyCommands(commands.Cog): farm_name = get_name(args) - resource = await run_command(ctx, self.base_url, self.api_token, "POST", "add_resource", errors=errors, + resource = await run_command(ctx, self.api_url, self.api_token, "POST", "add_resource", errors=errors, resource_name=resource_name, farm_name=farm_name, discord_uuid=ctx.message.author.id) @@ -202,7 +203,7 @@ class GeoffreyCommands(commands.Cog): name = get_name(args) - shop = await run_command(ctx, self.base_url, self.api_token, "POST", "add_shop", errors=errors, x_pos=x_pos, + shop = await run_command(ctx, self.api_url, self.api_token, "POST", "add_shop", errors=errors, x_pos=x_pos, z_pos=z_pos, name=name, discord_uuid=ctx.message.author.id) await ctx.send('{}, your shop has been added to the database: \n{}'.format(ctx.message.author.mention, @@ -220,7 +221,7 @@ class GeoffreyCommands(commands.Cog): name = get_name(args) - town = await run_command(ctx, self.base_url, self.api_token, "POST", "add_town", errors=errors, x_pos=x_pos, + town = await run_command(ctx, self.api_url, self.api_token, "POST", "add_town", errors=errors, x_pos=x_pos, z_pos=z_pos, name=name, discord_uuid=ctx.message.author.id) @@ -241,7 +242,7 @@ class GeoffreyCommands(commands.Cog): "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 = await run_command(ctx, self.api_url, self.api_token, "POST", "add_tunnel", errors=errors, tunnel_direction=tunnel_direction, tunnel_number=tunnel_number, location_name=name, discord_uuid=ctx.message.author.id) @@ -258,7 +259,7 @@ class GeoffreyCommands(commands.Cog): "LocationLookUpError": "you do not have a location by the name **{}** you ding dong goober.".format(name) } - location = await run_command(ctx, self.base_url, self.api_token, "POST", "delete", errors=errors, name=name, + location = await run_command(ctx, self.api_url, self.api_token, "POST", "delete", errors=errors, name=name, discord_uuid=ctx.message.author.id) await ctx.send("{}, **{}** has been deleted from Geoffrey, good riddance.".format(ctx.message.author.mention @@ -279,7 +280,7 @@ class GeoffreyCommands(commands.Cog): "ItemNotFound": "your shop does not sell **{}**. Try again buddy boy.".format(item_name) } - shop = await run_command(ctx, self.base_url, self.api_token, "POST", "delete_item", errors=errors, + shop = await run_command(ctx, self.api_url, self.api_token, "POST", "delete_item", errors=errors, item=item_name, shop_name=shop_name, discord_uuid=ctx.message.author.id) @@ -301,7 +302,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_resource", errors=errors, + farm = await run_command(ctx, self.api_url, self.api_token, "POST", "delete_resource", errors=errors, resource=resource_name, farm_name=farm_name, discord_uuid=ctx.message.author.id) @@ -321,7 +322,7 @@ class GeoffreyCommands(commands.Cog): old_name) } - location = await run_command(ctx, self.base_url, self.api_token, "POST", "edit_name", errors=errors, + location = await run_command(ctx, self.api_url, self.api_token, "POST", "edit_name", errors=errors, loc_name=old_name, new_name=new_name, discord_uuid=ctx.message.author.id) @@ -340,7 +341,7 @@ class GeoffreyCommands(commands.Cog): "LocationLookUpError": "you do not have a location by the name **{}** you ding dong goober.".format( loc_name) } - location = await run_command(ctx, self.base_url, self.api_token, "POST", "edit_pos", errors=errors, x=new_x, + location = await run_command(ctx, self.api_url, self.api_token, "POST", "edit_pos", errors=errors, x=new_x, z=new_z, loc_name=loc_name, discord_uuid=ctx.message.author.id) @@ -361,9 +362,9 @@ class GeoffreyCommands(commands.Cog): "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, - tunnel_direction=new_tunnel_direction, tunnel_number=new_tunnel_number, - loc_name=loc_name, discord_uuid=ctx.message.author.id) + location = await run_command(ctx, self.api_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) await ctx.send("{}, **{}**'s tunnel been moved to **{}**".format(ctx.message.author.mention, location["name"], @@ -385,7 +386,7 @@ class GeoffreyCommands(commands.Cog): else: radius = 200 - locations = await run_command(ctx, self.base_url, self.api_token, "GET", "find_around", errors=errors, + locations = await run_command(ctx, self.api_url, self.api_token, "GET", "find_around", errors=errors, x_pos=x_pos, z_pos=z_pos, radius=radius) message = ["{}, the following locations are within **{}** blocks of (x={}, z={}):".format( @@ -407,7 +408,7 @@ class GeoffreyCommands(commands.Cog): 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, + locations = await run_command(ctx, self.api_url, self.api_token, "GET", "find_farm", errors=errors, resource_name=search) message = ["{}, the following farms produce **{}**:".format(ctx.message.author.mention, search)] @@ -428,7 +429,7 @@ class GeoffreyCommands(commands.Cog): errors = { "LocationLookUpError": "there are no locations that match **{}**.".format(search) } - locations = await run_command(ctx, self.base_url, self.api_token, "GET", "find_location", errors=errors, + locations = await run_command(ctx, self.api_url, self.api_token, "GET", "find_location", errors=errors, search=search) message = ["{}, the following locations match **{}**:".format(ctx.message.author.mention, search)] @@ -465,21 +466,21 @@ class GeoffreyCommands(commands.Cog): "LocationLookUpError": "there are no locations that match **{}**.".format(location_name) } - location = await run_command(ctx, self.base_url, self.api_token, "GET", "info", location_name=location_name, + location = await run_command(ctx, self.api_url, self.api_token, "GET", "info", location_name=location_name, errors=errors) message = "{}, info on {}:\n".format(ctx.message.author.mention, location["name"]) if location["type"] == "Shop": - info_list = formatted_shop(location, self.base_url) + info_list = formatted_shop(location, self.geoffrey_app_url) elif location["type"] == "Town": - info_list = formatted_town(location, self.base_url) + info_list = formatted_town(location, self.geoffrey_app_url) elif location["type"] == "PublicFarm": - info_list = formatted_farm(location, self.base_url) + info_list = formatted_farm(location, self.geoffrey_app_url) elif location["type"] == "Market": - info_list = formatted_market(location, self.base_url) + info_list = formatted_market(location, self.geoffrey_app_url) else: - info_list = formatted_location_info(location, self.base_url) + info_list = formatted_location_info(location, self.geoffrey_app_url) await ctx.send(message) await self.bot.send_list(ctx, info_list) @@ -490,7 +491,7 @@ class GeoffreyCommands(commands.Cog): {}me """ - locations = await run_command(ctx, self.base_url, self.api_token, "GET", "me", + locations = await run_command(ctx, self.api_url, self.api_token, "GET", "me", discord_uuid=ctx.message.author.id) message = ["{}, you have the following locations:".format(ctx.message.author.mention)] @@ -509,7 +510,7 @@ class GeoffreyCommands(commands.Cog): "PlayerInDBError": "you are already registered with Geoffrey you ding dong." } - await run_command(ctx, self.base_url, self.api_token, "POST", "register", errors=errors, + await run_command(ctx, self.api_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.".format( @@ -530,7 +531,7 @@ class GeoffreyCommands(commands.Cog): "LocationLookUpError": "you do not have a town called **{}** you ding dong goober.".format(town_name) } - location = await run_command(ctx, self.base_url, self.api_token, "POST", "remove_resident", errors=errors, + location = await run_command(ctx, self.api_url, self.api_token, "POST", "remove_resident", errors=errors, resident_name=resident_name, town_name=town_name, discord_uuid=ctx.message.author.id) @@ -549,12 +550,12 @@ class GeoffreyCommands(commands.Cog): "ItemNotFound": "no shop was found selling {}".format(item) } - results = await run_command(ctx, self.base_url, self.api_token, "GET", "selling", errors=errors, item_name=item) + results = await run_command(ctx, self.api_url, self.api_token, "GET", "selling", errors=errors, item_name=item) message = ["{} The following shop(s) sell **{}**:".format(ctx.message.author.mention, item)] for shop in results: - for line in formatted_shop(shop, base_url=self.base_url): + for line in formatted_shop(shop, base_url=self.geoffrey_app_url): message.append(line) message.append('') @@ -573,13 +574,13 @@ class GeoffreyCommands(commands.Cog): "ItemNotFound": "no shop was found selling {}".format(item) } - results = await run_command(ctx, self.base_url, self.api_token, "GET", "selling_price", errors=errors, + results = await run_command(ctx, self.api_url, self.api_token, "GET", "selling_price", errors=errors, item_name=item) message = ["{} The following shop(s) sell **{}**:".format(ctx.message.author.mention, item)] for shop in results: - for line in formatted_shop(shop, base_url=self.base_url): + for line in formatted_shop(shop, base_url=self.geoffrey_app_url): message.append(line) message.append('') @@ -601,7 +602,7 @@ class GeoffreyCommands(commands.Cog): "EntryNameNotUniqueError": "you have more than one location. Please specify a name, dingus." } - item = await run_command(ctx, self.base_url, self.api_token, "POST", "restock", errors=errors, + item = await run_command(ctx, self.api_url, self.api_token, "POST", "restock", errors=errors, item_name=item_name, shop_name=shop_name, discord_uuid=ctx.message.author.id) await ctx.send('{}, **{}** has been restocked at **{}**'.format(ctx.message.author.mention, item_name, @@ -618,7 +619,7 @@ class GeoffreyCommands(commands.Cog): errors = { "LocationLookUpError": "**{}** has no tunnels in the database.".format(player_name) } - tunnels = await run_command(ctx, self.base_url, self.api_token, "GET", "tunnel", errors=errors, + tunnels = await run_command(ctx, self.api_url, self.api_token, "GET", "tunnel", errors=errors, player_name=player_name) message = ["{}, **{}** has the following tunnels:".format(ctx.message.author.mention, player_name)] diff --git a/GeoffreyBot/geoffrey_formatter.py b/GeoffreyBot/geoffrey_formatter.py index e42d308..21be7d2 100644 --- a/GeoffreyBot/geoffrey_formatter.py +++ b/GeoffreyBot/geoffrey_formatter.py @@ -87,6 +87,7 @@ def formatted_location_info(location, base_url): info = [] info.append(formatted_location(location)) + info.append(get_full_link(base_url, location["link"])) return info diff --git a/GeoffreyBot/geoffrey_mod_cmds.py b/GeoffreyBot/geoffrey_mod_cmds.py index e81a932..1d1394b 100644 --- a/GeoffreyBot/geoffrey_mod_cmds.py +++ b/GeoffreyBot/geoffrey_mod_cmds.py @@ -6,7 +6,7 @@ from GeoffreyBot.util import run_command, HandledError class GeoffreyModCommands(commands.Cog): def __init__(self, bot): self.bot = bot - self.base_url = bot.base_url + self.api_url = bot.api_url self.api_token = bot.api_token # Check if the user has permission to use mod commands @@ -35,7 +35,7 @@ class GeoffreyModCommands(commands.Cog): "LocationLookUpError": "That user does not have a location by the name **{}**.".format(name) } - location = await run_command(ctx, self.base_url, self.api_token, "POST", "delete", errors=errors, name=name, + location = await run_command(ctx, self.api_url, self.api_token, "POST", "delete", errors=errors, name=name, discord_uuid=discord_uuid) await ctx.send("{}, **{}** has been deleted from Geoffrey".format(ctx.message.author.mention, location)) @@ -54,7 +54,7 @@ class GeoffreyModCommands(commands.Cog): "EntryNameNotUniqueError": "Please specify the location name".format(item_name) } - shop = await run_command(ctx, self.base_url, self.api_token, "POST", "delete_item", errors=errors, + shop = await run_command(ctx, self.api_url, self.api_token, "POST", "delete_item", errors=errors, item=item_name, shop_name=shop_name, discord_uuid=discord_uuid) @@ -74,7 +74,7 @@ class GeoffreyModCommands(commands.Cog): old_name) } - location = await run_command(ctx, self.base_url, self.api_token, "POST", "edit_name", errors=errors, + location = await run_command(ctx, self.api_url, self.api_token, "POST", "edit_name", errors=errors, loc_name=old_name, new_name=new_name, discord_uuid=discord_uuid) @@ -95,7 +95,7 @@ class GeoffreyModCommands(commands.Cog): "LocationLookUpError": "Town not found.".format(town_name) } - location = await run_command(ctx, self.base_url, self.api_token, "POST", "remove_resident", errors=errors, + location = await run_command(ctx, self.api_url, self.api_token, "POST", "remove_resident", errors=errors, resident_name=resident_name, town_name=town_name, discord_uuid=discord_uuid) diff --git a/GeoffreyBot/util.py b/GeoffreyBot/util.py index 9d07478..f4ed828 100644 --- a/GeoffreyBot/util.py +++ b/GeoffreyBot/util.py @@ -21,7 +21,7 @@ class CommandError: async def run_command(ctx, base_url, api_token, request_type, command, errors=None, **kwargs): - URL = base_url + '/GeoffreyApp/api/command/{}/' + URL = base_url + 'command/{}/' kwargs["api"] = api_token