command

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arguments

type Arguments interface {

	// GetInt returns the integer value of an argument
	GetInt(name string) int

	// GetString returns the string value of an argument
	GetString(name string) string
}

Arguments represents a command arguments

type Command

type Command interface {

	// Name returns the command name
	Name() (name string)

	// Execute the command
	Execute(client client.Client, event Event) (err error)
}

Command represents a command

type CommandBuilder

type CommandBuilder interface {

	// AddInt adds an integer argument to the command
	AddInt(name string) CommandBuilder

	// AddString adds a string argument to the command
	AddString(name string) CommandBuilder

	// AddRest add the rest of the arguments concatenated with a whitespace to the command
	AddRest(name string) CommandBuilder

	// AddFilter adds a channel filter for the command
	AddFilter(filter FilterFn) CommandBuilder

	// Resolver sets the command resolver
	Resolver(CommandFn) CommandBuilder

	// Build the command
	Build() Command
}

CommandBuilder allows to build commands

func NewCommandBuilder

func NewCommandBuilder(name string) CommandBuilder

NewCommandBuilder creates a command builder

type CommandFn

type CommandFn func(client client.Client, event Event, arguments Arguments) error

CommandFn is the resolver function for a command

type Event

type Event struct {

	// UserID is the user that performed the command
	UserID string

	// UserPermission holds the user permission
	UserPermissions int64

	// GuildID is the guild where the command was performed
	GuildID string

	// CategoryID is the category where the command was performed
	CategoryID string

	// ChannelID is the channel where the command was performed
	ChannelID string

	// MessageID holds the message where the command was performed
	MessageID string

	// 	Params holds the command params a string that was executed
	Params string
}

type FilterFn

type FilterFn func(event Event) (skip bool)

FilterFn is a function used to filter commands

type Lexer

type Lexer interface {

	// HasNext returns true while the lexer has more token to read.
	HasNext() bool

	// Next returns the next token as string
	Next() (string, error)
}

Lexer tokenizes commands

type Parser

type Parser interface {

	// ReadInt reads an int from the input command
	ReadInt() (int, error)

	// ReadString reads a string from the input
	ReadString() (string, error)

	// ReadRest reads the rest of the input command and returns a string that concatenates remaining tokens using space
	ReadRest() (string, error)
}

Parser represents a command parser

Jump to

Keyboard shortcuts

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