cmd

package
v0.0.0-...-7404a93 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RBuildHelp

func RBuildHelp(c *Context, builder *strings.Builder, cmds []*Command, depth int)

Types

type Command

type Command struct {
	//Name is the primary trigger and is used for each level of a permission node
	Name        string
	Aliases     []string
	Description string
	//Usage format: http://docopt.org/
	Usage string
	//HideInHelp whether or not this should be hidden from the help command.
	HideInHelp  bool
	SubCommands []*Command
	Handler     ContextExecutor
}

Command holds information about a command and what to do

func (*Command) GeneratePermissionNode

func (c *Command) GeneratePermissionNode(baseNode string) []string

GeneratePermissionNode recursivly generates permission nodes for this and all subcommands and returns them

func (*Command) HasSubcommands

func (c *Command) HasSubcommands() bool

HasSubcommands returns whether or not this command holds subcommands

func (*Command) SPrintHelp

func (c *Command) SPrintHelp() string

SPrintHelp returns the command's Usage and Description formatted in a nice way

func (*Command) Triggers

func (c *Command) Triggers() []string

Triggers returns all strings (the command name and any aliases) that trigger this command

type Context

type Context struct {
	//The current discordgo.Session
	Session *discordgo.Session
	//The message that started this execution
	Message *discordgo.MessageCreate
	//The command being executed
	Command *Command
	//Command args (i.e. the split message content)
	Args []string
	//The router currently used
	Router *Router
}

Context holds all state for a command's execution

func (*Context) DB

func (ctx *Context) DB() *db.WadlDB

DB returns the current db.WadlDB instance

func (*Context) ReplyError

func (ctx *Context) ReplyError(err error) bool

ReplyError returns a generic error to the user

func (*Context) ReplyHelp

func (ctx *Context) ReplyHelp() *discordgo.Message

ReplyHelp prints the command's help text to the provided Context

func (*Context) ReplyString

func (ctx *Context) ReplyString(message string) *discordgo.Message

ReplyString replies to the contextual channel with the string provided. returns nil if an error occured while sending the message

func (*Context) ReplyStringf

func (ctx *Context) ReplyStringf(format string, a ...interface{}) *discordgo.Message

ReplyStringf replies to the contextual channel with the string provided

func (*Context) ReplyTimeDeleteStringf

func (ctx *Context) ReplyTimeDeleteStringf(delay time.Duration, format string, a ...interface{})

type ContextExecutor

type ContextExecutor func(*Context)

ContextExecutor represents an executor for a context execution

type Router

type Router struct {
	Commands   []*Command
	Prefix     string
	WadlDB     *db.WadlDB
	PermSystem *permissions.PermissionSystem
	Config     *cfg.Config
}

Router is the central command multiplexer

func BuildRouter

func BuildRouter(wdb *db.WadlDB, permSystem *permissions.PermissionSystem, cfg *cfg.Config) Router

BuildRouter returns a fully built router stuct with commands preregistered

func (*Router) Handler

func (r *Router) Handler() func(*discordgo.Session, *discordgo.MessageCreate)

Handler returns the func that deals with command delegates execution to command

func (*Router) RegisterCommands

func (r *Router) RegisterCommands(cmds []*Command)

RegisterCommands adds a command(s) to the Router

func (*Router) SetupPermissions

func (r *Router) SetupPermissions()

SetupPermissions generates permission nodes and adds references in the permission system

Jump to

Keyboard shortcuts

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