-
-
Notifications
You must be signed in to change notification settings - Fork 241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added guess the number game #1405
base: main
Are you sure you want to change the base?
Conversation
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 is purely a code review for now.
I will test once the changes are implemented and the conversion bug is fixed.
await ctx.send("Timeout!") | ||
return | ||
|
||
if not user_guess.content.isdigit(): |
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.
isdigit
would break on some instances as it takes unicode into account.
For example, if you call '²'.isdigit()
, it'll return True
.
Instead, wrap it in a try.except block where you try to convert it into an integer by calling int(content)
return | ||
|
||
if not user_guess.content.isdigit(): | ||
await ctx.send(f"**Invalid guess**, Please guess a number. Try again, You've {tries} left.") |
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 would look better in an Embed IMO.
return | ||
|
||
if not user_guess.content.isdigit(): | ||
await ctx.send(f"**Invalid guess**, Please guess a number. Try again, You've {tries} left.") |
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'm not sure here whether we should just quit on invalid numbers, or otherwise set a counter for the number of invalid tries a user can have, otherwise this could keep on going forever. I think both are fine.
What i'm sure of though, is that we shouldn't let a backdoor that'll keep the command running forever.
if not user_guess.content.isdigit(): | ||
await ctx.send(f"**Invalid guess**, Please guess a number. Try again, You've {tries} left.") | ||
|
||
elif int(user_guess.content) == self.active_games[ctx.author.id]: |
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 make the conversion only once, before anything else, then keep on using the converted number if successfull. The conversion should be done like I indicated in my previous comment.
else: | ||
tries = tries - 1 | ||
if tries == 0: | ||
await ctx.channel.send( |
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 can go into the while
loop's else
block, which separates the end game code from the rest & makes it clearer & less indented.
@sarzz2 Hey, just checking up. Will you be continuing this PR? Thanks! |
Yes, been a little busy with work lately. Planning to do it by next week. |
Relevant Issues
Closes #1082
Description
Added new cog of guess the number game
Did you: