diff --git a/README.md b/README.md index 24ecdc6..6202d64 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,9 @@ https://www.rethinkdb.com/docs/install/ I also use a few libraries that aren't included by default, which can be installed using pip. ``` -python3.5 -m pip install rethinkdb pendulum ruamel.yaml BeautifulSoup4 Pillow==3.4.1 +python3.5 -m pip install discord.py[voice] lxml fuzzywuzzy youtube_dl rethinkdb ruamel.yaml pendulum Pillow==3.4.1 readline # Or on windows -py -3 -m pip install rethinkdb pendulum ruamel.yaml BeautifulSoup4 Pillow==3.4.1 +py -3 -m pip install discord.py[voice] lxml fuzzywuzzy youtube_dl rethinkdb ruamel.yaml pendulum Pillow==3.4.1 readline ``` Note: ATM of writing this, Pillow 3.4.2 (the stable version...good job Pillow?) is broken, do not use pip's default to install this. This is why we're using Pillow==3.4.1 above, and not just Pillow diff --git a/cogs/hangman.py b/cogs/hangman.py index 09300cd..9a188b3 100644 --- a/cogs/hangman.py +++ b/cogs/hangman.py @@ -156,8 +156,7 @@ class Hangman: @checks.custom_perms(send_messages=True) async def create_hangman(self, ctx): """This is used to create a new hangman game - Due to the fact that I might not be able to delete a message, I will PM you and ask for the phrase you want. - The phrase needs to be under 30 characters + A predefined phrase will be randomly chosen as the phrase to use EXAMPLE: !hangman start RESULT: This is pretty obvious .-.""" diff --git a/cogs/overwatch.py b/cogs/overwatch.py index 446b9b0..3680f8b 100644 --- a/cogs/overwatch.py +++ b/cogs/overwatch.py @@ -7,7 +7,7 @@ import discord import aiohttp -base_url = "https://api.owapi.net/api/v2/u/" +base_url = "https://api.owapi.net/api/v3/u/" # This is a list of the possible things that we may want to retrieve from the stats # The API returns something if it exists, and leaves it out of the data returned entirely if it does not # For example if you have not won with a character, wins will not exist in the list @@ -35,13 +35,14 @@ class Overwatch: # Attempt to connect up to our max retries for x in range(MAX_RETRIES): try: - async with aiohttp.ClientSession().get(url, headers=self.headers, params=payload) as r: - # If we failed to connect, attempt again - if r.status != 200: - continue + async with aiohttp.ClientSession(headers=self.headers) as session: + async with session.get(url, params=payload) as r: + # If we failed to connect, attempt again + if r.status != 200: + continue - data = await r.json() - return data + data = await r.json() + return data # If any error happened when making the request, attempt again except: continue @@ -76,24 +77,31 @@ class Overwatch: if hero == "": # If no hero was provided, we just want the base stats for a player - data = await self._request(None, "{}/stats/general".format(bt)) + data = await self._request(None, "{}/stats".format(bt)) + region = [x for x in data.keys() if data[x] is not None][0] + stats = data[region]['stats']['quickplay'] - output_data = [(k.title().replace("_", " "), r) for k, r in data['game_stats'].items() if + output_data = [(k.title().replace("_", " "), r) for k, r in stats['game_stats'].items() if k in check_g_stats] else: # If there was a hero provided, search for a user's data on that hero - endpoint = "{}/heroes/{}".format(bt, hero.lower().replace('-', '')) + hero = hero.lower().replace('-', '') + endpoint = "{}/heroes".format(bt) data = await self._request(None, endpoint) - if data is None: + + region = [x for x in data.keys() if data[x] is not None][0] + stats = data[region]['heroes']['stats']['quickplay'].get(hero) + + if stats is None: fmt = "I couldn't find data with that hero, make sure that is a valid hero, " \ "otherwise {} has never used the hero {} before!".format(user.display_name, hero) await self.bot.say(fmt) return # Same list comprehension as before - output_data = [(k.title().replace("_", " "), r) for k, r in data['general_stats'].items() if + output_data = [(k.title().replace("_", " "), r) for k, r in stats['general_stats'].items() if k in check_g_stats] - for k, r in data['hero_stats'].items(): + for k, r in stats['hero_stats'].items(): output_data.append((k.title().replace("_", " "), r)) try: banner = await images.create_banner(user, "Overwatch", output_data) @@ -118,7 +126,7 @@ class Overwatch: await self.bot.say("Looking up your profile information....") # All we're doing here is ensuring that the status is 200 when looking up someone's general information # If it's not, let them know exactly how to format their tag - endpoint = "{}/stats/general".format(bt) + endpoint = "{}/stats".format(bt) data = await self._request(None, endpoint) if data is None: await self.bot.say("Profile does not exist! Battletags are picky, " diff --git a/cogs/utils/config.py b/cogs/utils/config.py index fc6b64e..b1c139b 100644 --- a/cogs/utils/config.py +++ b/cogs/utils/config.py @@ -73,7 +73,7 @@ shard_count = global_config.get('shard_count', 1) shard_id = global_config.get('shard_id', 0) # The default status the bot will use -default_status = global_config.get("default_status", "") +default_status = global_config.get("default_status", None) # The URL that will be used to link to for the help command help_url = global_config.get("help_url", "") # The rethinkdb hostname