help

package
v0.0.0-...-4e18fe8 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2021 License: MIT Imports: 12 Imported by: 1

Documentation

Overview

Package help provides the default help command. It is used to create help messages that can list all commands and modules, commands and modules in a specific module, and details about a command.

Index

Constants

This section is empty.

Variables

View Source
var BaseEmbed = msgbuilder.NewEmbed().
	WithColor(0x6eb7b1)

Functions

func DefaultArgFormatter

func DefaultArgFormatter(name, _ string, optional, variadic bool) string

Types

type ArgFormatter

type ArgFormatter func(name, typeName string, optional, variadic bool) string

type Help

Help is the default help command. It should fully suffice for most bots, however, it is limited to the same restrictions any embed has. Particularly, the following rules apply:

You can have at most 23 top-level modules and any amount of top-level commands, or 24 top-level modules and no top-level commands.

The total amount characters used for listing all top-level commands, as well as the commands of individual modules, may not exceed 1024. Otherwise, another embed field will be used, which means the number of allowed top-level modules shrinks by one.

The total amount of characters of the embed cannot exceed 6000. A few of those are already taken, to display title and prefixes.

Note also that some commands may be cut off, in order to stay within that character limit.

func New

func New(o Options) *Help

New creates a new help command using the passed Options.

func (*Help) Invoke

func (h *Help) Invoke(s *state.State, ctx *plugin.Context) (interface{}, error)

type HiddenLevel

type HiddenLevel uint8
const (
	// Show is the HiddenLevel used if the command should be shown.
	Show HiddenLevel = iota
	// HideList is the HiddenLevel used if the command should be hidden from
	// command lists, i.e. from the general help page, and it's parent
	// module's help pages, if it has any.
	//
	// It will still be shown, if directly requesting it.
	HideList
	// Hide is the HiddenLevel used if the command should not be shown at all,
	// i.e. neither through command lists nor if asking directly for it.
	Hide
)

func (HiddenLevel) Allows

func (a HiddenLevel) Allows(b HiddenLevel) bool

Allows checks if this HiddenLevel would allow a plugin with the given HiddenLevel to be shown.

type HideFunc

func CheckChannelTypes

func CheckChannelTypes(lvl HiddenLevel) HideFunc

CheckChannelTypes returns a HideFunc that checks if the commands plugin.ChannelTypes match those of the invoking channel, and returns the passed HiddenLevel if not.

If an error occurs, it will be handled silently and Show will be returned.

func CheckHidden

func CheckHidden(lvl HiddenLevel) HideFunc

CheckHidden returns a HideFunc that returns the passed HiddenLevel, if the checked command is marked as Hidden.

func CheckRestrictions

func CheckRestrictions(lvl HiddenLevel) HideFunc

CheckRestrictions returns a HideFunc that returns the passed HiddenLevel, if the checked command is restricted. If plugin.ResolvedCommand.IsRestricted returns an error that fulfills errors.As(err, **plugin.RestrictionError) and that is fatal, lvl is returned. Otherwise, Show is returned.

type Options

type Options struct {
	// HideFuncs are the functions used to determine the HiddenLevel of a
	// command.
	// The highest HiddenLevel returned by any the functions will be used.
	// Invalid HiddenLevels will default to Hide.
	//
	// Modules may also be hidden as a result of this, if all their commands
	// are hidden.
	// If that is the case, the lowest HiddenLevel any subcommand of the module
	// has, will be used for that module.
	//
	// Defaults to:
	// 	[]HideFunc{
	// 		CheckHidden(HideList), CheckChannelTypes(HideList),
	//		CheckRestrictions(HideList),
	//	}
	//
	// Use an empty slice to always show commands.
	HideFuncs []HideFunc
	// NoPrefix toggles whether in a guild the all embed should list the
	// available prefixes.
	NoPrefix bool

	// Aliases are the aliases of the help command.
	//
	// Defaults to []string{"h", "how"}.
	// Use an empty slice to use no aliases.
	Aliases []string

	// ArgFormatter is the plugin.ArgFormatter used to generate command usages.
	//
	// Defaults to DefaultArgFormatter
	ArgFormatter ArgFormatter
}

Jump to

Keyboard shortcuts

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