Conversation
Fix Pipfile dependencies
| self.bot = bot | ||
|
|
||
| @staticmethod | ||
| def snake_url(name) -> str: |
| 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 |
There was a problem hiding this comment.
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"]) |
There was a problem hiding this comment.
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') |
lemonsaurus
left a comment
There was a problem hiding this comment.
A couple of things here to look at, but it could be worse. Looking forward to the finished product.
| "72eb2aa" = {file = "https://github.com/Rapptz/discord.py/archive/rewrite.zip"} | ||
| aiodns = "*" | ||
| aiohttp = "<2.3.0,>=2.0.0" | ||
| aiohttp = "*" |
There was a problem hiding this comment.
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())) |
There was a problem hiding this comment.
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=query&prop=extracts|pageimages&exintro=&explaintext=&titles={}&redirects=1" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
| self.bot = bot | ||
|
|
||
| @staticmethod | ||
| def snake_url(name) -> str: |
| 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 |
There was a problem hiding this comment.
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!", |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
other teams seem to have found a way not to return maps. :P
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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]) |
There was a problem hiding this comment.
didn't you already strip out the newlines when you created SNAKES?
| "72eb2aa" = {file = "https://github.com/Rapptz/discord.py/archive/rewrite.zip"} | ||
| aiodns = "*" | ||
| aiohttp = "<2.3.0,>=2.0.0" | ||
| aiohttp = "==2.0.0" |
| @@ -1,11 +1,39 @@ | |||
| # coding=utf-8 | |||
|
|
|||
| import async_timeout | |||
There was a problem hiding this comment.
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)""" |
There was a problem hiding this comment.
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]: |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): | ||
|
|
There was a problem hiding this comment.
You're missing a docstring here.
| bot.load_extension("bot.cogs.snakes") | ||
|
|
||
| bot.run(os.environ.get("BOT_TOKEN")) | ||
| #bot.run('bot token goes here for testing') |
There was a problem hiding this comment.
You should remove this line.
There was a problem hiding this comment.
We explained exactly how this works in the docs.
| wikipedia | ||
| help | ||
| wikipedia | ||
| help |
There was a problem hiding this comment.
Should these be in there?
| wutu | ||
| yarara | ||
| list of snakes | ||
| list of reptiles |
There was a problem hiding this comment.
I imagine these listing pages don't need to be here either
| @@ -0,0 +1,150 @@ | |||
| # coding=utf-8 | |||
There was a problem hiding this comment.
Why is there another snakes solution file here? I'm not going to review both - pick one and work on it together
|
|
||
| bot.run(os.environ.get("BOT_TOKEN")) | ||
| #bot.run(os.environ.get("BOT_TOKEN")) | ||
| bot.run('NDE0MDk5NTIyOTMxNzg1NzI4.DZiQjA.3eA2gcYy6D8KI8IhSfCr87oDePc') |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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