-
-
Notifications
You must be signed in to change notification settings - Fork 736
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
[Feature]: ComponentBuilder component removal methods #2644
Conversation
IMO it would be a good idea to add a method to remove a link-button by a URL, since one doesn't have a custom id |
Good call. What would you suggest an example implementation looks like? |
Looks good to me |
@Misha-133 not sure I can/want to do the link button one - IMessageComponent only exposes custom id & component type to reference. Adding to that interface would mean forcing an additional unused property in all the other components that don't need it (ie: SelectMenu, TextInput, etc). |
You could cast the component to a button tho if(component is ButtonComponent button && button.Url == ......) |
I was on the right track, just derped and used |
src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentBuilder.cs
Outdated
Show resolved
Hide resolved
Also, shouldn't these methods support regex wildcards? So it'd be possible to do something like |
I despise working with Regex, but I'll take a gander when I'm more free and want to torture myself with it. 🥲 |
I took a look, figured I could just reference the Regex implementation that is used in the ComponentInteration attribute, but I cannot find it 😳 thinking we should just use this PR as-is, and have another PR sometime in the future that will expand the functionality of these to support regex. |
A feature that does not support functionality the library offers out of the box should not be merged. @Cenngo, could you reference the component regex? |
This is internal to the Discord.Net.Interaction namespace; ComponentBuilder is in Core... should I just copy all of the non-dependent code into either Core/Utils or ComponentBuilder.cs? or is there a better way to go about this? |
you could add the .Remove methods to the Discord.Interactions assembly as extension methods |
True, but along the lines of reusing that code, it is dependent on ICommandInfo and InteractionServiceConfig.WildCardExpression, both of which I don't think an extension method (or otherwise) would have any context for? |
Alright, well I hoped to add a couple useful functions that assisted me in my project so others could have that functionality too, rather than not at all - but this is not something I intend to spend hours digging into, I have enough on my plate as it is. If this absolutely cannot be included without regex support and be incrementally developed to add regex later down the line, then please go ahead and close this PR. thx |
This PR adds two helper methods to ComponentBuilder to assist in the removal of components.
ComponentBuilder.RemoveComponent(customId)
will remove a component based on its custom id.ComponentBuilder.RemoveComponentsOfType(componentType)
will remove all components of a given type (ie: button, menu, etc).Build() will now automatically resolve empty ActionRows.
An example that will always remove the button that is clicked from a message: