From 7b55a6979f06cec29de7bc5fc20e1da2699467fc Mon Sep 17 00:00:00 2001 From: phxntxm Date: Thu, 5 Jan 2017 12:13:22 -0600 Subject: [PATCH 1/8] Changed the hangman description to reflect the current way phrases are chosen --- cogs/hangman.py | 3 +-- cogs/utils/config.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) 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/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 From 497bb5e963dbaf6d5e4aecd65c8725510849de81 Mon Sep 17 00:00:00 2001 From: Dan Hess Date: Fri, 6 Jan 2017 22:11:36 -0600 Subject: [PATCH 2/8] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From f31cafb3234a645877164b6ade886456cc0cb1c2 Mon Sep 17 00:00:00 2001 From: phxntxm Date: Tue, 17 Jan 2017 09:16:33 -0600 Subject: [PATCH 3/8] Updated the version over the overwatch API I was using, as v2 is outdated --- cogs/overwatch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/overwatch.py b/cogs/overwatch.py index 446b9b0..48b81e0 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 From 62972c620599e16e49ad5a7e7880e4a8e0e2a5d5 Mon Sep 17 00:00:00 2001 From: phxntxm Date: Tue, 17 Jan 2017 09:31:09 -0600 Subject: [PATCH 4/8] Updated code to work with the new OW API --- cogs/overwatch.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cogs/overwatch.py b/cogs/overwatch.py index 48b81e0..d874e00 100644 --- a/cogs/overwatch.py +++ b/cogs/overwatch.py @@ -76,24 +76,29 @@ 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)) output_data = [(k.title().replace("_", " "), r) for k, r in data['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) From 2c0b82967a5b606c3d23978eacee8ad0a203161b Mon Sep 17 00:00:00 2001 From: phxntxm Date: Tue, 17 Jan 2017 09:35:22 -0600 Subject: [PATCH 5/8] Updated code to work with the new OW API --- cogs/overwatch.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cogs/overwatch.py b/cogs/overwatch.py index d874e00..880f141 100644 --- a/cogs/overwatch.py +++ b/cogs/overwatch.py @@ -77,8 +77,10 @@ class Overwatch: if hero == "": # If no hero was provided, we just want the base stats for a player 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 From 07e34ddee3cc8590acf3cb5d0137e3dc0ec0d4c5 Mon Sep 17 00:00:00 2001 From: phxntxm Date: Tue, 17 Jan 2017 09:38:26 -0600 Subject: [PATCH 6/8] Updated code to work with the new OW API --- cogs/overwatch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/overwatch.py b/cogs/overwatch.py index 880f141..1365bfd 100644 --- a/cogs/overwatch.py +++ b/cogs/overwatch.py @@ -125,7 +125,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, " From e62589e78cb430507228eaaedb3ab86418fdb479 Mon Sep 17 00:00:00 2001 From: phxntxm Date: Tue, 17 Jan 2017 10:20:03 -0600 Subject: [PATCH 7/8] Setup an actual clientsession --- cogs/overwatch.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/cogs/overwatch.py b/cogs/overwatch.py index 1365bfd..6619838 100644 --- a/cogs/overwatch.py +++ b/cogs/overwatch.py @@ -26,25 +26,26 @@ class Overwatch: self.headers = {"User-Agent": config.user_agent} self.session = aiohttp.ClientSession() - async def _request(self, payload, endpoint): - """Handles requesting to the API""" +async def _request(self, payload, endpoint): + """Handles requesting to the API""" - # Format the URL we'll need based on the base_url, and the endpoint we want to hit - url = "{}{}".format(base_url, endpoint) + # Format the URL we'll need based on the base_url, and the endpoint we want to hit + url = "{}{}".format(base_url, endpoint) - # 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: + # Attempt to connect up to our max retries + for x in range(MAX_RETRIES): + try: + 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 - # If any error happened when making the request, attempt again - except: - continue + # If any error happened when making the request, attempt again + except: + continue @commands.group(no_pm=True) async def ow(self): From ae406a736d4cf53f162412d8ddaee48df72e4bef Mon Sep 17 00:00:00 2001 From: phxntxm Date: Tue, 17 Jan 2017 10:23:07 -0600 Subject: [PATCH 8/8] Corrected an indentation error --- cogs/overwatch.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/cogs/overwatch.py b/cogs/overwatch.py index 6619838..3680f8b 100644 --- a/cogs/overwatch.py +++ b/cogs/overwatch.py @@ -26,26 +26,26 @@ class Overwatch: self.headers = {"User-Agent": config.user_agent} self.session = aiohttp.ClientSession() -async def _request(self, payload, endpoint): - """Handles requesting to the API""" + async def _request(self, payload, endpoint): + """Handles requesting to the API""" - # Format the URL we'll need based on the base_url, and the endpoint we want to hit - url = "{}{}".format(base_url, endpoint) + # Format the URL we'll need based on the base_url, and the endpoint we want to hit + url = "{}{}".format(base_url, endpoint) - # Attempt to connect up to our max retries - for x in range(MAX_RETRIES): - try: - 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 + # Attempt to connect up to our max retries + for x in range(MAX_RETRIES): + try: + 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 - # If any error happened when making the request, attempt again - except: - continue + data = await r.json() + return data + # If any error happened when making the request, attempt again + except: + continue @commands.group(no_pm=True) async def ow(self):