slashy

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2022 License: MIT Imports: 3 Imported by: 0

README

slashy

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoCompleter

type AutoCompleter interface {
	// AutoComplete returns an array of choices that match the current input of
	// the Context. The focused option is used to determine which option is
	// currently focused and, accordingly, the choices should be filtered.
	AutoComplete(ctx *Context, focused *discordgo.ApplicationCommandInteractionDataOption) []*discordgo.ApplicationCommandOptionChoice
}

type AutoCompleterFunc

AutoCompleterFunc is a function that implements the AutoCompleter interface.

func (AutoCompleterFunc) AutoComplete

AutoComplete calls fn() itself and returns the result.

type CommandRoute

type CommandRoute struct {
	// Runner runs the CommandRoute within a given Context. Every CommandRoute must have
	// at least a Runner.
	Runner Runner `json:"runner,omitempty"`

	// AutoCompleter provides auto-completion for the CommandRoute. This is optional.
	AutoCompleter AutoCompleter `json:"autoCompleter,omitempty"`

	// ErrorResponder is the command's individual ErrorResponder used to
	// construct interaction responses from errors. If this is nil, the Router's
	// ErrorResponder is used.
	ErrorResponder ErrorResponder `json:"errorResponder,omitempty"`
}

type Context

type Context struct {
	*discordgo.InteractionCreate

	// Command is the command name that was used to invoke the interaction.
	Command string

	// Session is the session that received the interaction-create event. It can
	// be used to interact directly with Discord.
	Session *discordgo.Session
}

func (*Context) FocusedOption

FocusedOption searches for the first option that is focused and returns it. If no option is found, nil is returned instead.

func (*Context) Option

Option searches for the first option that matches the given name and returns it. If no option is found, nil is returned instead

Option names are case-insensitive. Therefore, "option" and "OPTION" are considered the same.

type ErrorResponder

type ErrorResponder interface {
	// RespondError mutates the given Response according to the given error.
	RespondError(ctx *Context, resp *Response, err error)
}

type ErrorResponderFunc

type ErrorResponderFunc func(ctx *Context, resp *Response, err error)

ErrorResponderFunc is a function that implements the ErrorResponder interface.

func (ErrorResponderFunc) RespondError

func (fn ErrorResponderFunc) RespondError(ctx *Context, resp *Response, err error)

RespondError calls fn() itself and returns the result.

type Response

type Response struct {
	// contains filtered or unexported fields
}

func (*Response) AddComponents

func (r *Response) AddComponents(components ...discordgo.MessageComponent) *Response

AddComponents adds the given components to the response message.

func (*Response) AddEmbeds

func (r *Response) AddEmbeds(embeds ...*discordgo.MessageEmbed) *Response

AddEmbeds adds the given embeds to the response message.

func (*Response) AddFiles

func (r *Response) AddFiles(files ...*discordgo.File) *Response

AddFiles adds the given files to the response message.

func (*Response) AllowedMentions

func (r *Response) AllowedMentions(allowedMentions *discordgo.MessageAllowedMentions) *Response

AllowedMentions updates the allowed mentions of the response message.

func (*Response) Components

func (r *Response) Components(components ...discordgo.MessageComponent) *Response

Components updates the components of the response message.

func (*Response) Content

func (r *Response) Content(content string) *Response

Content updates the content of the response message.

func (*Response) Embeds

func (r *Response) Embeds(embeds ...*discordgo.MessageEmbed) *Response

Embeds updates the embeds of the response message.

func (*Response) Files

func (r *Response) Files(files ...*discordgo.File) *Response

Files updates the files of the response message.

func (*Response) Flags

func (r *Response) Flags(suppress, ephemeral bool) *Response

Flags enables or disables the given flags on the response message.

func (*Response) TTS

func (r *Response) TTS(tts bool) *Response

TTS updates whether the response message should be sent as text-to-speech.

type Router

type Router struct {
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter(opts *RouterOptions) *Router

NewRouter returns a new router without any commands. The given options are used to change the behavior of the router. If nil is passed, the default options are used.

func (*Router) AutoBind

func (r *Router) AutoBind(name string, cmd Runner)

AutoBind binds the given CommandRoute to the given name. If the name is already taken, the existing CommandRoute is overwritten.

The difference between Bind and AutoBind is that AutoBind takes a Runner and

tests whether the Runner is also an AutoCompleter. If that is the case,

the AutoCompleter is bound to the CommandRoute.

CommandRoute names are case-insensitive. Therefore, "command" and "COMMAND" are considered the same. Note that the name is stored in the lower-case.

func (*Router) AutoBindAll

func (r *Router) AutoBindAll(cmds map[string]Runner)

AutoBindAll binds all commands in the given map to the Router using its AutoBind() method. For more details, see AutoBind().

func (*Router) Bind

func (r *Router) Bind(name string, cmd *CommandRoute)

Bind binds the given CommandRoute to the given name. If the name is already taken, the existing CommandRoute is overwritten.

CommandRoute names are case-insensitive. Therefore, "command" and "COMMAND" are considered the same. Note that the name is stored in the lower-case.

func (*Router) BindAll

func (r *Router) BindAll(cmds map[string]*CommandRoute)

BindAll binds all commands in the given map to the Router using its Bind() method. For more details, see Bind().

func (*Router) Route

func (r *Router) Route(ses *discordgo.Session, evt *discordgo.InteractionCreate)

Route handles an interaction create events and routes it to the appropriate CommandRoute. Unknown interaction types and commands are ignored.

type RouterOptions

type RouterOptions struct {
	// ErrorResponder is the ErrorResponder that is used to construct error
	// responses.
	ErrorResponder ErrorResponder
}

type Runner

type Runner interface {
	// Run executes the CommandRoute with the given context. If the CommandRoute fails,
	// the causing error is returned.
	//
	// The given Response is used to mutate the response message. The response
	// message is built after the CommandRoute is run successfully.
	Run(ctx *Context, resp *Response) error
}

type RunnerFunc

type RunnerFunc func(ctx *Context, resp *Response) error

RunnerFunc is a function that implements the Runner interface.

func (RunnerFunc) Run

func (fn RunnerFunc) Run(ctx *Context, resp *Response) error

Run calls fn() itself and returns the result.

Jump to

Keyboard shortcuts

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