-
-
Notifications
You must be signed in to change notification settings - Fork 16
Team 20 #16
base: master
Are you sure you want to change the base?
Team 20 #16
Conversation
Fix Pipfile dependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks good!
I would check on the Travis CI report and fix the changes that the linter found
bot/cogs/snakes.py
Outdated
@@ -15,31 +38,67 @@ class Snakes: | |||
def __init__(self, bot: AutoShardedBot): | |||
self.bot = bot | |||
|
|||
@staticmethod | |||
def snake_url(name) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type hint name
here
bot/cogs/snakes.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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...
bot/cogs/snakes.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"
)
run.py
Outdated
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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this run properly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of things here to look at, but it could be worse. Looking forward to the finished product.
Pipfile
Outdated
@@ -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 = "*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any particular reason this was done? discord.py doesn't like the latest aiohttp, we locked the version for a reason.
bot/cogs/snakes.py
Outdated
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 itline
. this isn't code golf.
bot/cogs/snakes.py
Outdated
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line is 140 characters. it's not gonna pass linting and it's just not okay to do even if it did.
bot/cogs/snakes.py
Outdated
from discord import Embed | ||
|
||
import aiohttp | ||
import json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
bot/cogs/snakes.py
Outdated
@@ -15,31 +38,67 @@ class Snakes: | |||
def __init__(self, bot: AutoShardedBot): | |||
self.bot = bot | |||
|
|||
@staticmethod | |||
def snake_url(name) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name
should be typehinted.
bot/cogs/snakes.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returning a dictionary literal seems fine. this comment, however, does not.
bot/cogs/snakes.py
Outdated
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!"),
bot/cogs/snakes.py
Outdated
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
other teams seem to have found a way not to return maps. :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed they have, but we aren't other teams :D
bot/cogs/snakes.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's no two letter maxlimit on variable names. what's wrong with embed = Embed()
?
bot/cogs/snakes.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
bot/cogs/snakes.py
Outdated
@@ -1,11 +1,39 @@ | |||
# coding=utf-8 | |||
|
|||
import async_timeout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't declared in your Pipfile.
bot/cogs/snakes.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand - what is this supposed to be doing, and why?
bot/cogs/snakes.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of upper()
ing all the names every time you do this, maybe they could be stored that way?
bot/cogs/snakes.py
Outdated
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just with aiohttp.Timeout(10):
?
bot/cogs/snakes.py
Outdated
""" | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're missing a docstring here.
run.py
Outdated
@@ -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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should remove this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We explained exactly how this works in the docs.
snakes.txt
Outdated
wikipedia | ||
help | ||
wikipedia | ||
help |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be in there?
snakes.txt
Outdated
wutu | ||
yarara | ||
list of snakes | ||
list of reptiles |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine these listing pages don't need to be here either
snakes2.py
Outdated
@@ -0,0 +1,150 @@ | |||
# coding=utf-8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there another snakes solution file here? I'm not going to review both - pick one and work on it together
run.py
Outdated
@@ -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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
bot/cogs/snakes.py
Outdated
@@ -1,49 +0,0 @@ | |||
# coding=utf-8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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