route

package
v0.8.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MiddlewareTriggerValid MiddlewareTrigger = 1 << iota
	MiddlewareTriggerInvalid
	MiddlewareTriggerReactionAdd
	MiddlewareTriggerReactionRemove

	MiddlewareTriggerAllMessages  = MiddlewareTriggerInvalid | MiddlewareTriggerValid
	MiddlewareTriggerAllReactions = MiddlewareTriggerReactionAdd | MiddlewareTriggerReactionRemove

	MiddlewareTriggerEverything = MiddlewareTriggerAllMessages | MiddlewareTriggerAllReactions
)

Variables

View Source
var ChannelMention = channelMentionType{}

ChannelMention will validate a Discord channel mention and return the channel ID from that

View Source
var DiscordSnowflake = discordSnowflakeType{}

DiscordSnowflake will validate a Discord snowflake and return a string value

View Source
var Duration = durationType{}

Duration will parse a single duration in the form 1d2h3m4s

View Source
var Integer = integerType{}

Integer will parse a single integer

View Source
var RemainingString = remainingStringType{}

RemainingString will parse a the remainder of the message as a string

View Source
var String = stringType{}

String will parse a single (quote enclosed) string

View Source
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

type ArgumentInfo struct {
	Name       string
	Type       string
	Usage      string
	HasDefault bool
}

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 added in v0.2.0

type CommonContext struct {
	Session *discordgo.Session
	Kit     *Kit
}

func (*CommonContext) DefaultAllowedMentions added in v0.2.0

func (m *CommonContext) DefaultAllowedMentions() *discordgo.MessageAllowedMentions

func (*CommonContext) SendMessageEmbed added in v0.2.0

func (m *CommonContext) SendMessageEmbed(channelId string, embed *discordgo.MessageEmbed) (*discordgo.Message, error)

func (*CommonContext) SendMessageString added in v0.2.0

func (m *CommonContext) SendMessageString(channelId string, content string) (*discordgo.Message, error)

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 NewKit

func NewKit(session *discordgo.Session, prefixes []string) *Kit

NewKit creates a new Kit instance

func (*Kit) AddCommand

func (b *Kit) AddCommand(commands ...*Command)

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 added in v0.6.0

func (b *Kit) AddMiddleware(middlewares ...*Middleware)

AddMiddleware adds a middleware to the middleware set for this instance of Kit

func (*Kit) AddReaction

func (b *Kit) AddReaction(reactions ...*Reaction)

AddReaction adds a reaction create handler to the reaction set for this instance of Kit

func (*Kit) AddTemporaryMessageHandler added in v0.7.0

func (b *Kit) AddTemporaryMessageHandler(handler MessageRunFunc) int

AddTemporaryMessageHandler creates registers a temporary message handler and returns the created handler's ID.

func (*Kit) AddTemporaryReaction added in v0.2.0

func (b *Kit) AddTemporaryReaction(reaction *Reaction) int

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) GetNums added in v0.5.1

func (b *Kit) GetNums() (int, int)

func (*Kit) NewConfirmation added in v0.2.0

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 added in v0.5.0

func (b *Kit) NewPaginate(channelId string, userId string, embeds []*discordgo.MessageEmbed, timeout time.Duration) error

func (*Kit) RemoveTemporaryMessageHandler added in v0.7.0

func (b *Kit) RemoveTemporaryMessageHandler(id int)

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 added in v0.2.0

func (b *Kit) RemoveTemporaryReaction(id int)

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 added in v0.6.0

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 added in v0.6.0

type Middleware struct {
	Name    string
	Run     func(interface{}) error
	Trigger MiddlewareTrigger
}

type MiddlewareTrigger added in v0.6.0

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL