Add ConfirmView utility #6176
No reviewers
Labels
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!6176
Loading…
Reference in a new issue
No description provided.
Delete branch "add-confirm-view"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
closes #6174
Description of the changes
Have the changes in this PR been tested?
Yes
Would it be worth adding an on_timeout that sets the buttons to disabled?
I am open to customizing the timeout but I will not be adding support for disabling the buttons automatically. That would require sending the message through the view which I feel takes away from the simplicity of this. The buttons when interacted with will remove the buttons from the message but timeout will do nothing and it should be up to the user to handle that I think.
Huh, I have a confirm that doesn't send through a view and works fine.
That would disable the button and prevent any response but would still require editing the original message which this does not have any reference to.
I have reworked this slightly so we can know if the buttons were not pressed so users can clean them up however they wish, whether that be disabling the buttons or removing them after the timeout.
It shouldn't be required (i.e. we should only try doing it if not
None) but I think that it would be simple enough to allow settingview.messageattribute after the message is sent and remove the view from the messageon_timeoutin such a case. I would also suggest updating the relevant example to use that, i.e.@ -431,3 +431,190 @@ class SetApiView(discord.ui.View):return await interaction.response.send_modal(That's a weird order, comments generally are placed before the action they talk about:
I don't know what this is supposed to convey, making it
if not self.disable_buttonswith an early return would have been no different so I don't see any prioritization here.These have been changed to no longer remove the view from the message, why is that?
That's a weird order, comments generally are placed before the action they talk about.
The comment also seemed a bit unclear so here's a suggested rephrase:
It would probably make sense to explain the default behavior:
This may be unnecessary but the sentence read weirdly to me:
Is this meant to be a public method? If so, please document it, otherwise prefix it with
_.@ -11,7 +11,7 @@ from redbot.core.commands.converter import get_dict_converterif TYPE_CHECKING:nitpick: we try to keep items in
__all__in definition order to make it somewhat easier to check if anything is missing in__all__:There's mostly a bunch of docstring fixes left but I also commented with one implementation question.
@ -431,3 +431,190 @@ class SetApiView(discord.ui.View):return await interaction.response.send_modal(This may seem like a nitpick but this is actually a very important fix to how Sphinx ends up displaying this:
Looking at the documentation, it seems that it's consistent with it but I do wonder if we actually want to make the behavior of the view's timeout action dependent on whether some random person other than the author decides to click one of the buttons under the message? Would it not make more sense to this API's consumers to expect that not setting
view.messagewill fully prevent it from removing/disabling the buttons on the message?I suppose my original thinking was to prefer cleanup of the view in as many situations as possible. For example, a cog sends the view without explicitly setting the message attribute, if the issuer of the command doesn't click the button but someone else does it would be better to then cleanup the view even if it doesn't actually respond to them. I view it as better in that the buttons no longer sit around unusable for anyone. I could move it under the author check to be more consistent and keep everything else the same I suppose. Though now I also wonder if I should be responding to someone who isn't the author with a message as well.
I haven't thought about it but it would definitely make it seem not broken to bystanders. And it would be more consistent with all the other views/modals that we already have (just the simple menu and set api so far).
It seems like an alright way of handling it. But with your explanation, I honestly am not sure if we should do that or just leave it as is (since I guess that the option of not trying to do the cleanup at all is not something we're interested in).
I added a response if someone other than the author attempts to interact with the buttons. I left in setting the message object from any interaction though. I am much happier with the way this would work now and I would rather prioritize removing or disabling the view in as many situations as possible. Leaving broken buttons lying around outside of development and testing just feels bad.
This new utility works as expected so from my side, this is good to go.
I would, however, like you to look at the rendered documentation and assess whether the current version of it is acceptable:
https://red-discordbot--6176.org.readthedocs.build/en/6176/framework_utils.html#redbot.core.utils.views.ConfirmView
Basically, I looked at the rendered documentation and thought that showing the documentation from the base class on our overridden version of the methods was confusing and have instead opted to document it with the actual behavior of them. Additionally, I documented
confirm/dismiss_buttonas a regular attribute of theButtontype since that's what it actually ends up being on the instance of this view.If everything seems fine to you, feel free to just merge this.