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

Team 4 #5

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

Team 4 #5

wants to merge 11 commits into from

Conversation

Refisio
Copy link

@Refisio Refisio commented Mar 23, 2018

This will be updated as production starts and continues.

(PC) Refisio added 2 commits March 22, 2018 20:31
Exclude virtualenv from Flake8 linting. Again.
@gdude2002 gdude2002 changed the title Initial Pull Request Team 4 Mar 23, 2018
@@ -4,6 +4,8 @@

from discord.ext.commands import AutoShardedBot, Context, command

from .snakegame import SnakeGame
Copy link
Contributor

Choose a reason for hiding this comment

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

Relative imports are discouraged



def setup(bot):
bot.add_cog(Snakes(bot))
bot.add_cog(Snakes(bot, SnakeGame((5, 5))))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is quite weird - maybe you should instantiate it in the __init__ instead?

@@ -4,6 +4,8 @@

from discord.ext.commands import AutoShardedBot, Context, command

from .snakegame import SnakeGame
Copy link
Contributor

Choose a reason for hiding this comment

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

You also seem to be missing this file

RoberTnf and others added 7 commits March 23, 2018 10:52
First commit by Refisio to the PR. Wew lad.
Alright. Let's go.

- Set up the basis for pulling information from the MediaWiki API
- Set up the basis for the list that will be checked for command caching
- Took down some notes for continuing with the project in the morning. All of these are findable in the comments within the functions.
- Pretty much have the 'get_snek' function done. Just have a few things I would like to flesh out.
- Cleared the Wikipedia module from 'Pipfile' and 'Pipfile.lock'. Let's hope I didn't screw anything up with that one.
[UPDATE] Ignored a silly rule from flake8.
Adding W503 and E226 to flake8 ignore list.
Copy link
Contributor

@gdude2002 gdude2002 left a comment

Choose a reason for hiding this comment

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

Nice work so far!

# account for snakes without a page somewhere. >(PC)
async with ClientSession() as session:
async with session.get(url) as response:
resp = json.loads(str(await response.read(), '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.

Can't you just return await response.json()?

Copy link
Author

Choose a reason for hiding this comment

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

I keep getting a TypeError when trying that, so I decided to build it using "json.load()". I still works exactly as I would like it to, without all the TypeError stuff.

"usable_data = web_data['query']['pages'][0]['extract']
TypeError: 'generator' object is not subscriptable"

I also completely rewrote it, so while this is still there, it's not returning anything until it's actually done doing what it's supposed to do. You'll see it in the next commit in a little while, or below if you're invested enough.

image

if name.split(' '):
name = '%20'.join(name.split(' '))

# leaving off here for the evening. Building the embed is easy. Pulling the information is hard. /s >(PC)
Copy link
Contributor

Choose a reason for hiding this comment

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

So, build the embed. :P

Copy link
Author

Choose a reason for hiding this comment

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

image

@gdude2002
Copy link
Contributor

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

Copy link

@Zwork101 Zwork101 left a comment

Choose a reason for hiding this comment

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

Very nice, and some great ideas! Might want to look into becoming more pythonic (read pep8!). However clearly you guys know how to use python, evident from your code. Check out how to use the @property decorator. Other then that, great project! See you next code jam!


async with ClientSession() as session:
async with session.get(possible_names) as all_sneks:
resp = str(await all_sneks.read(), 'utf-8')
Copy link

Choose a reason for hiding this comment

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

What's the reason for specifying the encoding?

Copy link
Author

Choose a reason for hiding this comment

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

There was a problem with encoding when trying to change the read response to a string. Specification solved that.


# accounting for the spaces in the names of some snakes. Allows for parsing of spaced names. >(PC)
if name.split(' '):
name = '%20'.join(name.split(' '))
Copy link

Choose a reason for hiding this comment

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

Please use the urllib module for this operation

Copy link
Author

Choose a reason for hiding this comment

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

Could you specify which function of URLLib I should be using for this?


# Maybe one game at a given time, and maybe editing the original message instead of constantly posting
# new ones? Maybe we could also ask nicely for DMs to be allowed for this if they aren't. >(PC)
if order in self.movement_command.keys():
Copy link

Choose a reason for hiding this comment

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

I may be wrong, but it would appear that only 1 person can play at once, you should save the message author ID to a dict with their last time? I havn't played this game, so I may be misinterpreting it.

snekembed.add_field(name="Winner movement",
value="{dir}: {per:.2f}%".format(dir=direction, per=percentage))

snek_head = next(emoji for emoji in ctx.guild.emojis if emoji.name == 'python')
Copy link

Choose a reason for hiding this comment

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

Very clever usage of next, I like that. However this creates issues if the name is changed. Might want to make this optional.

"""

self.snake = Snake(positions=[[2, 2], [2, 1]])
self.putFood()
Copy link

Choose a reason for hiding this comment

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

This applies to all functions and variables, use

self.put_food()

Instead!


return move_status

def isLost(self):
Copy link

Choose a reason for hiding this comment

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

This should use python property decorator! So it would look like

@property
def lost(self):

Applies to other is functions too!

self.head[1] + velocity[1]]
self.positions.insert(0, self.head)

return "ok"
Copy link

Choose a reason for hiding this comment

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

It would be much nicer, if it returned a bool, or enum instead, this leads to less mistakes when developing.

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.

4 participants