commands

package
v0.29.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2018 License: MIT Imports: 30 Imported by: 0

README

The commands plugin handles the configuration of the global command settings.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CategoryGeneral = &dcmd.Category{
		Name:        "General",
		Description: "General & informational commands",
		HelpEmoji:   "ℹ️",
		EmbedColor:  0xe53939,
	}
	CategoryTool = &dcmd.Category{
		Name:        "Tools & Utilities",
		Description: "Various miscellaneous commands",
		HelpEmoji:   "🔨",
		EmbedColor:  0xeaed40,
	}
	CategoryModeration = &dcmd.Category{
		Name:        "Moderation",
		Description: "Moderation commands",
		HelpEmoji:   "👮",
		EmbedColor:  0xdb0606,
	}
	CategoryFun = &dcmd.Category{
		Name:        "Fun",
		Description: "Various commands meant for entertainment",
		HelpEmoji:   "🎉",
		EmbedColor:  0x5ae26c,
	}
	CategoryDebug = &dcmd.Category{
		Name:        "Debug & Maintenance",
		Description: "Debug and other commands to inspect the bot",
		HelpEmoji:   "🖥",
		EmbedColor:  0,
	}
)
View Source
var (
	RKeyCommandCooldown = func(uID int64, cmd string) string { return "cmd_cd:" + discordgo.StrID(uID) + ":" + cmd }
	RKeyCommandLock     = func(uID int64, cmd string) string { return "cmd_lock:" + discordgo.StrID(uID) + ":" + cmd }

	CommandExecTimeout = time.Minute
)
View Source
var (
	CommandSystem *dcmd.System
)

Functions

func AddRootCommands

func AddRootCommands(cmds ...*YAGCommand)

func CensorError

func CensorError(err error) string

Keys and other sensitive information shouldnt be sent in error messages, but just in case it is

func CheckChannelsConfig

func CheckChannelsConfig(conf *CommandsConfig, channels []*discordgo.Channel)

Fills in the defaults for missing data, for when users create channels or commands are added

func CmdNotFound

func CmdNotFound(search string) string

func Dir

func Dir(useLocal bool, name string) http.FileSystem

Dir returns a http.Filesystem for the embedded assets on a given prefix dir. If useLocal is true, the filesystem's contents are instead used.

func FS

func FS(useLocal bool) http.FileSystem

FS returns a http.Filesystem for the embedded assets. If useLocal is true, the filesystem's contents are instead used.

func FSByte

func FSByte(useLocal bool, name string) ([]byte, error)

FSByte returns the named file from the embedded assets. If useLocal is true, the filesystem's contents are instead used.

func FSMustByte

func FSMustByte(useLocal bool, name string) []byte

FSMustByte is the same as FSByte, but panics if name is not present.

func FSMustString

func FSMustString(useLocal bool, name string) string

FSMustString is the string version of FSMustByte.

func FSString

func FSString(useLocal bool, name string) (string, error)

FSString is the string version of FSByte.

func GetCommandPrefix

func GetCommandPrefix(client *redis.Client, guild int64) (string, error)

func HandleCommands

func HandleCommands(w http.ResponseWriter, r *http.Request) interface{}

Servers the command page with current config

func HandleGuildCreate

func HandleGuildCreate(evt *eventsystem.EventData)

func HandlePostCommands

func HandlePostCommands(w http.ResponseWriter, r *http.Request) interface{}

Handles the updating of global and per channel command settings

func ParseDuration

func ParseDuration(str string) (time.Duration, error)

Parses a time string like 1day3h

func RegisterPlugin

func RegisterPlugin()

func TmplExecCmdFuncs

func TmplExecCmdFuncs(ctx *templates.Context, maxExec int, dryRun bool) (userCtxCommandExec cmdExecFunc, botCtxCommandExec cmdExecFunc)

Returns 2 functions to execute commands in user or bot context with limited about of commands executed

Types

type ChannelCommandSetting

type ChannelCommandSetting struct {
	Info           *YAGCommand `json:"-"` // Used for template info
	Cmd            string      `json:"cmd"`
	CommandEnabled bool        `json:"enabled"`
	AutoDelete     bool        `json:"autodelete"`
	RequiredRole   string      `json:"required_role"`
}

type ChannelOverride

type ChannelOverride struct {
	Settings        []*ChannelCommandSetting `json:"settings"`
	OverrideEnabled bool                     `json:"enabled"`
	Channel         string                   `json:"channel"`
	ChannelName     string                   `json:"-"` // Used for the template rendering
}

