commands

package module
v0.0.0-...-36a4bd5 Latest Latest
Warning

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

Go to latest
Published: May 14, 2025 License: EUPL-1.2 Imports: 7 Imported by: 0

README

Router for Discordgo

Documentation

Overview

Package commands implements a command executor for Discordgo.

Index

Constants

View Source
const DiscordMessageMaxLength = 2000

DiscordMessageMaxLength is the maximum length a discord message may have.

Variables

This section is empty.

Functions

func HasCommandPrefix

func HasCommandPrefix(trigger string, command string, message string) bool

HasCommandPrefix determines whether or not a message has the given command prefix.

func SplitArgs

func SplitArgs(s string) []string

SplitArgs splits the arguments of a command into a string slice.

func StripPrefix

func StripPrefix(trigger string, command string) func(string) string

StripPrefix strips the prefix from a command.

Types

type Command

type Command interface {
	Name() string
	Apply(ctx *Context) error
	SkipsPrefix() bool
}

Command is a command to be executed.

func CommandFunc

func CommandFunc(literal bool, incantation string, f func(*Context) error) Command

CommandFunc defines a new command.

func NewCommand

func NewCommand(incantation string, f func(*Context) error) Command

NewCommand defines a new command.

func NewLiteral

func NewLiteral(incantation string, f func(*Context) error) Command

NewLiteral defines a new literal command.

type Context

type Context struct {
	Message *discordgo.Message
	Content string
	Args    []string
	Session *discordgo.Session
	Ctx     context.Context //nolint:containedctx // not long lived.
}

Context is the context that a command is running in.

func (*Context) Error

func (ctx *Context) Error(err error) (*discordgo.Message, error)

func (*Context) Reference

func (ctx *Context) Reference() *discordgo.MessageReference

Reference reports a reference to the message.

func (*Context) Reply

func (ctx *Context) Reply(s string) (*discordgo.Message, error)

Reply replies to a message.

func (*Context) ReplyList

func (ctx *Context) ReplyList(s []string) ([]*discordgo.Message, error)

ReplyList replies to a message using a list.

type Executor

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

Executor runs commands.

func NewCommandExecutor

func NewCommandExecutor(commands []Command, log *zap.Logger) *Executor

NewCommandExecutor builds a new command executor.

func (*Executor) Apply

func (e *Executor) Apply(ctx context.Context, trigger string, message *discordgo.Message, s *discordgo.Session)

Apply finds and executes a command.

func (*Executor) HasMatch

func (e *Executor) HasMatch(trigger string, message string) bool

HasMatch determines whether a message has a match on a registered command.

Directories

Path Synopsis
Package fx implements FX dependency injection module for commands.
Package fx implements FX dependency injection module for commands.

Jump to

Keyboard shortcuts

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