Documentation ¶
Index ¶
- Constants
- Variables
- func IsThread(ch *discord.Channel) bool
- func ModalResponse(id discord.InteractionID, token string, s *state.State, customID, title string, ...) error
- func NewCheckError[T HasContext](content string, embeds ...discord.Embed) error
- func PermStrings(p discord.Permissions) []string
- func PermStringsFor(m []Perm, p discord.Permissions) []string
- type AutocompleteBuilder
- type AutocompleteContext
- type ButtonBuilder
- type ButtonContext
- type Check
- type CheckError
- type CollectFunc
- type CommandBuilder
- type CommandContext
- type Context
- func (ctx *Context) Ctx() *Context
- func (ctx *Context) Defer() error
- func (ctx *Context) DeferEphemeral() error
- func (ctx *Context) Original() (msg *discord.Message, err error)
- func (ctx *Context) Paginate(data []PaginateData, timeout time.Duration) (*discord.Message, context.CancelFunc, error)
- func (ctx *Context) Reply(content string, embeds ...discord.Embed) error
- func (ctx *Context) ReplyComplex(data api.InteractionResponseData) error
- func (ctx *Context) ReplyEphemeral(content string, embeds ...discord.Embed) error
- type HandlerFunc
- type HasContext
- type ModalBuilder
- type ModalContext
- type PaginateData
- type Perm
- type Router
- func (r *Router) Autocomplete(path string) *AutocompleteBuilder
- func (r *Router) Button(id discord.ComponentID) *ButtonBuilder
- func (r *Router) Command(path string) *CommandBuilder
- func (r *Router) DefaultCollectFunc(s *state.State, guildID discord.GuildID, channelID discord.ChannelID) (g *discord.Guild, ch, parentCh *discord.Channel, err error)
- func (r *Router) Execute(ic *gateway.InteractionCreateEvent) (err error)
- func (r *Router) Modal(id discord.ComponentID) *ModalBuilder
- func (r *Router) NewAutocompleteContext(ic *gateway.InteractionCreateEvent) (ctx *AutocompleteContext, err error)
- func (r *Router) NewButtonContext(ic *gateway.InteractionCreateEvent) (ctx *ButtonContext, err error)
- func (r *Router) NewCommandContext(ic *gateway.InteractionCreateEvent) (ctx *CommandContext, err error)
- func (r *Router) NewModalContext(ic *gateway.InteractionCreateEvent) (ctx *ModalContext, err error)
- func (r *Router) NewRootContext(ic *gateway.InteractionCreateEvent) (ctx *Context, err error)
- func (r *Router) NewSelectContext(ic *gateway.InteractionCreateEvent) (ctx *SelectContext, err error)
- func (r *Router) Select(id discord.ComponentID) *SelectBuilder
- func (r *Router) ShardFromGuildID(guildID discord.GuildID) (*state.State, int)
- type SelectBuilder
- type SelectContext
Constants ¶
const ( ErrNotCommand = errors.Sentinel("not a command interaction") ErrNotModal = errors.Sentinel("not a modal interaction") ErrNotButton = errors.Sentinel("not a button interaction") )
const ( PermissionViewServerInsights = 1 << 19 PermissionModerateMembers = 1 << 40 )
Permission constants that Arikawa is missing
const ErrUnknownCommand = errors.Sentinel("no command with that path found")
const NoPaginateData = errors.Sentinel("no paginate data")
Variables ¶
var ( MajorPerms = []Perm{ {discord.PermissionAdministrator, "Administrator"}, {discord.PermissionManageGuild, "Manage Server"}, {discord.PermissionManageWebhooks, "Manage Webhooks"}, {discord.PermissionManageChannels, "Manage Channels"}, {discord.PermissionBanMembers, "Ban Members"}, {discord.PermissionKickMembers, "Kick Members"}, {discord.PermissionManageRoles, "Manage Roles"}, {discord.PermissionManageNicknames, "Manage Nicknames"}, {discord.PermissionManageEmojisAndStickers, "Manage Emojis and Stickers"}, {discord.PermissionManageThreads, "Manage Threads"}, {discord.PermissionManageMessages, "Manage Messages"}, {discord.PermissionMentionEveryone, "Mention Everyone"}, {discord.PermissionModerateMembers, "Timeout Members"}, {discord.PermissionMuteMembers, "Voice Mute Members"}, {discord.PermissionDeafenMembers, "Voice Deafen Members"}, {discord.PermissionMoveMembers, "Voice Move Members"}, } NotablePerms = []Perm{ {discord.PermissionViewAuditLog, "View Audit Log"}, {PermissionViewServerInsights, "View Server Insights"}, {discord.PermissionPrioritySpeaker, "Priority Speaker"}, {discord.PermissionSendTTSMessages, "Send TTS Messages"}, {discord.PermissionCreateInstantInvite, "Create Invite"}, {discord.PermissionCreatePublicThreads, "Create Public Threads"}, {discord.PermissionCreatePrivateThreads, "Create Private Threads"}, } MinorPerms = []Perm{ {discord.PermissionStream, "Video"}, {discord.PermissionUseVAD, "Use Voice Activity"}, {discord.PermissionSpeak, "Speak"}, {discord.PermissionConnect, "Connect"}, {discord.PermissionRequestToSpeak, "Request to Speak"}, {discord.PermissionAttachFiles, "Attach Files"}, {discord.PermissionEmbedLinks, "Embed Links"}, {discord.PermissionStartEmbeddedActivities, "Start Embedded Activities"}, {discord.PermissionAddReactions, "Add Reactions"}, {discord.PermissionSendMessages, "Send Messages"}, {discord.PermissionSendMessagesInThreads, "Send Messages in Threads"}, {discord.PermissionReadMessageHistory, "Read Message History"}, {discord.PermissionViewChannel, "View Channel"}, {discord.PermissionUseSlashCommands, "Use Slash Commands"}, {discord.PermissionChangeNickname, "Change Nickname"}, {discord.PermissionUseExternalEmojis, "Use External Emojis"}, } AllPerms = append(MajorPerms, append(NotablePerms, MinorPerms...)...) )
All permissions
Functions ¶
func ModalResponse ¶
func ModalResponse( id discord.InteractionID, token string, s *state.State, customID, title string, components ...discord.InteractiveComponent, ) error
ModalResponse creates a modal interaction response.
func NewCheckError ¶
func NewCheckError[T HasContext](content string, embeds ...discord.Embed) error
NewCheckError returns a simple, static CheckError.
func PermStrings ¶
func PermStrings(p discord.Permissions) []string
PermStrings gives permission strings for all Discord permissions
func PermStringsFor ¶
func PermStringsFor(m []Perm, p discord.Permissions) []string
PermStringsFor gives permission strings for the given Perm slice
Types ¶
type AutocompleteBuilder ¶
type AutocompleteBuilder struct {
// contains filtered or unexported fields
}
func (*AutocompleteBuilder) Exec ¶
func (c *AutocompleteBuilder) Exec(hn HandlerFunc[*AutocompleteContext])
Exec adds this autocomplete handler to the router.
type AutocompleteContext ¶
type AutocompleteContext struct { *Context Command []string Options []discord.AutocompleteOption Data *discord.AutocompleteInteraction }
type ButtonBuilder ¶
type ButtonBuilder struct {
// contains filtered or unexported fields
}
func (*ButtonBuilder) Check ¶
func (b *ButtonBuilder) Check(check Check[*ButtonContext]) *ButtonBuilder
Check adds a check to this button handler. The behaviour of the passed check is controlled by b.Once().
func (*ButtonBuilder) Exec ¶
func (b *ButtonBuilder) Exec(hn HandlerFunc[*ButtonContext])
Exec adds this button to the router.
func (*ButtonBuilder) Message ¶
func (b *ButtonBuilder) Message(id discord.MessageID) *ButtonBuilder
Message changes this button interaction to be limited to a single message ID.
func (*ButtonBuilder) Once ¶
func (b *ButtonBuilder) Once() *ButtonBuilder
Once changes this button interaction to only be listened for once. If the check fails, it will be silent, and the button will not be removed.
type ButtonContext ¶
type ButtonContext struct { *Context Data *discord.ButtonInteraction CustomID discord.ComponentID }
type Check ¶
type Check[T HasContext] func(ctx T) (err error)
Check is a check for slash commands. If err != nil: - if err implements CheckError, respond with the content and embeds from that method - otherwise, print the string representation of the error
func And ¶
func And[T HasContext](checks ...Check[T]) Check[T]
And combines all the given checks into a single check. The first one to fail is returned.
func HasChannelPermissions ¶
func HasChannelPermissions[T HasContext](perm discord.Permissions) Check[T]
HasChannelPermissions returns a check that requires the given permissions on a channel level (taking into account overwrites).
func HasGuildPermissions ¶
func HasGuildPermissions[T HasContext](perm discord.Permissions) Check[T]
HasGuildPermissions returns a check that requires the given permissions on a guild level.
func Or ¶
func Or[T HasContext](checks ...Check[T]) Check[T]
Or checks all given checks and returns nil if at least one of them succeeds.
type CheckError ¶
type CheckError[T HasContext] interface { CheckError(T) (string, []discord.Embed) }
type CollectFunc ¶
type CommandBuilder ¶
type CommandBuilder struct {
// contains filtered or unexported fields
}
func (*CommandBuilder) Check ¶
func (c *CommandBuilder) Check(check Check[*CommandContext]) *CommandBuilder
Check adds a check to this command handler.
func (*CommandBuilder) Exec ¶
func (c *CommandBuilder) Exec(hn HandlerFunc[*CommandContext])
Exec adds this command to the router.
type CommandContext ¶
type CommandContext struct { *Context Command []string Options discord.CommandInteractionOptions Data *discord.CommandInteraction }
func (*CommandContext) FirstMessage ¶
func (ctx *CommandContext) FirstMessage() discord.Message
func (*CommandContext) FirstUser ¶
func (ctx *CommandContext) FirstUser() discord.User
func (*CommandContext) Option ¶
func (ctx *CommandContext) Option(name string) discord.CommandInteractionOption
type Context ¶
type Context struct { InteractionID discord.InteractionID InteractionToken string Event *gateway.InteractionCreateEvent State *state.State User discord.User Member *discord.Member Guild *discord.Guild Channel *discord.Channel ParentChannel *discord.Channel // contains filtered or unexported fields }
Context is the root context embedded into CommandContext, ModalContext etc
func (*Context) DeferEphemeral ¶
func (*Context) Paginate ¶
func (ctx *Context) Paginate(data []PaginateData, timeout time.Duration) (*discord.Message, context.CancelFunc, error)
func (*Context) ReplyComplex ¶
func (ctx *Context) ReplyComplex(data api.InteractionResponseData) error
type HandlerFunc ¶
type HandlerFunc[T HasContext] func(T) error
type HasContext ¶
type HasContext interface {
Ctx() *Context
}
type ModalBuilder ¶
type ModalBuilder struct {
// contains filtered or unexported fields
}
func (*ModalBuilder) Check ¶
func (m *ModalBuilder) Check(check Check[*ModalContext]) *ModalBuilder
Check adds a check to this modal handler.
func (*ModalBuilder) Exec ¶
func (m *ModalBuilder) Exec(hn HandlerFunc[*ModalContext])
Exec adds this modal to the router.
type ModalContext ¶
type ModalContext struct { *Context CustomID discord.ComponentID Components []discord.InteractiveComponent TextInputs []discord.TextInputComponent Data *discord.ModalInteraction }
type PaginateData ¶
type PaginateData struct { Content string Embeds []discord.Embed Components discord.ContainerComponents AllowedMentions *api.AllowedMentions }
func PaginateEmbeds ¶
func PaginateEmbeds(embeds ...discord.Embed) []PaginateData
func PaginateStrings ¶
func PaginateStrings(strings ...string) []PaginateData
type Perm ¶
type Perm struct { Permission discord.Permissions Name string }
Perm is a single permission
type Router ¶
type Router struct { Rest *api.Client State *state.State ShardManager *shard.Manager // CollectFunc is the function used to collect the guild and channel an interaction takes place in. // The default CollectFunc uses a *state.State, but this can be overridden for more specialized caches. CollectFunc CollectFunc // contains filtered or unexported fields }
func NewFromState ¶
func (*Router) Autocomplete ¶
func (r *Router) Autocomplete(path string) *AutocompleteBuilder
func (*Router) Button ¶
func (r *Router) Button(id discord.ComponentID) *ButtonBuilder
func (*Router) Command ¶
func (r *Router) Command(path string) *CommandBuilder
func (*Router) DefaultCollectFunc ¶
func (*Router) Modal ¶
func (r *Router) Modal(id discord.ComponentID) *ModalBuilder
func (*Router) NewAutocompleteContext ¶
func (r *Router) NewAutocompleteContext(ic *gateway.InteractionCreateEvent) (ctx *AutocompleteContext, err error)
NewAutocompleteContext creates a new autocomplete context.
func (*Router) NewButtonContext ¶
func (r *Router) NewButtonContext(ic *gateway.InteractionCreateEvent) (ctx *ButtonContext, err error)
ButtonContext creates a new command context.
func (*Router) NewCommandContext ¶
func (r *Router) NewCommandContext(ic *gateway.InteractionCreateEvent) (ctx *CommandContext, err error)
NewCommandContext creates a new command context.
func (*Router) NewModalContext ¶
func (r *Router) NewModalContext(ic *gateway.InteractionCreateEvent) (ctx *ModalContext, err error)
NewModalContext creates a new modal context.
func (*Router) NewRootContext ¶
func (r *Router) NewRootContext(ic *gateway.InteractionCreateEvent) (ctx *Context, err error)
func (*Router) NewSelectContext ¶
func (r *Router) NewSelectContext(ic *gateway.InteractionCreateEvent) (ctx *SelectContext, err error)
NewSelectContext creates a new select context.
func (*Router) Select ¶
func (r *Router) Select(id discord.ComponentID) *SelectBuilder
type SelectBuilder ¶
type SelectBuilder struct {
// contains filtered or unexported fields
}
func (*SelectBuilder) Check ¶
func (b *SelectBuilder) Check(check Check[*SelectContext]) *SelectBuilder
Check adds a check to this select handler. The behaviour of the passed check is controlled by b.Once().
func (*SelectBuilder) Exec ¶
func (b *SelectBuilder) Exec(hn HandlerFunc[*SelectContext])
Exec adds this select to the router.
func (*SelectBuilder) Message ¶
func (b *SelectBuilder) Message(id discord.MessageID) *SelectBuilder
Message changes this Select interaction to be limited to a single message ID.
func (*SelectBuilder) Once ¶
func (b *SelectBuilder) Once() *SelectBuilder
Once changes this select interaction to only be listened for once. If the check fails, it will be silent, and the select will not be removed.
type SelectContext ¶
type SelectContext struct { *Context CustomID discord.ComponentID Values []string Data *discord.SelectInteraction }