type CommandsConfig

type CommandsConfig struct {
	Prefix string `json:"-"` // Stored in a seperate key for speed

	Global           []*ChannelCommandSetting `json:"gloabl"`
	ChannelOverrides []*ChannelOverride       `json:"overrides"`
}

func GetConfig

func GetConfig(client *redis.Client, guild int64, channels []*discordgo.Channel) *CommandsConfig

type ContextKey

type ContextKey int
const (
	CtxKeyRedisClient ContextKey = iota
)

type DurationArg

type DurationArg struct{}

func (*DurationArg) HelpName

func (d *DurationArg) HelpName() string

func (*DurationArg) Matches

func (d *DurationArg) Matches(part string) bool

func (*DurationArg) Parse

func (d *DurationArg) Parse(part string, data *dcmd.Data) (interface{}, error)

type Plugin

type Plugin struct{}

func (*Plugin) InitBot

func (p *Plugin) InitBot()

func (*Plugin) InitWeb

func (p *Plugin) InitWeb()

func (*Plugin) Name

func (p *Plugin) Name() string

func (*Plugin) Prefix

func (p *Plugin) Prefix(data *dcmd.Data) string

type YAGCommand

type YAGCommand struct {
	Name            string   // Name of command, what its called from
	Aliases         []string // Aliases which it can also be called from
	Description     string   // Description shown in non targetted help
	LongDescription string   // Longer description when this command was targetted

	Arguments      []*dcmd.ArgDef // Slice of argument definitions, ctx.Args will always be the same size as this slice (although the data may be nil)
	RequiredArgs   int            // Number of reuquired arguments, ignored if combos is specified
	ArgumentCombos [][]int        // Slice of argument pairs, will override RequiredArgs if specified
	ArgSwitches    []*dcmd.ArgDef // Switches for the commadn to use

	AllowEveryoneMention bool

	HideFromCommandsPage bool   // Set to  hide this command from the commands page
	Key                  string // GuildId is appended to the key, e.g if key is "test:", it will check for "test:<guildid>"
	CustomEnabled        bool   // Set to true to handle the enable check itself
	Default              bool   // The default enabled state of this command

	Cooldown    int // Cooldown in seconds before user can use it again
	CmdCategory *dcmd.Category

	RunInDM      bool // Set to enable this commmand in DM's
	HideFromHelp bool // Set to hide from help

	// Run is ran the the command has sucessfully been parsed
	// It returns a reply and an error
	// the reply can have a type of string, *MessageEmbed or error
	RunFunc dcmd.RunFunc
}

Slight extension to the simplecommand, it will check if the command is enabled in the HandleCommand func And invoke a custom handlerfunc with provided redis client

func (*YAGCommand) ArgDefs

func (yc *YAGCommand) ArgDefs(data *dcmd.Data) (args []*dcmd.ArgDef, required int, combos [][]int)

func (*YAGCommand) Category

func (yc *YAGCommand) Category() *dcmd.Category

CmdWithCategory puts the command in a category, mostly used for the help generation

func (*YAGCommand) CooldownLeft

func (cs *YAGCommand) CooldownLeft(client *redis.Client, userID int64) (int, error)

CooldownLeft returns the number of seconds before a command can be used again

func (*YAGCommand) Descriptions

func (yc *YAGCommand) Descriptions(data *dcmd.Data) (short, long string)

func (*YAGCommand) Enabled

func (cs *YAGCommand) Enabled(client *redis.Client, channel int64, gState *dstate.GuildState) (enabled bool, requiredRole int64, autodel bool, err error)

Enabled returns wether the command is enabled or not

func (*YAGCommand) GetTrigger

func (yc *YAGCommand) GetTrigger() *dcmd.Trigger

func (*YAGCommand) Logger

func (yc *YAGCommand) Logger(data *dcmd.Data) *log.Entry

func (*YAGCommand) Run

func (yc *YAGCommand) Run(data *dcmd.Data) (interface{}, error)

func (*YAGCommand) SendResponse

func (yc *YAGCommand) SendResponse(cmdData *dcmd.Data, resp interface{}, err error) (replies []*discordgo.Message, errR error)

func (*YAGCommand) SetCooldown

func (cs *YAGCommand) SetCooldown(client *redis.Client, userID int64) error

SetCooldown sets the cooldown of the command as it's defined in the struct

func (*YAGCommand) Switches

func (yc *YAGCommand) Switches() []*dcmd.ArgDef

Jump to

Keyboard shortcuts

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