Documentation ¶
Index ¶
- Constants
- func ParseComponentMatrix(components [][]discordgo.MessageComponent) []discordgo.MessageComponent
- func RolesFromMember(h *Harmonia, member *discordgo.Member) ([]*discordgo.Role, error)
- type Author
- type CommandFunc
- type CommandHandler
- type GroupSlashCommand
- func (s *GroupSlashCommand) Do(h *Harmonia, i *Invocation)
- func (s *GroupSlashCommand) GetName() string
- func (s *GroupSlashCommand) WithDMPermission(isAllowed bool) *GroupSlashCommand
- func (s *GroupSlashCommand) WithDefaultPermissions(defaultPermissions int64) *GroupSlashCommand
- func (s *GroupSlashCommand) WithDescription(description string) *GroupSlashCommand
- func (s *GroupSlashCommand) WithGuildID(guildID string) *GroupSlashCommand
- func (s *GroupSlashCommand) WithSubCommands(subcommands ...CommandHandler) *GroupSlashCommand
- type Harmonia
- func (h *Harmonia) AddCommand(command CommandHandler) (err error)
- func (h *Harmonia) AddComponentHandler(customID string, handler CommandFunc) error
- func (h *Harmonia) AddComponentHandlerToInteractionMessage(f *InteractionMessage, customID string, handler CommandFunc) error
- func (h *Harmonia) DeferResponse(i *Invocation) error
- func (h *Harmonia) DeleteFollowup(f *InteractionMessage) error
- func (h *Harmonia) DeleteResponse(i *Invocation) error
- func (h *Harmonia) EditFollowup(f *InteractionMessage, content string) (*InteractionMessage, error)
- func (h *Harmonia) EditFollowupWithComponents(f *InteractionMessage, content string, ...) (*InteractionMessage, error)
- func (h *Harmonia) EditResponse(i *Invocation, content string) (*InteractionMessage, error)
- func (h *Harmonia) EditResponseWithComponents(i *Invocation, content string, components [][]discordgo.MessageComponent) (*InteractionMessage, error)
- func (h *Harmonia) EphemeralFollowup(i *Invocation, content string) (*InteractionMessage, error)
- func (h *Harmonia) EphemeralRespond(i *Invocation, content string) (*InteractionMessage, error)
- func (h *Harmonia) Followup(i *Invocation, content string) (*InteractionMessage, error)
- func (h *Harmonia) FollowupComplex(i *Invocation, params *discordgo.WebhookParams) (*InteractionMessage, error)
- func (h *Harmonia) FollowupWithComponents(i *Invocation, content string, components [][]discordgo.MessageComponent) (*InteractionMessage, error)
- func (h *Harmonia) RemoveAllCommands() error
- func (h *Harmonia) RemoveCommand(name string) error
- func (h *Harmonia) RemoveComponentHandler(customID string) error
- func (h *Harmonia) RemoveComponentHandlerFromInteractionMessage(f *InteractionMessage, customID string) error
- func (h *Harmonia) Respond(i *Invocation, content string) (*InteractionMessage, error)
- func (h *Harmonia) RespondComplex(i *Invocation, resp *discordgo.InteractionResponse) (*InteractionMessage, error)
- func (h *Harmonia) RespondWithComponents(i *Invocation, content string, components [][]discordgo.MessageComponent) (*InteractionMessage, error)
- func (h *Harmonia) Run() error
- type InteractionMessage
- type Invocation
- func (i *Invocation) GetOption(name string) *discordgo.ApplicationCommandInteractionDataOption
- func (i *Invocation) GetOptionMap() map[string]*discordgo.ApplicationCommandInteractionDataOption
- func (i *Invocation) TargetAuthor(h *Harmonia) (*Author, error)
- func (i *Invocation) TargetMessage(h *Harmonia) (*discordgo.Message, error)
- type MessageCommand
- func (s *MessageCommand) Do(h *Harmonia, i *Invocation)
- func (s *MessageCommand) GetName() string
- func (s *MessageCommand) WithCommand(commandFunc CommandFunc) *MessageCommand
- func (s *MessageCommand) WithDMPermission(isAllowed bool) *MessageCommand
- func (s *MessageCommand) WithDefaultPermissions(defaultPermissions int64) *MessageCommand
- func (s *MessageCommand) WithGuildID(guildID string) *MessageCommand
- type Option
- type SlashCommand
- func (s *SlashCommand) Do(h *Harmonia, i *Invocation)
- func (s *SlashCommand) GetName() string
- func (s *SlashCommand) WithCommand(commandFunc CommandFunc) *SlashCommand
- func (s *SlashCommand) WithDMPermission(isAllowed bool) *SlashCommand
- func (s *SlashCommand) WithDefaultPermissions(defaultPermissions int64) *SlashCommand
- func (s *SlashCommand) WithDescription(description string) *SlashCommand
- func (s *SlashCommand) WithGuildID(guildID string) *SlashCommand
- func (s *SlashCommand) WithOptions(options ...*Option) *SlashCommand
- type UserCommand
- func (s *UserCommand) Do(h *Harmonia, i *Invocation)
- func (s *UserCommand) GetName() string
- func (s *UserCommand) WithCommand(commandFunc CommandFunc) *UserCommand
- func (s *UserCommand) WithDMPermission(isAllowed bool) *UserCommand
- func (s *UserCommand) WithDefaultPermissions(defaultPermissions int64) *UserCommand
- func (s *UserCommand) WithGuildID(guildID string) *UserCommand
Constants ¶
const VERSION = "0.7.4"
VERSION of Harmonia, follows Semantic Versioning. (http://semver.org/)
Variables ¶
This section is empty.
Functions ¶
func ParseComponentMatrix ¶ added in v0.2.0
func ParseComponentMatrix(components [][]discordgo.MessageComponent) []discordgo.MessageComponent
ParseComponentMatrix parses a 2D slice of MessageComponents and returns a 1D slice of MessageComponents with ActionsRows.
Types ¶
type Author ¶
type Author struct { *discordgo.User IsMember bool Guild *discordgo.Guild JoinedAt time.Time Nick string Deaf bool Mute bool Roles []*discordgo.Role PremiumSince *time.Time }
An Author describes either a User or Member, depending if the message was sent in a Guild or DMs.
func AuthorFromInteraction ¶ added in v0.7.0
func AuthorFromInteraction(h *Harmonia, i *discordgo.Interaction) (a *Author, err error)
AuthorFromInteraction uses the information obtained from the Interaction to create an Author.
func AuthorFromMember ¶ added in v0.7.0
AuthorFromMember returns an Author from a *discordgo.Member.
func AuthorFromUser ¶ added in v0.5.0
AuthorFromUser returns an Author from a *discordgo.User.
type CommandFunc ¶ added in v0.7.0
type CommandFunc func(h *Harmonia, i *Invocation)
type CommandHandler ¶
type CommandHandler interface { // GetName returns the name of the Command. GetName() string // Do executes the Command. Do(h *Harmonia, i *Invocation) // contains filtered or unexported methods }
type GroupSlashCommand ¶ added in v0.7.0
type GroupSlashCommand struct {
// contains filtered or unexported fields
}
GroupSlashCommand describes a group of slash commands.
func NewGroupSlashCommand ¶ added in v0.7.0
func NewGroupSlashCommand(name string) *GroupSlashCommand
NewGroupSlashCommand returns a GroupSlashCommand with a given name
func (*GroupSlashCommand) Do ¶ added in v0.7.0
func (s *GroupSlashCommand) Do(h *Harmonia, i *Invocation)
func (*GroupSlashCommand) GetName ¶ added in v0.7.0
func (s *GroupSlashCommand) GetName() string
func (*GroupSlashCommand) WithDMPermission ¶ added in v0.7.0
func (s *GroupSlashCommand) WithDMPermission(isAllowed bool) *GroupSlashCommand
WithDMPermission changes the DM Permission of the GroupSlashCommand and returns itself, so that it can be chained.
func (*GroupSlashCommand) WithDefaultPermissions ¶ added in v0.7.0
func (s *GroupSlashCommand) WithDefaultPermissions(defaultPermissions int64) *GroupSlashCommand
WithDefaultPermissions changes the DefaultPermissions of the GroupSlashCommand and returns itself, so that it can be chained.
func (*GroupSlashCommand) WithDescription ¶ added in v0.7.0
func (s *GroupSlashCommand) WithDescription(description string) *GroupSlashCommand
WithDescription changes the description of the GroupSlashCommand and returns itself, so that it can be chained.
func (*GroupSlashCommand) WithGuildID ¶ added in v0.7.0
func (s *GroupSlashCommand) WithGuildID(guildID string) *GroupSlashCommand
WithGuildID changes the guildID of the GroupSlashCommand and returns itself, so that it can be chained.
func (*GroupSlashCommand) WithSubCommands ¶ added in v0.7.0
func (s *GroupSlashCommand) WithSubCommands(subcommands ...CommandHandler) *GroupSlashCommand
type Harmonia ¶
type Harmonia struct { *discordgo.Session Commands map[string]CommandHandler ComponentHandlers map[string]CommandFunc }
A Harmonia represents a connection to the Discord API and contains the slash commands and component handlers used by Harmonia.
func New ¶
New creates a new Discord session with the provided token and wraps the Harmonia struct around it.
func (*Harmonia) AddCommand ¶ added in v0.7.0
func (h *Harmonia) AddCommand(command CommandHandler) (err error)
AddCommand adds a command to Harmonia.
func (*Harmonia) AddComponentHandler ¶ added in v0.2.0
func (h *Harmonia) AddComponentHandler(customID string, handler CommandFunc) error
AddComponentHandler adds a handler for a component. I suggest this is only used for globally used components, and not for components used on a message by message basis. See AddComponentHandlerToInteractionMessage
func (*Harmonia) AddComponentHandlerToInteractionMessage ¶ added in v0.3.0
func (h *Harmonia) AddComponentHandlerToInteractionMessage(f *InteractionMessage, customID string, handler CommandFunc) error
AddComponentHandlerToInteractionMessage adds a handler for a component, but will be handled only on its original Interaction. This is done by prepending the InteractionMessage's ID to the customID. Harmonia will do the heavy lifting from there.
func (*Harmonia) DeferResponse ¶ added in v0.3.0
func (h *Harmonia) DeferResponse(i *Invocation) error
DeferResponse sends an acknowledgement to the DiscordAPI, allowing you to send a follow-up message later. See Followup for that.
func (*Harmonia) DeleteFollowup ¶
func (h *Harmonia) DeleteFollowup(f *InteractionMessage) error
DeleteFollowup deletes a follow-up message.
func (*Harmonia) DeleteResponse ¶ added in v0.2.0
func (h *Harmonia) DeleteResponse(i *Invocation) error
DeleteResponse deletes a response.
func (*Harmonia) EditFollowup ¶
func (h *Harmonia) EditFollowup(f *InteractionMessage, content string) (*InteractionMessage, error)
EditFollowup allows you to edit a follow-up message.
func (*Harmonia) EditFollowupWithComponents ¶ added in v0.2.0
func (h *Harmonia) EditFollowupWithComponents(f *InteractionMessage, content string, components [][]discordgo.MessageComponent) (*InteractionMessage, error)
EditFollowupWithComponents does the same as EditFollowup, but also takes in a 2D slice of discordgo.MessageComponents that will be added to the follow-up message.
func (*Harmonia) EditResponse ¶ added in v0.2.0
func (h *Harmonia) EditResponse(i *Invocation, content string) (*InteractionMessage, error)
EditResponse edits an already sent response.
func (*Harmonia) EditResponseWithComponents ¶ added in v0.2.0
func (h *Harmonia) EditResponseWithComponents(i *Invocation, content string, components [][]discordgo.MessageComponent) (*InteractionMessage, error)
EditResponseWithComponents does the same as EditResponse, but also takes in a 2D slice of discordgo.MessageComponents that will be added to the response.
func (*Harmonia) EphemeralFollowup ¶ added in v0.2.0
func (h *Harmonia) EphemeralFollowup(i *Invocation, content string) (*InteractionMessage, error)
EphemeralFollowup does the same as Followup, but sets the flag such that only the invoker can see the message.
func (*Harmonia) EphemeralRespond ¶ added in v0.2.0
func (h *Harmonia) EphemeralRespond(i *Invocation, content string) (*InteractionMessage, error)
EphemeralRespond does the same as Respond, but sets the flag such that only the invoker can see the message.
func (*Harmonia) Followup ¶
func (h *Harmonia) Followup(i *Invocation, content string) (*InteractionMessage, error)
Followup sends a follow-up message to the Interaction, this does require you to have used DeferResponse before.
func (*Harmonia) FollowupComplex ¶ added in v0.2.0
func (h *Harmonia) FollowupComplex(i *Invocation, params *discordgo.WebhookParams) (*InteractionMessage, error)
FollowupComplex allows you full freedom to follow-up with whatever you'd like.
func (*Harmonia) FollowupWithComponents ¶ added in v0.2.0
func (h *Harmonia) FollowupWithComponents(i *Invocation, content string, components [][]discordgo.MessageComponent) (*InteractionMessage, error)
FollowupWithComponents does the same as Followup, but also takes in a 2D slice of discordgo.MessageComponents that will be added to the response.
func (*Harmonia) RemoveAllCommands ¶
RemoveAllCommands does removes all registered commands from the Discord API.
func (*Harmonia) RemoveCommand ¶
RemoveCommand removes a slash command from Harmonia and from the Discord API.
func (*Harmonia) RemoveComponentHandler ¶ added in v0.2.0
RemoveComponentHandler removes a component handler.
func (*Harmonia) RemoveComponentHandlerFromInteractionMessage ¶ added in v0.3.0
func (h *Harmonia) RemoveComponentHandlerFromInteractionMessage(f *InteractionMessage, customID string) error
RemoveComponentHandlerFromInteractionMessage removes a component handler from an InteractionMessage.
func (*Harmonia) Respond ¶
func (h *Harmonia) Respond(i *Invocation, content string) (*InteractionMessage, error)
Respond allows Harmonia to easily respond to an Invocation with a string.
func (*Harmonia) RespondComplex ¶ added in v0.2.0
func (h *Harmonia) RespondComplex(i *Invocation, resp *discordgo.InteractionResponse) (*InteractionMessage, error)
RespondComplex allows you full freedom to respond with whatever you'd like.
func (*Harmonia) RespondWithComponents ¶ added in v0.2.0
func (h *Harmonia) RespondWithComponents(i *Invocation, content string, components [][]discordgo.MessageComponent) (*InteractionMessage, error)
RespondWithComponents does the same as Respond, but also takes in a 2D slice of discordgo.MessageComponents that will be added to the response.
type InteractionMessage ¶ added in v0.3.0
type InteractionMessage struct { *discordgo.Message Interaction *discordgo.Interaction Channel *discordgo.Channel Guild *discordgo.Guild }
InteractionMessage describes a message sent as a follow-up or response to an Interaction.
type Invocation ¶
type Invocation struct { *discordgo.Interaction Guild *discordgo.Guild Channel *discordgo.Channel Author *Author // Only when the incoming Interaction is from a SelectMenu component. Values []string // contains filtered or unexported fields }
An Invocation describes an incoming Interaction.
func (*Invocation) GetOption ¶
func (i *Invocation) GetOption(name string) *discordgo.ApplicationCommandInteractionDataOption
GetOption returns a specific option from an Invocation.
func (*Invocation) GetOptionMap ¶
func (i *Invocation) GetOptionMap() map[string]*discordgo.ApplicationCommandInteractionDataOption
GetOptionMap returns a map of options passed through the Invocation.
func (*Invocation) TargetAuthor ¶ added in v0.7.0
func (i *Invocation) TargetAuthor(h *Harmonia) (*Author, error)
TargetAuthor takes the targetID from the invocation and returns an Author struct from it.
func (*Invocation) TargetMessage ¶ added in v0.7.0
func (i *Invocation) TargetMessage(h *Harmonia) (*discordgo.Message, error)
TargetMessage takes the targetID from the invocation and returns an Message struct from it.
type MessageCommand ¶ added in v0.7.0
type MessageCommand struct {
// contains filtered or unexported fields
}
A MessageCommand describes a user command or USER application command.
func NewMessageCommand ¶ added in v0.7.0
func NewMessageCommand(name string) *MessageCommand
NewMessageCommand returns a MessageCommand with a given name
func (*MessageCommand) Do ¶ added in v0.7.0
func (s *MessageCommand) Do(h *Harmonia, i *Invocation)
func (*MessageCommand) GetName ¶ added in v0.7.0
func (s *MessageCommand) GetName() string
func (*MessageCommand) WithCommand ¶ added in v0.7.0
func (s *MessageCommand) WithCommand(commandFunc CommandFunc) *MessageCommand
WithCommand changes the CommandFunc that is called when the MessageCommand is executed and returns itself, so that it can be chained.
func (*MessageCommand) WithDMPermission ¶ added in v0.7.0
func (s *MessageCommand) WithDMPermission(isAllowed bool) *MessageCommand
WithDMPermission changes the DM Permission of the MessageCommand and returns itself, so that it can be chained.
func (*MessageCommand) WithDefaultPermissions ¶ added in v0.7.0
func (s *MessageCommand) WithDefaultPermissions(defaultPermissions int64) *MessageCommand
WithDefaultPermissions changes the DefaultPermissions of the MessageCommand and returns itself, so that it can be chained.
func (*MessageCommand) WithGuildID ¶ added in v0.7.0
func (s *MessageCommand) WithGuildID(guildID string) *MessageCommand
WithGuildID changes the guildID of the MessageCommand and returns itself, so that it can be chained.
type Option ¶
type Option struct {
*discordgo.ApplicationCommandOption
}
An Option is a wrapper around an ApplicationCommandOption with added functionality.
func NewOption ¶ added in v0.7.0
func NewOption(name string, t discordgo.ApplicationCommandOptionType) *Option
NewOption returns an option with given name and type.
func (*Option) AddChoice ¶
AddChoice adds a choice to an option, value should be the same as the choice's type and returns itself, so that it can be chained.
func (*Option) IsRequired ¶ added in v0.7.0
IsRequired sets the requirement of the Option to true and returns itself, so that it can be chained. By default an Option is not required.
func (*Option) WithDescription ¶ added in v0.7.0
WithDescription changes the description of the Option and returns itself, so that it can be chained.
type SlashCommand ¶
type SlashCommand struct {
// contains filtered or unexported fields
}
A SlashCommand describes a slash command or CHAT_INPUT application command.
func NewSlashCommand ¶ added in v0.7.0
func NewSlashCommand(name string) *SlashCommand
NewSlashCommand returns a SlashCommand with a given name
func (*SlashCommand) Do ¶ added in v0.7.0
func (s *SlashCommand) Do(h *Harmonia, i *Invocation)
func (*SlashCommand) GetName ¶ added in v0.7.0
func (s *SlashCommand) GetName() string
func (*SlashCommand) WithCommand ¶ added in v0.7.0
func (s *SlashCommand) WithCommand(commandFunc CommandFunc) *SlashCommand
WithCommand changes the CommandFunc that is called when the SlashCommand is executed and returns itself, so that it can be chained.
func (*SlashCommand) WithDMPermission ¶ added in v0.7.0
func (s *SlashCommand) WithDMPermission(isAllowed bool) *SlashCommand
WithDMPermission changes the DM Permission of the SlashCommand and returns itself, so that it can be chained.
func (*SlashCommand) WithDefaultPermissions ¶ added in v0.7.0
func (s *SlashCommand) WithDefaultPermissions(defaultPermissions int64) *SlashCommand
WithDefaultPermissions changes the DefaultPermissions of the SlashCommand and returns itself, so that it can be chained.
func (*SlashCommand) WithDescription ¶ added in v0.7.0
func (s *SlashCommand) WithDescription(description string) *SlashCommand
WithDescription changes the description of the SlashCommand and returns itself, so that it can be chained.
func (*SlashCommand) WithGuildID ¶ added in v0.7.0
func (s *SlashCommand) WithGuildID(guildID string) *SlashCommand
WithGuildID changes the guildID of the SlashCommand and returns itself, so that it can be chained.
func (*SlashCommand) WithOptions ¶ added in v0.7.0
func (s *SlashCommand) WithOptions(options ...*Option) *SlashCommand
WithOptions changes the options in the SlashCommand and returns itself, so that it can be chained.
type UserCommand ¶ added in v0.7.0
type UserCommand struct {
// contains filtered or unexported fields
}
A UserCommand describes a user command or USER application command.
func NewUserCommand ¶ added in v0.7.0
func NewUserCommand(name string) *UserCommand
NewUserCommand returns a UserCommand with a given name
func (*UserCommand) Do ¶ added in v0.7.0
func (s *UserCommand) Do(h *Harmonia, i *Invocation)
func (*UserCommand) GetName ¶ added in v0.7.0
func (s *UserCommand) GetName() string
func (*UserCommand) WithCommand ¶ added in v0.7.0
func (s *UserCommand) WithCommand(commandFunc CommandFunc) *UserCommand
WithCommand changes the CommandFunc that is called when the UserCommand is executed and returns itself, so that it can be chained.
func (*UserCommand) WithDMPermission ¶ added in v0.7.0
func (s *UserCommand) WithDMPermission(isAllowed bool) *UserCommand
WithDMPermission changes the DM Permission of the UserCommand and returns itself, so that it can be chained.
func (*UserCommand) WithDefaultPermissions ¶ added in v0.7.0
func (s *UserCommand) WithDefaultPermissions(defaultPermissions int64) *UserCommand
WithDefaultPermissions changes the DefaultPermissions of the UserCommand and returns itself, so that it can be chained.
func (*UserCommand) WithGuildID ¶ added in v0.7.0
func (s *UserCommand) WithGuildID(guildID string) *UserCommand
WithGuildID changes the guildID of the UserCommand and returns itself, so that it can be chained.