Skip to content

Conversation

DMFriends
Copy link
Contributor

Relevant Issues

Closes #847

Description

This PR is designed to add a fun Madlibs game to Sir Lancebot.

When the command, .madlibs, is run, the bot will ask the user to enter a word that fits a random part of speech (e.g. noun, adjective, verb, plural noun, etc.). The user will simply send a message with any word that fits the given part of speech.

The bot chooses a random number of user inputs to use for the game and a random story.

Once the user has finished entering all the input prompts, the bot should send a message with the completed story using the words that the user entered.

Did you:

@Xithrius Xithrius added area: backend Related to internal functionality and utilities category: fun Related to fun and games status: WIP Work In Progress type: feature Relating to the functionality of the application. labels Oct 12, 2021
@DMFriends
Copy link
Contributor Author

DMFriends commented Oct 18, 2021

Tysm for your review @TizzySaurus ! Your reviews are very thorough and it helps me a lot especially since this is my first time contributing to open-source!! I will implement your changes later today if I get the chance.

Copy link
Contributor

@Akarys42 Akarys42 left a comment

Choose a reason for hiding this comment

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

works as intended

Copy link
Contributor

@onerandomusername onerandomusername left a comment

Choose a reason for hiding this comment

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

Should only allow a user to invoke the command once at a time.

Easy fix, decorate the command with this: https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.max_concurrency

@commands.max_concurrency(1, per=commands.BucketType.user)

@onerandomusername
Copy link
Contributor

It turns out that the bots error handler doesn't actually catch the error raised by a concurrency blocker.

To solve this, we can use local error handlers (method) (guide)

I've put an implementation together below, since some of this involves digging into our error handler implementation.

    @madlibs.error
    async def handle_madlibs_error(self, ctx: commands.Context, error: commands.CommandError) -> None:
        if isinstance(error, commands.MaxConcurrencyReached):
            await ctx.send("You are already playing madlibs!")
            error.handled = True

The reason we set error.handled to True is because in our error handler we use getattr(error, "handler", False) to see if we have already handled the error.

@DMFriends
Copy link
Contributor Author

It turns out that the bots error handler doesn't actually catch the error raised by a concurrency blocker.

To solve this, we can use local error handlers (method) (guide)

I've put an implementation together below, since some of this involves digging into our error handler implementation.

    @madlibs.error
    async def handle_madlibs_error(self, ctx: commands.Context, error: commands.CommandError) -> None:
        if isinstance(error, commands.MaxConcurrencyReached):
            await ctx.send("You are already playing madlibs!")
            error.handled = True

The reason we set error.handled to True is because in our error handler we use getattr(error, "handler", False) to see if we have already handled the error.

So this would go in the error handler file in the repo, correct?

@DMFriends
Copy link
Contributor Author

Should only allow a user to invoke the command once at a time.

Easy fix, decorate the command with this: https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.max_concurrency

@commands.max_concurrency(1, per=commands.BucketType.user)

Would this go right after line 65?
Screenshot_20211214-073211_GitHub.jpg

@onerandomusername
Copy link
Contributor

It turns out that the bots error handler doesn't actually catch the error raised by a concurrency blocker.
To solve this, we can use local error handlers (method) (guide)
I've put an implementation together below, since some of this involves digging into our error handler implementation.

    @madlibs.error
    async def handle_madlibs_error(self, ctx: commands.Context, error: commands.CommandError) -> None:
        if isinstance(error, commands.MaxConcurrencyReached):
            await ctx.send("You are already playing madlibs!")
            error.handled = True

The reason we set error.handled to True is because in our error handler we use getattr(error, "handler", False) to see if we have already handled the error.

So this would go in the error handler file in the repo, correct?

No, this would go in the madlibs file, since its local to the command.

@onerandomusername
Copy link
Contributor

Should only allow a user to invoke the command once at a time.
Easy fix, decorate the command with this: https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.max_concurrency

@commands.max_concurrency(1, per=commands.BucketType.user)

Would this go right after line 65? Screenshot_20211214-073211_GitHub.jpg

Yeah.

@DMFriends
Copy link
Contributor Author

It turns out that the bots error handler doesn't actually catch the error raised by a concurrency blocker.
To solve this, we can use local error handlers (method) (guide)
I've put an implementation together below, since some of this involves digging into our error handler implementation.

    @madlibs.error
    async def handle_madlibs_error(self, ctx: commands.Context, error: commands.CommandError) -> None:
        if isinstance(error, commands.MaxConcurrencyReached):
            await ctx.send("You are already playing madlibs!")
            error.handled = True

The reason we set error.handled to True is because in our error handler we use getattr(error, "handler", False) to see if we have already handled the error.

So this would go in the error handler file in the repo, correct?

No, this would go in the madlibs file, since its local to the command.

Ah, gotcha. So where exactly does this go? Right after the async def madlibs, correct?

@Shivansh-007
Copy link
Contributor

Shivansh-007 commented Dec 14, 2021

Ah, gotcha. So where exactly does this go? Right after the async def madlibs, correct?

Yeah, it can go anywhere in the cog, it's just a special decorator like the on_command_error method but for a cog, which would be called whenever there is an error raised in the cog, also error.handled is set so the error handler doesn't handle the error again.

@DMFriends
Copy link
Contributor Author

Ah, gotcha. So where exactly does this go? Right after the async def madlibs, correct?

Yeah, it can go anywhere in the cog, it's just a special decorator like the on_command_error method but for a cog, which would be called whenever there is an error raised in the cog, also error.handled is set so the error handler doesn't handle the error again.

Gotcha, thanks.

- Added a small piece of code so that users can invoke the command only once at a time
- Added an error handler for that piece of code
Both of the above were requested by arl (onerandomusername)

Co-Authored-By: aru <[email protected]>
Copy link
Contributor

@onerandomusername onerandomusername left a comment

Choose a reason for hiding this comment

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

lgtm :D

@onerandomusername
Copy link
Contributor

Not changing my approval, but there is this error message on timeout which I don't fully think makes sense.
image

Additonally, I'm not sure about the random titles, as its somewhat unprompted.

Finally, I suggest mentioning the user with this error as its a timeout.

@DMFriends
Copy link
Contributor Author

DMFriends commented Dec 20, 2021

Not changing my approval, but there is this error message on timeout which I don't fully think makes sense. image

Additonally, I'm not sure about the random titles, as its somewhat unprompted.

Finally, I suggest mentioning the user with this error as its a timeout.

As you mentioned on Discord, it does say "Please try again later" and yes I agree that that the user could try again right away. To be honest, I could probably change what the embed says as a whole. I'm going to think about this more. Also I think mentioning the user would be good, will add that.

About the random titles, that was something that Shom770 pointed out in a review so I added that. It sounds like this is a standard convention for similar projects so I decided to commit that suggestion. If you think I should not have it, I think it's fine either way.

@onerandomusername
Copy link
Contributor

About the random titles, that was something that Shom770 pointed out in a review so I added that. It sounds like this is a standard convention for similar projects so I decided to commit that suggestion. If you think I should not have it, I think it's fine either way.

Well, we should keep them then, but I think that message should mention the user at minimum, and remove the please try again later :D

@DMFriends
Copy link
Contributor Author

DMFriends commented Dec 20, 2021

About the random titles, that was something that Shom770 pointed out in a review so I added that. It sounds like this is a standard convention for similar projects so I decided to commit that suggestion. If you think I should not have it, I think it's fine either way.

Well, we should keep them then, but I think that message should mention the user at minimum, and remove the please try again later :D

Yep, I already added that locally, will commit sometime soon :)
Everything else besides the "please try again later" is good, right? @onerandomusername

@onerandomusername
Copy link
Contributor

Yep!

Add an author mention to the timeout embed and removed part of the embed message as requested by arl (onerandomusername)
@Xithrius Xithrius added status: needs review Author is waiting for someone to review and approve and removed status: waiting for author Waiting for author to address a review or respond to a comment labels Dec 24, 2021
@Xithrius
Copy link
Member

To whoever eventually hits the merge button: squash.

- Add a message about not spamming as requested by ChrisLovering
- Made a small grammar change in the docstring of the edit listener function
@ChrisLovering ChrisLovering enabled auto-merge (squash) January 2, 2022 12:09
@ChrisLovering ChrisLovering merged commit cf7a432 into python-discord:main Jan 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: backend Related to internal functionality and utilities category: fun Related to fun and games status: needs review Author is waiting for someone to review and approve type: feature Relating to the functionality of the application.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Madlibs game

9 participants