★ wanayoo — archive 1999 https://github.com/python-discord/code-jam-1/pull/16Nouvelle recherche | Portail wanayoo
Skip to content
This repository has been archived by the owner. It is now read-only.

Team 20 #16

Open
wants to merge 41 commits into
base: master
from
Open

Team 20 #16

wants to merge 41 commits into from

Conversation

@isik-kaplan
Copy link

@isik-kaplan isik-kaplan commented Mar 24, 2018

Write some gibberish -Bisk 24.03.2018

@isik-kaplan isik-kaplan changed the title I don't know what to write Team 20 Mar 24, 2018
Copy link

@schwartzadev schwartzadev left a comment •

this looks good!
I would check on the Travis CI report and fix the changes that the linter found

@@ -15,31 +38,67 @@ class Snakes:
def __init__(self, bot: AutoShardedBot):
self.bot = bot

@staticmethod
def snake_url(name) -> str:

This comment has been minimized.

@schwartzadev

schwartzadev Mar 24, 2018 •

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

This comment has been minimized.

@schwartzadev

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...

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"])

This comment has been minimized.

@schwartzadev

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"
)
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')

This comment has been minimized.

@schwartzadev

schwartzadev Mar 24, 2018

How does this run properly?

Copy link
Member

@lemonsaurus lemonsaurus left a comment

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 = "*"

This comment has been minimized.

@lemonsaurus

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.

"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()))

This comment has been minimized.

@lemonsaurus

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.

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>

This comment has been minimized.

@lemonsaurus

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.

from discord import Embed

import aiohttp
import json

This comment has been minimized.

@lemonsaurus

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?

@@ -15,31 +38,67 @@ class Snakes:
def __init__(self, bot: AutoShardedBot):
self.bot = bot

@staticmethod
def snake_url(name) -> str:

This comment has been minimized.

@lemonsaurus

lemonsaurus Mar 24, 2018
Member

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

This comment has been minimized.

@lemonsaurus

lemonsaurus Mar 24, 2018
Member

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!",

This comment has been minimized.

@lemonsaurus

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!"),
# 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"

This comment has been minimized.

@lemonsaurus

lemonsaurus Mar 24, 2018
Member

other teams seem to have found a way not to return maps. :P

This comment has been minimized.

@kingdom5500

kingdom5500 Mar 24, 2018

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()

This comment has been minimized.

@lemonsaurus

lemonsaurus Mar 24, 2018
Member

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])

This comment has been minimized.

@lemonsaurus

lemonsaurus Mar 24, 2018
Member

didn't you already strip out the newlines when you created SNAKES?

isik-kaplan and others added 15 commits Mar 24, 2018
kingdom5500
[UPDATE] Ignored a silly rule from flake8.
kingdom5500
This reverts commit a626e56.
This reverts commit a626e56.
kingdom5500
@@ -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"

This comment has been minimized.

@gdude2002

gdude2002 Mar 25, 2018
Contributor

Why?

@@ -1,11 +1,39 @@
# coding=utf-8

import async_timeout

This comment has been minimized.

@gdude2002

gdude2002 Mar 25, 2018
Contributor

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)"""

This comment has been minimized.

@gdude2002

gdude2002 Mar 25, 2018
Contributor

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]:

This comment has been minimized.

@gdude2002

gdude2002 Mar 25, 2018
Contributor

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):

This comment has been minimized.

@gdude2002

gdude2002 Mar 25, 2018
Contributor

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):

This comment has been minimized.

@gdude2002

gdude2002 Mar 25, 2018
Contributor

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')

This comment has been minimized.

@gdude2002

gdude2002 Mar 25, 2018
Contributor

You should remove this line.

This comment has been minimized.

@gdude2002

gdude2002 Mar 25, 2018
Contributor

We explained exactly how this works in the docs.

snakes.txt Outdated
wikipedia
help
wikipedia
help

This comment has been minimized.

@gdude2002

gdude2002 Mar 25, 2018
Contributor

Should these be in there?

snakes.txt Outdated
wutu
yarara
list of snakes
list of reptiles

This comment has been minimized.

@gdude2002

gdude2002 Mar 25, 2018
Contributor

I imagine these listing pages don't need to be here either

snakes2.py Outdated
@@ -0,0 +1,150 @@
# coding=utf-8

This comment has been minimized.

@gdude2002

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

kingdom5500
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')

This comment has been minimized.

@gdude2002

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.

kingdom5500 added 3 commits Mar 25, 2018
kingdom5500
kingdom5500
kingdom5500
@@ -1,49 +0,0 @@
# coding=utf-8

This comment has been minimized.

@gdude2002

gdude2002 Mar 25, 2018
Contributor

Ya want to explain this? Why delete that file?

isik-kaplan and others added 7 commits Mar 25, 2018
kingdom5500
This reverts commit 8bb749d.
kingdom5500
@gdude2002
Copy link
Contributor

@gdude2002 gdude2002 commented Mar 25, 2018

You code is failing to lint. Please see Travis for more information.

kingdom5500 added 5 commits Mar 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.