From 78fb85cf1770d02f16b405de8cef2ef3cb9a4913 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Wed, 10 Apr 2019 14:08:39 -0500 Subject: [PATCH] Upgraded to discord.py v1.0 --- GeoffreyBot/geoffrey.py | 23 +++++----- GeoffreyBot/geoffrey_api.py | 90 ++++++++++++++++++------------------- README | 2 + setup.py | 2 +- 4 files changed, 58 insertions(+), 59 deletions(-) create mode 100644 README diff --git a/GeoffreyBot/geoffrey.py b/GeoffreyBot/geoffrey.py index e892830..e534d08 100644 --- a/GeoffreyBot/geoffrey.py +++ b/GeoffreyBot/geoffrey.py @@ -46,9 +46,8 @@ class GeoffreyBot(commands.Bot): self.special_users = [] self.default_status = setting['STATUS'] - super().__init__(command_prefix=self.prefix, description=description, case_insensitive=True) + super().__init__(command_prefix=self.prefix, description=description, case_insensitive=True, help_command=None) - self.remove_command("help") self.load_extension('GeoffreyBot.geoffrey_api') self.help_page = self.build_help_page() @@ -98,8 +97,8 @@ class GeoffreyBot(commands.Bot): error_str = "Well bud, you got this far. Good job! But you still h*cked up the syntax. Check {}help." \ .format(self.prefix) elif e == "DataError": - error_str = "Slow down their slugger, that's a long word or number you are trying to cram into me, try " \ - "again with something smaller, please" + error_str = "Slow down their slugger, that's a long word or number you are trying to cram into me, " \ + "try again with something smaller, please" if error_str is '': await self.send_error_message( @@ -124,7 +123,7 @@ class GeoffreyBot(commands.Bot): async def send_error_message(self, msg): for user_id in self.error_users: - user = await self.get_user_info(user_id) + user = self.get_user(user_id) if msg is list: await self.send_list(user, msg) @@ -132,11 +131,12 @@ class GeoffreyBot(commands.Bot): await user.send(msg) def run_command(self, command, **kwargs): - URL = self.base_url + '/api/command/{}' + url = self.base_url + '/api/command/{}' - return requests.get(url=URL.format(command), params=kwargs).json() + return requests.get(url=url.format(command), params=kwargs).json() - async def send_list(self, ctx, send_list): + @staticmethod + async def send_list(ctx, send_list): size = 0 msg = "" @@ -168,7 +168,7 @@ class GeoffreyBot(commands.Bot): name = command["command"].ljust(largest_command_size + 2) help_list.append(" {}{}{}".format(self.prefix, name, command["help"])) - help_list.append("\nDo ?help to get more info on any of thee commands above") + help_list.append("\nDo ?help to get more info on any of the commands above") help_list.append("```") return help_list @@ -178,9 +178,7 @@ class GeoffreyBot(commands.Bot): for command in self.command_list: command_name = command["command"] - help_list = ['```'] - - help_list.append(command["help"] + "\n") + help_list = ['```', command["help"] + "\n"] c = self.get_command(command_name) @@ -193,4 +191,3 @@ class GeoffreyBot(commands.Bot): help_dict[command_name] = help_list return help_dict - diff --git a/GeoffreyBot/geoffrey_api.py b/GeoffreyBot/geoffrey_api.py index 6de2beb..e403ff0 100644 --- a/GeoffreyBot/geoffrey_api.py +++ b/GeoffreyBot/geoffrey_api.py @@ -35,7 +35,7 @@ def check_error(exception, handled_errors): raise exception -class GeoffreyCommands: +class GeoffreyCommands(commands.Cog): def __init__(self, bot): self.bot = bot self.base_url = bot.base_url @@ -43,11 +43,11 @@ class GeoffreyCommands: @commands.command(pass_context=True) async def add_base(self, ctx, x_pos: int, z_pos: int, *args): - ''' + """ {}add_base The Name parameter is optional if this is your first base - ''' + """ name = get_name(args) try: @@ -74,12 +74,12 @@ class GeoffreyCommands: @commands.command(pass_context=True) async def add_item(self, ctx, item_name, quantity: int, diamond_price: int, *args): - ''' + """ {}add_item If item name contains spaces, it must be wrapped in quotes. eg "Diamond Pickaxe" The Shop Name parameter is optional if this is your first shop - ''' + """ shop_name = get_name(args) try: @@ -104,10 +104,10 @@ class GeoffreyCommands: @commands.command(pass_context=True) 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. - ''' + """ location_name = get_name(args) @@ -140,9 +140,9 @@ class GeoffreyCommands: @commands.command(pass_context=True) async def add_resident(self, ctx, new_resident_name, *args): - ''' + """ {}add_resident - ''' + """ town_name = get_name(args) try: @@ -175,10 +175,10 @@ class GeoffreyCommands: @commands.command(pass_context=True) async def add_shop(self, ctx, x_pos: int, z_pos: int, *args): - ''' + """ {}add_shop The Shop Name parameter is optional if this is your first shop - ''' + """ name = get_name(args) @@ -206,10 +206,10 @@ class GeoffreyCommands: @commands.command(pass_context=True) async def add_town(self, ctx, x_pos: int, z_pos: int, *args): - ''' + """ {}add_town The Town Name parameter is optional if this is your first town - ''' + """ name = get_name(args) @@ -237,10 +237,10 @@ class GeoffreyCommands: @commands.command(pass_context=True) async def add_tunnel(self, ctx, tunnel_direction, tunnel_number: int, *args): - ''' + """ {}add_tunnel The Name parameter is optional if you only have one location - ''' + """ name = get_name(args) @@ -269,9 +269,9 @@ class GeoffreyCommands: @commands.command(pass_context=True) async def delete(self, ctx, *args): - ''' + """ {}delete - ''' + """ name = get_name(args) try: @@ -292,10 +292,10 @@ class GeoffreyCommands: @commands.command(pass_context=True) async def delete_item(self, ctx, item_name: str, *args): - ''' + """ {}delete_item The Shop Name parameter is optional if you only have one location. - ''' + """ shop_name = get_name(args) try: @@ -323,10 +323,10 @@ class GeoffreyCommands: @commands.command(pass_conext=True) async def edit_name(self, ctx, new_name: str, old_name: str): - ''' + """ {}edit_name If the name has spaces in it, it must be wrapped in quotes. eg "Cool Shop 123" - ''' + """ try: location = run_command(self.base_url, self.api_token, "POST", "edit_name", loc_name=old_name, @@ -349,9 +349,9 @@ class GeoffreyCommands: @commands.command(pass_conext=True) async def edit_pos(self, ctx, new_x: int, new_z: int, *args): - ''' + """ {}edit_post - ''' + """ loc_name = get_name(args) try: @@ -372,9 +372,9 @@ class GeoffreyCommands: @commands.command(pass_conext=True) async def edit_tunnel(self, ctx, new_tunnel_direction: str, new_tunnel_number: int, *args): - ''' + """ {}edit_tunnel - ''' + """ loc_name = get_name(args) try: @@ -401,10 +401,10 @@ class GeoffreyCommands: @commands.command(pass_context=True) async def find_around(self, ctx, x_pos, z_pos, *args): - ''' + """ {}find_around The Radius parameter is optional and defaults to 200 blocks - ''' + """ try: if len(args) > 0: @@ -434,9 +434,9 @@ class GeoffreyCommands: @commands.command(pass_context=True, aliases=["find"]) async def find_location(self, ctx, *args): - ''' + """ {}find_location - ''' + """ search = get_name(args) try: @@ -476,9 +476,9 @@ class GeoffreyCommands: @commands.command(pass_context=True) async def info(self, ctx, *args): - ''' + """ {}info - ''' + """ location_name = get_name(args) try: @@ -509,9 +509,9 @@ class GeoffreyCommands: @commands.command(pass_context=True) async def me(self, ctx): - ''' + """ {}me - ''' + """ locations = run_command(self.base_url, self.api_token, "GET", "me", discord_uuid=ctx.message.author.id) @@ -524,9 +524,9 @@ class GeoffreyCommands: @commands.command(pass_context=True) async def register(self, ctx): - ''' + """ {}register - ''' + """ try: run_command(self.base_url, self.api_token, "POST", "register", player_name=ctx.message.author.display_name, discord_uuid=ctx.message.author.id) @@ -545,10 +545,10 @@ class GeoffreyCommands: @commands.command(pass_context=True) async def remove_resident(self, ctx, resident_name, *args): - ''' + """ {}remove_resident The Town Name is optional if you only have one town. - ''' + """ town_name = get_name(args) try: @@ -577,10 +577,10 @@ class GeoffreyCommands: @commands.command(pass_context=True) async def selling(self, ctx, *args): - ''' + """ {}selling Sorts by most recently added - ''' + """ item = get_name(args) try: @@ -608,10 +608,10 @@ class GeoffreyCommands: @commands.command(pass_context=True) async def selling_price(self, ctx, *args): - ''' + """ {}selling Sorts by most recently added - ''' + """ item = get_name(args) try: @@ -639,10 +639,10 @@ class GeoffreyCommands: @commands.command(pass_context=True) async def restock(self, ctx, item_name, *args): - ''' + """ {}restock The Shop Name is optional if you only have one shop. - ''' + """ shop_name = get_name(args) @@ -670,9 +670,9 @@ class GeoffreyCommands: @commands.command(pass_context=True) async def tunnel(self, ctx, *args): - ''' + """ {}tunnel - ''' + """ player_name = get_name(args) try: diff --git a/README b/README new file mode 100644 index 0000000..28bda4a --- /dev/null +++ b/README @@ -0,0 +1,2 @@ +Geoffrey Discord Bot +A Discord Bot for The Geoffrey Database \ No newline at end of file diff --git a/setup.py b/setup.py index a63a4a1..834f579 100644 --- a/setup.py +++ b/setup.py @@ -4,6 +4,6 @@ setup( name='Geoffrey-Discordbot', version=__import__('GeoffreyBot').__version__, packages=['GeoffreyBot, GeoffreyBot.cogs'], - install_requires=['git+https://github.com/Rapptz/discord.py@rewrite', 'requests'], + install_requires=['discord.py', 'requests'], long_description=open('README').read(), )