Conversation
… more testing but not code.
gdude2002
left a comment
There was a problem hiding this comment.
I see no changes here - did you forget to push?
commit ba5705b8e9e18d9f8a541dee446da21002853d37
Author: TildeBeta <tildebetabot@gmail.com>
Date: Sun Mar 25 14:57:00 2018 +0300
Flake8 fixes and special case handling
commit 051952e
Author: TildeBeta <tildebetabot@gmail.com>
Date: Sun Mar 25 01:01:39 2018 +0200
Fix disambiguator, create a mock embed
commit d0d944f
Author: TildeBeta <tildebetabot@gmail.com>
Date: Sun Mar 25 00:25:25 2018 +0200
Fix up malformed data
commit d8d9894
Author: TildeBeta <tildebetabot@gmail.com>
Date: Sat Mar 24 20:09:42 2018 +0200
Redundant set cast
commit 0984643
Author: TildeBeta <tildebetabot@gmail.com>
Date: Sat Mar 24 19:33:29 2018 +0200
Improve disambiguation
commit 2124795
Author: TildeBeta <tildebetabot@gmail.com>
Date: Sat Mar 24 15:26:55 2018 +0200
Paginate results instead of posting a massive block
commit c6112d5
Author: TildeBeta <tildebetabot@gmail.com>
Date: Sat Mar 24 14:29:41 2018 +0200
Improve snake name matching
[UPDATE] Ignored a silly rule from flake8.
|
so does it work now? |
|
flake8 error fixed |
bot/cogs/snakes.py
Outdated
| """ | ||
| snake_info = {} | ||
| # python (programming language) pageid = 23862 | ||
| URL = "https://en.wikipedia.org/w/api.php?" |
There was a problem hiding this comment.
Constants should probably be at module-level?
bot/cogs/snakes.py
Outdated
| PAGE_ID_URL = f"{URL}{FORMAT}&{ACTION}&{LIST}&{SRSEARCH}{name}&{UTF8}&{SRLIMIT}" | ||
|
|
||
| async with aiohttp.ClientSession() as session: | ||
| j = await self.fetch(session, PAGE_ID_URL) |
There was a problem hiding this comment.
Not a fan of one-letter variable names.
bot/cogs/snakes.py
Outdated
| '.svg', | ||
| 'ange.', | ||
| 'Adder%20(PSF).png' | ||
| ] |
There was a problem hiding this comment.
These are hilariously arbitrary. What's up? :P
There was a problem hiding this comment.
Wikipedia has arbitrary images on their snake pages ¯\_(ツ)_/¯
bot/cogs/snakes.py
Outdated
| 'Adder%20(PSF).png' | ||
| ] | ||
| for image in snake_info["images"]: | ||
| i = image["title"].split(':')[1].replace(" ", "%20") |
There was a problem hiding this comment.
Again, I don't love these one-letter variable names
| title=data['title'], | ||
| description=match.group(1) if match else None, | ||
| url=data['fullurl'], | ||
| colour=0x59982F |
There was a problem hiding this comment.
What colour is this? Is it not included in the discord.Colour class as a staticmethod?
There was a problem hiding this comment.
No it's just a random green I found online
| return commands.check(predicate) | ||
|
|
||
|
|
||
| def locked(): |
There was a problem hiding this comment.
Can you comment this? It's not obvious what it does
lemonsaurus
left a comment
There was a problem hiding this comment.
some minor change requests
bot/cogs/snakes.py
Outdated
| PAGE_ID_URL = f"{URL}{FORMAT}&{ACTION}&{LIST}&{SRSEARCH}{name}&{UTF8}&{SRLIMIT}" | ||
|
|
||
| async with aiohttp.ClientSession() as session: | ||
| j = await self.fetch(session, PAGE_ID_URL) |
There was a problem hiding this comment.
j is not acceptable as a variable name for this.
bot/cogs/snakes.py
Outdated
| try: | ||
| PAGEID = j["query"]["search"][0]["pageid"] | ||
| except KeyError: | ||
| PAGEID = 41118 |
There was a problem hiding this comment.
this could use a comment, what the hell is it
bot/cogs/snakes.py
Outdated
| 'Adder%20(PSF).png' | ||
| ] | ||
| for image in snake_info["images"]: | ||
| i = image["title"].split(':')[1].replace(" ", "%20") |
There was a problem hiding this comment.
this line is far too dense, and i is another awful variable name.
bot/cogs/snakes.py
Outdated
| if not i.startswith('Map'): | ||
| for b in banned: | ||
| image_banned = False | ||
| if b in i: |
There was a problem hiding this comment.
and this line pretty much perfectly illustrates why single letter variables suck.
| return commands.check(predicate) | ||
|
|
||
|
|
||
| def locked(): |
There was a problem hiding this comment.
please docstring the decorators as well. I shouldn't have to study this to figure out what that decorator does. (I don't think it's immediately obvious from the name, either)
bot/cogs/snakes.py
Outdated
| '.svg', | ||
| 'ange.', | ||
| 'Adder%20(PSF).png' | ||
| ] |
There was a problem hiding this comment.
please be consistent about this style choice. Later on you're using the convention that looks like this:
var = (
"contents"
)This is the style used in all of our open source projects, so we would prefer if you used this style here as well.
Zwork101
left a comment
There was a problem hiding this comment.
Amazing work! You seem to like to have hard coded values and urls in your function. I would move that right next to you regex compiles. Other then that, great bot! See you next code jam!
| def __init__(self, bot: AutoShardedBot): | ||
| self.bot = bot | ||
|
|
||
| async def get_snek(self, name: str = None) -> Dict[str, Any]: |
There was a problem hiding this comment.
Why remove what it returns? That's great documenting!
| """ | ||
| Go online and fetch information about a snake | ||
| async with aiohttp.ClientSession() as session: | ||
| params = { |
There was a problem hiding this comment.
These don't have to be defined each time it's called, maybe class property?
|
|
||
| # constructing dict - handle exceptions later | ||
| try: | ||
| snake_info["title"] = json["query"]["pages"][f"{pageid}"]["title"] |
There was a problem hiding this comment.
Use loops! That would clean up this hunk of code
| thumb_list = [] | ||
|
|
||
| # Wikipedia has arbitrary images that are not snakes | ||
| banned = [ |
There was a problem hiding this comment.
Once again, hard coded lists should be moved to somewhere such as a class variable
| for image in snake_info["images"]: | ||
| # images come in the format of `File:filename.extension` | ||
| file, sep, filename = image["title"].partition(':') | ||
| filename = filename.replace(" ", "%20") # Wikipedia returns good data! |
|
|
||
| embed.set_footer(text='Powered by Wikipedia') | ||
|
|
||
| emoji = 'https://emojipedia-us.s3.amazonaws.com/thumbs/60/google/3/snake_1f40d.png' |
There was a problem hiding this comment.
Yak! Hard coded value inside the function again. Same issue as the list and dicts.
… more testing but not code.