Documentation ¶
Index ¶
- Constants
- Variables
- type Argument
- type ArgumentInfo
- type ArgumentType
- type Command
- type CommandInfo
- type CommandRestriction
- type CommonContext
- func (m *CommonContext) DefaultAllowedMentions() *discordgo.MessageAllowedMentions
- func (m *CommonContext) SendMessageEmbed(channelId string, embed *discordgo.MessageEmbed) (*discordgo.Message, error)
- func (m *CommonContext) SendMessageString(channelId string, content string) (*discordgo.Message, error)
- type Kit
- func (b *Kit) AddCommand(commands ...*Command)
- func (b *Kit) AddMiddleware(middlewares ...*Middleware)
- func (b *Kit) AddReaction(reactions ...*Reaction)
- func (b *Kit) AddTemporaryMessageHandler(handler MessageRunFunc) int
- func (b *Kit) AddTemporaryReaction(reaction *Reaction) int
- func (b *Kit) CreateHandlers()
- func (b *Kit) GetCommandInfo() []*CommandInfo
- func (b *Kit) GetNums() (int, int)
- func (b *Kit) NewConfirmation(channelId string, userId string, embed *discordgo.MessageEmbed, ...) error
- func (b *Kit) NewPaginate(channelId string, userId string, embeds []*discordgo.MessageEmbed, ...) error
- func (b *Kit) RemoveTemporaryMessageHandler(id int)
- func (b *Kit) RemoveTemporaryReaction(id int)
- type MessageContext
- type MessageRunFunc
- type Middleware
- type MiddlewareTrigger
- type Reaction
- type ReactionContext
- type ReactionEvent
- type ReactionRunFunc
Constants ¶
const ( MiddlewareTriggerValid MiddlewareTrigger = 1 << iota MiddlewareTriggerInvalid MiddlewareTriggerReactionAdd MiddlewareTriggerReactionRemove MiddlewareTriggerAllMessages = MiddlewareTriggerInvalid | MiddlewareTriggerValid MiddlewareTriggerAllReactions = MiddlewareTriggerReactionAdd | MiddlewareTriggerReactionRemove MiddlewareTriggerEverything = MiddlewareTriggerAllMessages | MiddlewareTriggerAllReactions )
Variables ¶
var ChannelMention = channelMentionType{}
ChannelMention will validate a Discord channel mention and return the channel ID from that
var DiscordSnowflake = discordSnowflakeType{}
DiscordSnowflake will validate a Discord snowflake and return a string value
var Duration = durationType{}
Duration will parse a single duration in the form 1d2h3m4s
var Integer = integerType{}
Integer will parse a single integer
var RemainingString = remainingStringType{}
RemainingString will parse a the remainder of the message as a string
var String = stringType{}
String will parse a single (quote enclosed) string
var URL = urlType{}
URL will parse a single URL
Functions ¶
This section is empty.
Types ¶
type Argument ¶
type Argument struct { Name string Type ArgumentType Default func(session *discordgo.Session, message *discordgo.MessageCreate) (interface{}, error) }
Argument represents an argument in a command
type ArgumentInfo ¶
ArgumentInfo contains textual information about a command argument
type ArgumentType ¶
type ArgumentType interface { // Parse should consume the argument is has parsed Parse(content *string) (interface{}, error) // Name should return the readable name of the type, eg "integer" or "string" Name() string Help(name string) string }
ArgumentType defines a possible argument, how to parse it and generates relevant help text
type Command ¶
type Command struct { Name string Help string CommandText []string Arguments []Argument Restrictions []CommandRestriction Run MessageRunFunc Invisible bool // prevent command from being shown in *kit.GetCommandInfo AllowOverloading bool Category uint // contains filtered or unexported fields }
Command represents a command
type CommandInfo ¶
type CommandInfo struct { Name string Description string CommandText string HasRestrictions bool Category uint Arguments []*ArgumentInfo }
CommandInfo contains textual information about a command
type CommandRestriction ¶
type CommandRestriction func(session *discordgo.Session, message *discordgo.MessageCreate) (bool, error)
CommandRestriction is a function that returns true if a command can be run based on the current state (eg. details about the user, roles, channel, etc)
func RestrictionByChannel ¶
func RestrictionByChannel(channelIds ...string) CommandRestriction
RestrictionByChannel creates a CommandRestriction that requires the command to have been sent in a channel with a given ID
func RestrictionByRole ¶
func RestrictionByRole(roleIds ...string) CommandRestriction
RestrictionByRole creates a CommandRestriction that requires the commanding guild member to have a given role ID
type CommonContext ¶
func (*CommonContext) DefaultAllowedMentions ¶
func (m *CommonContext) DefaultAllowedMentions() *discordgo.MessageAllowedMentions
func (*CommonContext) SendMessageEmbed ¶
func (m *CommonContext) SendMessageEmbed(channelId string, embed *discordgo.MessageEmbed) (*discordgo.Message, error)
func (*CommonContext) SendMessageString ¶
type Kit ¶
type Kit struct { Session *discordgo.Session ErrorHandler func(error) Prefixes []string IsCaseSensitive bool DebugMode bool AllowBots bool DefaultAllowedMentions discordgo.MessageAllowedMentions AllowDirectMessages bool UserErrorFunc func(string) string // contains filtered or unexported fields }
Kit is the core model for command parsing and routing
func (*Kit) AddCommand ¶
AddCommand adds commands to the command set for this instance of Kit. Command overloading is supported for commands that have AllowOverloading set true. If more than one command is matched by an incoming message, the command that was added to the Kit first is run.
func (*Kit) AddMiddleware ¶
func (b *Kit) AddMiddleware(middlewares ...*Middleware)
AddMiddleware adds a middleware to the middleware set for this instance of Kit
func (*Kit) AddReaction ¶
AddReaction adds a reaction create handler to the reaction set for this instance of Kit
func (*Kit) AddTemporaryMessageHandler ¶
func (b *Kit) AddTemporaryMessageHandler(handler MessageRunFunc) int
AddTemporaryMessageHandler creates registers a temporary message handler and returns the created handler's ID.
func (*Kit) AddTemporaryReaction ¶
AddTemporaryReaction creates registers a temporary reaction handler and returns the created handler's ID.
func (*Kit) CreateHandlers ¶
func (b *Kit) CreateHandlers()
func (*Kit) GetCommandInfo ¶
func (b *Kit) GetCommandInfo() []*CommandInfo
GetCommandInfo returns information about all commands in the kit (intended for use in help commands)
func (*Kit) NewConfirmation ¶
func (b *Kit) NewConfirmation(channelId string, userId string, embed *discordgo.MessageEmbed, acceptFunc ReactionRunFunc, rejectFunc ReactionRunFunc) error
NewConfirmation will create a new confirmation embed in the channel with the ID channelId. If userID is specified, reactions by users other than the user with that ID are ignored - else, all reactions are accepted. acceptFunc and rejectFunc can also be nil.
func (*Kit) NewPaginate ¶
func (*Kit) RemoveTemporaryMessageHandler ¶
RemoveTemporaryMessageHandler removes a temporary message handler based on the provided ID. If the ID does not exist, RemoveTemporaryMessageHandler is a no-op.
func (*Kit) RemoveTemporaryReaction ¶
RemoveTemporaryReaction removes a temporary reaction handler based on the provided ID. If the ID does not exist, RemoveTemporaryReaction is a no-op.
type MessageContext ¶
type MessageContext struct { *CommonContext Message *discordgo.MessageCreate Arguments map[string]interface{} Raw string // Command must not be modified Command *Command }
func (*MessageContext) GetCommandInfo ¶
func (m *MessageContext) GetCommandInfo() []*CommandInfo
GetCommandInfo returns information about all commands in the kit (intended for use in help commands)
func (*MessageContext) SendErrorMessage ¶
func (m *MessageContext) SendErrorMessage(problem string) error
SendErrorMessage sends a Discord message containing error information using kit.UserErrorFunc
type MessageRunFunc ¶
type MessageRunFunc func(ctx *MessageContext) error
type Middleware ¶
type Middleware struct { Name string Run func(interface{}) error Trigger MiddlewareTrigger }
type MiddlewareTrigger ¶
type MiddlewareTrigger uint
type Reaction ¶
type Reaction struct { Name string Run ReactionRunFunc Event ReactionEvent }
Reaction represents a new reaction handler
type ReactionContext ¶
type ReactionContext struct { *CommonContext Reaction *discordgo.MessageReaction Event ReactionEvent }
type ReactionEvent ¶
type ReactionEvent uint8
ReactionEvent represents a the type of reaction event that has been triggered
const ( ReactionAdd ReactionEvent = iota ReactionRemove )
type ReactionRunFunc ¶
type ReactionRunFunc func(ctx *ReactionContext) error