Skip to content
This repository was archived by the owner on Mar 14, 2021. It is now read-only.

Team 20 #16

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open

Team 20 #16

wants to merge 41 commits into from

Conversation

isik-kaplan
Copy link

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

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

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

@staticmethod
def snake_url(name) -> str:
Copy link

@schwartzadev schwartzadev Mar 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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

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

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

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?

Copy link
Member

@lemonsaurus lemonsaurus left a 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 = "*"
Copy link
Member

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.

"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()))
Copy link
Member

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 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=query&prop=extracts|pageimages&exintro=&explaintext=&titles={}&redirects=1"
Copy link
Member

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.

from discord import Embed

import aiohttp
import json
Copy link
Member

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?

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

@staticmethod
def snake_url(name) -> str:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

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.

# 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!",
Copy link
Member

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

# 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"
Copy link
Member

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

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

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()
Copy link
Member

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

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])
Copy link
Member

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

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

import async_timeout
Copy link
Contributor

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.

Go online and fetch information about a snake
@staticmethod
def parse_kwarg(kwarg: str):
"""Return the value of a kwarg (needs manual assignment)"""
Copy link
Contributor

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?

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]:
Copy link
Contributor

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?

@staticmethod
async def fetch(session, url: str):
"""Fetch the contents of a URL as a json"""
async with async_timeout.timeout(10):
Copy link
Contributor

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

"""
Go online and fetch information about a snake
async def get(self, ctx: Context, name: str = None, autocorrect: str = None, details: str = None):

Copy link
Contributor

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')
Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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')
Copy link
Contributor

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.

@@ -1,49 +0,0 @@
# coding=utf-8
Copy link
Contributor

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?

@gdude2002
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants