feat(interactions): add GetOption method to interaction data structs (#1535)

* Add ApplicationCommandInteractionData.GetOption
* Add ApplicationCommandInteractionDataOption.GetOption

---------

Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com>
This commit is contained in:
Yusta 2024-10-06 23:47:26 +07:00 committed by GitHub
parent 7fded9fd03
commit 02e7ea559b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -346,6 +346,18 @@ type ApplicationCommandInteractionData struct {
TargetID string `json:"target_id"` TargetID string `json:"target_id"`
} }
// GetOption finds and returns an application command option by its name.
func (d ApplicationCommandInteractionData) GetOption(name string) (option *ApplicationCommandInteractionDataOption) {
for _, opt := range d.Options {
if opt.Name == name {
option = opt
break
}
}
return
}
// ApplicationCommandInteractionDataResolved contains resolved data of command execution. // ApplicationCommandInteractionDataResolved contains resolved data of command execution.
// Partial Member objects are missing user, deaf and mute fields. // Partial Member objects are missing user, deaf and mute fields.
// Partial Channel objects only have id, name, type and permissions fields. // Partial Channel objects only have id, name, type and permissions fields.
@ -428,6 +440,18 @@ type ApplicationCommandInteractionDataOption struct {
Focused bool `json:"focused,omitempty"` Focused bool `json:"focused,omitempty"`
} }
// GetOption finds and returns an application command option by its name.
func (o ApplicationCommandInteractionDataOption) GetOption(name string) (option *ApplicationCommandInteractionDataOption) {
for _, opt := range o.Options {
if opt.Name == name {
option = opt
break
}
}
return
}
// IntValue is a utility function for casting option value to integer // IntValue is a utility function for casting option value to integer
func (o ApplicationCommandInteractionDataOption) IntValue() int64 { func (o ApplicationCommandInteractionDataOption) IntValue() int64 {
if o.Type != ApplicationCommandOptionInteger { if o.Type != ApplicationCommandOptionInteger {