Team 20 #16
Team 20 #16
Conversation
Fix Pipfile dependencies
|
this looks good! |
| @@ -15,31 +38,67 @@ class Snakes: | |||
| def __init__(self, bot: AutoShardedBot): | |||
| self.bot = bot | |||
|
|
|||
| @staticmethod | |||
| def snake_url(name) -> str: | |||
schwartzadev
Mar 24, 2018
•
type hint name here
type hint name here
| thumb = content.get("thumbnail", {}).get("source", "http://i.imgur.com/HtIPyLy.png/beep") | ||
| image = "/".join(thumb.replace("thumb/", "").split("/")[:-1]) | ||
|
|
||
| # WHY WOULD YOU USE DICTIONARY LITERAL IN A RETURN STATEMENT but okay lol |
schwartzadev
Mar 24, 2018
this seems fine from the way you've done this - not sure I have any qualms with it but maybe consider making a class for this return object...
this seems fine from the way you've done this - not sure I have any qualms with it but maybe consider making a class for this return object...
| em = Embed() | ||
| em.title = content["name"] | ||
| em.description = content["info"][:1970] + "\n\nPS. If the image is a fucking map, blame wikipedia. -Somejuan" | ||
| em.set_image(url=content["image"]) |
schwartzadev
Mar 24, 2018
some of this can be more concise:
embed=discord.Embed(
title=content["name"],
description=content["info"][:1970] + "\n\nPS. If the image is a fucking map, blame wikipedia. -Somejuan"
)
some of this can be more concise:
embed=discord.Embed(
title=content["name"],
description=content["info"][:1970] + "\n\nPS. If the image is a fucking map, blame wikipedia. -Somejuan"
)| bot.run(os.environ.get("BOT_TOKEN")) | ||
| #bot.run(os.environ.get("BOT_TOKEN")) | ||
| # I SWEAR TO GOD, HONESTLY WATCH ME LEAVE THIS TOKEN IN LMAO | ||
| bot.run('BOT TOKEN') |
schwartzadev
Mar 24, 2018
How does this run properly?
How does this run properly?
|
A couple of things here to look at, but it could be worse. Looking forward to the finished product. |
| @@ -6,8 +6,9 @@ name = "pypi" | |||
| [packages] | |||
| "72eb2aa" = {file = "https://github.com/Rapptz/discord.py/archive/rewrite.zip"} | |||
| aiodns = "*" | |||
| aiohttp = "<2.3.0,>=2.0.0" | |||
| aiohttp = "*" | |||
lemonsaurus
Mar 24, 2018
Member
any particular reason this was done? discord.py doesn't like the latest aiohttp, we locked the version for a reason.
any particular reason this was done? discord.py doesn't like the latest aiohttp, we locked the version for a reason.
| "image": "https://www.python.org/static/community_logos/python-logo-master-v3-TM-flattened.png" | ||
| } | ||
| with open("bot/snakes.txt") as file: | ||
| SNAKES = list(map(lambda ln: ln.strip('\n'), file.readlines())) |
lemonsaurus
Mar 24, 2018
Member
I don't even know where to begin with this line.
- don't use map and lambdas, use list comps. this isn't Python 1.0.
- a simple
ln.strip() will also remove newlines (and spaces) from the start and end. why even specify the \n?
- don't call the file variable
file, that's a python 2 builtin which means syntax highlighting looks funky in most editors.
ln is a shitty variable name. just call it line. this isn't code golf.
I don't even know where to begin with this line.
- don't use map and lambdas, use list comps. this isn't Python 1.0.
- a simple
ln.strip()will also remove newlines (and spaces) from the start and end. why even specify the\n? - don't call the file variable
file, that's a python 2 builtin which means syntax highlighting looks funky in most editors. lnis a shitty variable name. just call itline. this isn't code golf.
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
| # Probably should move these somewhere | ||
| BASEURL = "https://en.wikipedia.org/w/api.php?format=json&action=/old?u=https%3A%2F%2Fgithub.com%2Fpython-discord%2Fcode-jam-1%2Fpull%2Fquery%26amp%3Bprop%3Dextracts%7Cpageimages%26amp%3Bexintro%3D%26amp%3Bexplaintext%3D%26amp%3Btitles%3D%7B%7D%26amp%3Bredirects%3D1%26quot%3B%3C%2Fspan&y=1999> |
lemonsaurus
Mar 24, 2018
Member
this line is 140 characters. it's not gonna pass linting and it's just not okay to do even if it did.
this line is 140 characters. it's not gonna pass linting and it's just not okay to do even if it did.
| from discord import Embed | ||
|
|
||
| import aiohttp | ||
| import json |
lemonsaurus
Mar 24, 2018
Member
these imports aren't gonna pass linting. wrong import orders and groupings. you should fix them so they are PEP8 compliant. Why aren't you guys using flake8?
these imports aren't gonna pass linting. wrong import orders and groupings. you should fix them so they are PEP8 compliant. Why aren't you guys using flake8?
| @@ -15,31 +38,67 @@ class Snakes: | |||
| def __init__(self, bot: AutoShardedBot): | |||
| self.bot = bot | |||
|
|
|||
| @staticmethod | |||
| def snake_url(name) -> str: | |||
lemonsaurus
Mar 24, 2018
Member
name should be typehinted.
name should be typehinted.
| thumb = content.get("thumbnail", {}).get("source", "http://i.imgur.com/HtIPyLy.png/beep") | ||
| image = "/".join(thumb.replace("thumb/", "").split("/")[:-1]) | ||
|
|
||
| # WHY WOULD YOU USE DICTIONARY LITERAL IN A RETURN STATEMENT but okay lol |
lemonsaurus
Mar 24, 2018
Member
returning a dictionary literal seems fine. this comment, however, does not.
returning a dictionary literal seems fine. this comment, however, does not.
| # WHY WOULD YOU USE DICTIONARY LITERAL IN A RETURN STATEMENT but okay lol | ||
| return { | ||
| "name": content["title"], | ||
| "info": content.get("extract", "") or "I don't know about that snake!", |
lemonsaurus
Mar 24, 2018
Member
don't do this. the second param of .get is what to return if the get fails.
"info": content.get("extract", "I don't know about that snake!"),
don't do this. the second param of .get is what to return if the get fails.
"info": content.get("extract", "I don't know about that snake!"),| # Just a temporary thing to make sure it's working | ||
| em = Embed() | ||
| em.title = content["name"] | ||
| em.description = content["info"][:1970] + "\n\nPS. If the image is a fucking map, blame wikipedia. -Somejuan" |
lemonsaurus
Mar 24, 2018
Member
other teams seem to have found a way not to return maps. :P
other teams seem to have found a way not to return maps. :P
kingdom5500
Mar 24, 2018
Indeed they have, but we aren't other teams :D
Indeed they have, but we aren't other teams :D
| should be sent back to Discord in an embed. | ||
| content = await self.get_snek(name) | ||
| # Just a temporary thing to make sure it's working | ||
| em = Embed() |
lemonsaurus
Mar 24, 2018
Member
there's no two letter maxlimit on variable names. what's wrong with embed = Embed()?
there's no two letter maxlimit on variable names. what's wrong with embed = Embed()?
| Go online and fetch information about a snake | ||
| """Get a snake with a given name, or otherwise randomly""" | ||
| if name is None: | ||
| name = random.choice([x.strip('\n') for x in SNAKES]) |
lemonsaurus
Mar 24, 2018
Member
didn't you already strip out the newlines when you created SNAKES?
didn't you already strip out the newlines when you created SNAKES?
| @@ -6,8 +6,9 @@ name = "pypi" | |||
| [packages] | |||
| "72eb2aa" = {file = "https://github.com/Rapptz/discord.py/archive/rewrite.zip"} | |||
| aiodns = "*" | |||
| aiohttp = "<2.3.0,>=2.0.0" | |||
| aiohttp = "==2.0.0" | |||
gdude2002
Mar 25, 2018
Contributor
Why?
Why?
| @@ -1,11 +1,39 @@ | |||
| # coding=utf-8 | |||
|
|
|||
| import async_timeout | |||
gdude2002
Mar 25, 2018
Contributor
This isn't declared in your Pipfile.
This isn't declared in your Pipfile.
| Go online and fetch information about a snake | ||
| @staticmethod | ||
| def parse_kwarg(kwarg: str): | ||
| """Return the value of a kwarg (needs manual assignment)""" |
gdude2002
Mar 25, 2018
Contributor
I don't understand - what is this supposed to be doing, and why?
I don't understand - what is this supposed to be doing, and why?
| return BASEURL.format(urllib.parse.quote_plus(text)) | ||
|
|
||
| # Check if the snake name is valid | ||
| if name.upper() in [name.upper() for name in SNAKES]: |
gdude2002
Mar 25, 2018
Contributor
Instead of upper()ing all the names every time you do this, maybe they could be stored that way?
Instead of upper()ing all the names every time you do this, maybe they could be stored that way?
| @staticmethod | ||
| async def fetch(session, url: str): | ||
| """Fetch the contents of a URL as a json""" | ||
| async with async_timeout.timeout(10): |
gdude2002
Mar 25, 2018
Contributor
Why not just with aiohttp.Timeout(10):?
Why not just with aiohttp.Timeout(10):?
| """ | ||
| Go online and fetch information about a snake | ||
| async def get(self, ctx: Context, name: str = None, autocorrect: str = None, details: str = None): | ||
|
|
gdude2002
Mar 25, 2018
Contributor
You're missing a docstring here.
You're missing a docstring here.
| @@ -36,5 +36,6 @@ | |||
| bot.load_extension("bot.cogs.snakes") | |||
|
|
|||
| bot.run(os.environ.get("BOT_TOKEN")) | |||
| #bot.run('bot token goes here for testing') | |||
gdude2002
Mar 25, 2018
Contributor
You should remove this line.
You should remove this line.
gdude2002
Mar 25, 2018
Contributor
We explained exactly how this works in the docs.
We explained exactly how this works in the docs.
| wikipedia | ||
| help | ||
| wikipedia | ||
| help |
gdude2002
Mar 25, 2018
Contributor
Should these be in there?
Should these be in there?
| wutu | ||
| yarara | ||
| list of snakes | ||
| list of reptiles |
gdude2002
Mar 25, 2018
Contributor
I imagine these listing pages don't need to be here either
I imagine these listing pages don't need to be here either
| @@ -0,0 +1,150 @@ | |||
| # coding=utf-8 | |||
gdude2002
Mar 25, 2018
Contributor
Why is there another snakes solution file here? I'm not going to review both - pick one and work on it together
Why is there another snakes solution file here? I'm not going to review both - pick one and work on it together
| @@ -35,6 +35,7 @@ | |||
| # Commands, etc | |||
| bot.load_extension("bot.cogs.snakes") | |||
|
|
|||
| bot.run(os.environ.get("BOT_TOKEN")) | |||
| #bot.run(os.environ.get("BOT_TOKEN")) | |||
| bot.run('NDE0MDk5NTIyOTMxNzg1NzI4.DZiQjA.3eA2gcYy6D8KI8IhSfCr87oDePc') | |||
gdude2002
Mar 25, 2018
Contributor
You've committed your bot token to the repository. Go to you bot's application page, invalidate the token, and then read over the bot setup guide again - add your token to the .env file like we described, and return this line to how it was when we gave it to you.
You've committed your bot token to the repository. Go to you bot's application page, invalidate the token, and then read over the bot setup guide again - add your token to the .env file like we described, and return this line to how it was when we gave it to you.
| @@ -1,49 +0,0 @@ | |||
| # coding=utf-8 | |||
gdude2002
Mar 25, 2018
Contributor
Ya want to explain this? Why delete that file?
Ya want to explain this? Why delete that file?
|
You code is failing to lint. Please see Travis for more information. |
Write some gibberish -Bisk 24.03.2018