mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-12-02 09:47:52 +00:00
discord: Improve union interface documentation; fix *Option JSON
This commit is contained in:
parent
5c88317130
commit
8d78221de0
|
|
@ -255,6 +255,20 @@ const (
|
||||||
|
|
||||||
// CommandOption is a union of command option types. The constructors for
|
// CommandOption is a union of command option types. The constructors for
|
||||||
// CommandOption will hint the types that can be a CommandOption.
|
// CommandOption will hint the types that can be a CommandOption.
|
||||||
|
//
|
||||||
|
// The following types implement this interface:
|
||||||
|
//
|
||||||
|
// - *SubcommandGroupOption
|
||||||
|
// - *SubcommandOption
|
||||||
|
// - *StringOption
|
||||||
|
// - *IntegerOption
|
||||||
|
// - *BooleanOption
|
||||||
|
// - *UserOption
|
||||||
|
// - *ChannelOption
|
||||||
|
// - *RoleOption
|
||||||
|
// - *MentionableOption
|
||||||
|
// - *NumberOption
|
||||||
|
//
|
||||||
type CommandOption interface {
|
type CommandOption interface {
|
||||||
Name() string
|
Name() string
|
||||||
Type() CommandOptionType
|
Type() CommandOptionType
|
||||||
|
|
@ -329,6 +343,18 @@ func (s *SubcommandOption) UnmarshalJSON(b []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommandOptionValue is a subcommand option that fits into a subcommand.
|
// CommandOptionValue is a subcommand option that fits into a subcommand.
|
||||||
|
//
|
||||||
|
// The following types implement this interface:
|
||||||
|
//
|
||||||
|
// - *StringOption
|
||||||
|
// - *IntegerOption
|
||||||
|
// - *BooleanOption
|
||||||
|
// - *UserOption
|
||||||
|
// - *ChannelOption
|
||||||
|
// - *RoleOption
|
||||||
|
// - *MentionableOption
|
||||||
|
// - *NumberOption
|
||||||
|
//
|
||||||
type CommandOptionValue interface {
|
type CommandOptionValue interface {
|
||||||
CommandOption
|
CommandOption
|
||||||
_val()
|
_val()
|
||||||
|
|
@ -641,3 +667,39 @@ func (u *UserOption) MarshalJSON() ([]byte, error) {
|
||||||
raw: (*raw)(u),
|
raw: (*raw)(u),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalJSON marshals ChannelOption to JSON with the "type" field.
|
||||||
|
func (c *ChannelOption) MarshalJSON() ([]byte, error) {
|
||||||
|
type raw ChannelOption
|
||||||
|
return json.Marshal(struct {
|
||||||
|
Type CommandOptionType `json:"type"`
|
||||||
|
*raw
|
||||||
|
}{
|
||||||
|
Type: c.Type(),
|
||||||
|
raw: (*raw)(c),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalJSON marshals RoleOption to JSON with the "type" field.
|
||||||
|
func (r *RoleOption) MarshalJSON() ([]byte, error) {
|
||||||
|
type raw RoleOption
|
||||||
|
return json.Marshal(struct {
|
||||||
|
Type CommandOptionType `json:"type"`
|
||||||
|
*raw
|
||||||
|
}{
|
||||||
|
Type: r.Type(),
|
||||||
|
raw: (*raw)(r),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalJSON marshals MentionableOption to JSON with the "type" field.
|
||||||
|
func (m *MentionableOption) MarshalJSON() ([]byte, error) {
|
||||||
|
type raw MentionableOption
|
||||||
|
return json.Marshal(struct {
|
||||||
|
Type CommandOptionType `json:"type"`
|
||||||
|
*raw
|
||||||
|
}{
|
||||||
|
Type: m.Type(),
|
||||||
|
raw: (*raw)(m),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,13 @@ func (c *ContainerComponents) UnmarshalJSON(b []byte) error {
|
||||||
// Component is a component that can be attached to an interaction response. A
|
// Component is a component that can be attached to an interaction response. A
|
||||||
// Component is either an InteractiveComponent or a ContainerComponent. See
|
// Component is either an InteractiveComponent or a ContainerComponent. See
|
||||||
// those appropriate types for more information.
|
// those appropriate types for more information.
|
||||||
|
//
|
||||||
|
// The following types satisfy this interface:
|
||||||
|
//
|
||||||
|
// - *ActionRowComponent
|
||||||
|
// - *ButtonComponent
|
||||||
|
// - *SelectComponent
|
||||||
|
//
|
||||||
type Component interface {
|
type Component interface {
|
||||||
// Type returns the type of the underlying component.
|
// Type returns the type of the underlying component.
|
||||||
Type() ComponentType
|
Type() ComponentType
|
||||||
|
|
@ -73,6 +80,12 @@ type Component interface {
|
||||||
// InteractiveComponent extends the Component for components that are
|
// InteractiveComponent extends the Component for components that are
|
||||||
// interactible, or components that aren't containers (like ActionRow). This is
|
// interactible, or components that aren't containers (like ActionRow). This is
|
||||||
// useful for ActionRow to type-check that no nested ActionRows are allowed.
|
// useful for ActionRow to type-check that no nested ActionRows are allowed.
|
||||||
|
//
|
||||||
|
// The following types satisfy this interface:
|
||||||
|
//
|
||||||
|
// - *ButtonComponent
|
||||||
|
// - *SelectComponent
|
||||||
|
//
|
||||||
type InteractiveComponent interface {
|
type InteractiveComponent interface {
|
||||||
Component
|
Component
|
||||||
// ID returns the ID of the underlying component.
|
// ID returns the ID of the underlying component.
|
||||||
|
|
@ -83,6 +96,11 @@ type InteractiveComponent interface {
|
||||||
// ContainerComponent is the opposite of InteractiveComponent: it describes
|
// ContainerComponent is the opposite of InteractiveComponent: it describes
|
||||||
// components that only contain other components. The only component that
|
// components that only contain other components. The only component that
|
||||||
// satisfies that is ActionRow.
|
// satisfies that is ActionRow.
|
||||||
|
//
|
||||||
|
// The following types satisfy this interface:
|
||||||
|
//
|
||||||
|
// - *ActionRowComponent
|
||||||
|
//
|
||||||
type ContainerComponent interface {
|
type ContainerComponent interface {
|
||||||
Component
|
Component
|
||||||
_ctn()
|
_ctn()
|
||||||
|
|
|
||||||
|
|
@ -132,8 +132,16 @@ const (
|
||||||
|
|
||||||
// InteractionData holds the respose data of an interaction, or more
|
// InteractionData holds the respose data of an interaction, or more
|
||||||
// specifically, the data that Discord sends to us. Type assertions should be
|
// specifically, the data that Discord sends to us. Type assertions should be
|
||||||
// made on it to access the underlying data. The underlying types of the
|
// made on it to access the underlying data.
|
||||||
// Responses are value types. See the constructors for the possible types.
|
//
|
||||||
|
// The following types implement this interface:
|
||||||
|
//
|
||||||
|
// - *PingInteraction
|
||||||
|
// - *AutocompleteInteraction
|
||||||
|
// - *CommandInteraction
|
||||||
|
// - *SelectInteraction (also ComponentInteraction)
|
||||||
|
// - *ButtonInteraction (also ComponentInteraction)
|
||||||
|
//
|
||||||
type InteractionData interface {
|
type InteractionData interface {
|
||||||
InteractionType() InteractionDataType
|
InteractionType() InteractionDataType
|
||||||
data()
|
data()
|
||||||
|
|
@ -173,8 +181,13 @@ func (*AutocompleteInteraction) InteractionType() InteractionDataType {
|
||||||
func (*AutocompleteInteraction) data() {}
|
func (*AutocompleteInteraction) data() {}
|
||||||
|
|
||||||
// ComponentInteraction is a union component interaction response types. The
|
// ComponentInteraction is a union component interaction response types. The
|
||||||
// types can be whatever the constructors for this type will return. Underlying
|
// types can be whatever the constructors for this type will return.
|
||||||
// types of Response are all value types.
|
//
|
||||||
|
// The following types implement this interface:
|
||||||
|
//
|
||||||
|
// - *SelectInteraction
|
||||||
|
// - *ButtonInteraction
|
||||||
|
//
|
||||||
type ComponentInteraction interface {
|
type ComponentInteraction interface {
|
||||||
InteractionData
|
InteractionData
|
||||||
// ID returns the ID of the component in response. Not all component
|
// ID returns the ID of the component in response. Not all component
|
||||||
|
|
|
||||||
|
|
@ -12,29 +12,19 @@ types=(
|
||||||
MentionableOption
|
MentionableOption
|
||||||
)
|
)
|
||||||
|
|
||||||
recvs=(
|
for ((i = 0; i < ${#types[@]}; i++)); {
|
||||||
s
|
recv=$(head -c1 <<< "${types[$i]}" | tr "[:upper:]" "[:lower:]")
|
||||||
s
|
|
||||||
s
|
|
||||||
i
|
|
||||||
b
|
|
||||||
u
|
|
||||||
c
|
|
||||||
r
|
|
||||||
m
|
|
||||||
)
|
|
||||||
|
|
||||||
for ((i = 0; i < 6; i++)); {
|
|
||||||
cat<<EOF
|
cat<<EOF
|
||||||
// MarshalJSON marshals ${types[$i]} to JSON with the "type" field.
|
// MarshalJSON marshals ${types[$i]} to JSON with the "type" field.
|
||||||
func (${recvs[$i]} *${types[$i]}) MarshalJSON() ([]byte, error) {
|
func (${recv} *${types[$i]}) MarshalJSON() ([]byte, error) {
|
||||||
type raw ${types[$i]}
|
type raw ${types[$i]}
|
||||||
return json.Marshal(struct {
|
return json.Marshal(struct {
|
||||||
Type CommandOptionType \`json:"type"\`
|
Type CommandOptionType \`json:"type"\`
|
||||||
*raw
|
*raw
|
||||||
}{
|
}{
|
||||||
Type: ${recvs[$i]}.Type(),
|
Type: ${recv}.Type(),
|
||||||
raw: (*raw)(${recvs[$i]}),
|
raw: (*raw)(${recv}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue