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

Team 8 #4

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

Team 8 #4

wants to merge 59 commits into from

Conversation

biskette
Copy link

The stuff 'n' that.


# Any additional commands can be placed here. Be creative, but keep it to a reasonable amount!


def setup(bot):
bot.add_cog(Snakes(bot))
log.info("Cog loaded: Snakes")
bot.loop.create_task(Snakes(bot).cache_snakelist())
Copy link
Member

@jb3 jb3 Mar 24, 2018

Choose a reason for hiding this comment

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

Instead of creating two instances of the same class, the __init__ method of the class should create the task to cache the data.

Copy link
Author

Choose a reason for hiding this comment

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

Runew0lf wrote it.

Choose a reason for hiding this comment

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

Ruinew0lf fixed it.

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.

This is a pretty solid PR all in all. The game is fun, and appears to work well. Your get_snek is one of the better ones in the whole jam. all in all a job well done.

EMPTY = u'\u200b'

# Results
TICK_EMOJI = "\u2705" # Correct Peg, Correct Hole
Copy link
Member

Choose a reason for hiding this comment

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

Why Are You Capitalizing Every Word In This Comment

# Results
TICK_EMOJI = "\u2705" # Correct Peg, Correct Hole
CROSS_EMOJI = "\u274C" # Wrong
BLANK_EMOJI = "\u26AA" # Correct Peg Wrong Hole
Copy link
Member

Choose a reason for hiding this comment

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

missing comma, lol

# This caches the very expensive snake list operation on load
self.setup = bot.loop.create_task(self.cache_snake_list())

async def cache_snake_list(self):
Copy link
Member

Choose a reason for hiding this comment

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

This may be a little overengineered considering you only ever call get_snake_list() from this method. It may be better to just merge those two methods into one unless you plan on using get_snake_list for anything else.

"""
Go online and fetch information about a snake
self.snake_cache = await self.get_snake_list()
return
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 does nothing. A method that has no return will also return None at the end of the method, so there's no reason to do it explicitly.

snake_list = sorted(list(set(snake_list)))
return snake_list

async def get_snek(self, name: str = None) -> Dict[str, Any]:
Copy link
Member

Choose a reason for hiding this comment

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

the docstring for this method is bad.

return (
# Conditions for a successful pagination:
all((
# Reaction is on this message
Copy link
Member

Choose a reason for hiding this comment

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

these should probably be inline, and it'd be nice if they all lined up.

)

while True:
try:
Copy link
Member

Choose a reason for hiding this comment

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

this is a huge try, which is an anti-pattern. You should only try the code that can actually fail.

page_guess_list[antidote_tries] = " ".join(antidote_guess_list)
log.info(f"Guess: {' '.join(antidote_guess_list)}")

# Now Check Guess
Copy link
Member

Choose a reason for hiding this comment

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

Okay Then, Captain CapWords.

page_result_list[antidote_tries] = " ".join(guess_result)
log.info(f"Guess Result: {' '.join(guess_result)}")

# Rebuild the board
Copy link
Member

Choose a reason for hiding this comment

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

pls no more floating comments.

# Redisplay the board
await board_id.edit(embed=antidote_embed)

if win is True:
Copy link
Member

Choose a reason for hiding this comment

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

why are you using a while True with conditions and breaks at the end instead of just putting the conditions in the while?

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.

A very nice, readable PR. Since you're using async_timeout, you'll need to pipenv install it - or you could remove it, and stick with aiohttp.Timeout(interval).

from typing import Any, Dict

import aiohttp

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.

You could just use aiohttp.Timeout

@command(name="antidote")
async def build_board(self, ctx: Context):
"""
Antidote - Can you create the antivenom before the patient dies!
Copy link
Contributor

Choose a reason for hiding this comment

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

!! ??

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.

Nice try though.

CROSS_EMOJI = "\u274C" # Wrong
BLANK_EMOJI = "\u26AA" # Correct Peg Wrong Hole
BLANK_EMOJI = "\u26AA" # Correct peg, wrong hle
Copy link
Member

Choose a reason for hiding this comment

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

hle? seriously? 👍


# Holes
HOLE_EMOJI = "\u2B1C"

ANTIDOTE_EMOJI = [FIRST_EMOJI, SECOND_EMOJI, THIRD_EMOJI, FOURTH_EMOJI, FIFTH_EMOJI]


def to_lower(argument):
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 see why this helper function is useful. it's also error prone. if you pass anything into it that isn't a string, it'll crash the program. Just use the str.lower() method instead of having this helper function at all.

@@ -222,7 +225,7 @@ def __init__(self, bot: AutoShardedBot):
return snake_dict

@command()
async def get(self, ctx: Context, name: str = None):
async def get(self, ctx: Context, name: to_lower = None):
Copy link
Member

Choose a reason for hiding this comment

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

you can't typehint something to a function. to_lower is not a type, and as far as I can tell name is still a str

Copy link
Contributor

Choose a reason for hiding this comment

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

You can do that, discord.py will convert the string to lowercase automatically


# Check to see if the bot can remove reactions
if not ctx.channel.permissions_for(ctx.guild.me).manage_messages:
await ctx.send("Unable to start game as I dont have manage_messages permissions")
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

# There were no restrictions
no_restrictions
reaction_.message.id == board_id.id, # Reaction is on this message
reaction_.emoji in ANTIDOTE_EMOJI, # Reaction is one of the pagination emotes
Copy link
Member

Choose a reason for hiding this comment

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

best to line these comments up with each other, much better readability. PEP8 only says there should be at least 2 spaces, but does not say anything about not being allowed to use five if it helps your program become more readable. so this:

something = something      # do a useless thing
something = not something  # oh okay why did we even do the previous thing then

is encouraged.

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