Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var AllActions []Action
AllActions holds all actions that can be used by Grug
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct {
Name string // Name of the action
Exec func(*GrugSession, context.Context, ...interface{}) (interface{}, error) // Function that executes the action
}
Action is any named task
type ActionActivator ¶
type ActionActivator struct {
ActionName string `yaml:"action"` // Name of the action to execute
Arguments []interface{} `yaml:"args"` // Arguments taken by the action and their type
Store string `yaml:"store"` // If set, the result of the action is stored in a field with this name
FailurePlan *ActionSequence `yaml:"failurePlan"` // An action sequence to perform if this step fails during execution
HaltOnFail bool `yaml:"haltOnFailure"` // Whether or not to halt command execution on failure of this step
Conditional *ConditionalAction `yaml:"if"` // If set, this activator is considered an conditional and will instead alter flow of the sequence
}
ActionActivator is a YAML-(un)marshallable struct for storing the name of and arguments for an action
type ActionSequence ¶
type ActionSequence []ActionActivator
ActionSequence is a list of action activations to be performed in sequential order
type Command ¶
type Command struct {
Name string `yaml:"name"` // Descriptive name of the command
Description string `yaml:"desc"` // Description of the command
Activators []string `yaml:"activators"` // A list of ways to invoke the command
Plan ActionSequence `yaml:"plan"` // The action sequence to perform when the command is invoked
}
Command represents an invokable Grug command and holds its activators and execution plan
type ConditionalAction ¶
type ConditionalAction struct {
ActionName string `yaml:"condition"` // Name of the action performing the conditional
Arguments []interface{} `yaml:"args"` // Arguments taken by the conditional action
TrueSequence ActionSequence `yaml:"true"` // The action sequence to perform when the condition evaluates to true
FalseSequence ActionSequence `yaml:"false"` // The action sequence to perform when the condition evaluates to false
}
ConditionalAction represents a conditional part of an action sequence. Performs no action, but determines which action sequence is taken after evaluation
type GrugConfig ¶
type GrugConfig struct {
Name string `yaml:"name"` // Name of the bot
Token string `yaml:"token"` // Discord Bot Token to use
Invoker string `yaml:"invoker"` // The command prefix that invokes grug
Commands []string `yaml:"commands"` // A list of paths to command config files
Verbose bool `yaml:"verbose"` // Whether or not to use verbose logging
HardError bool `yaml:"hardError"` // If set to true, Grug will crash on panics in commands
}
GrugConfig holds the master configuration values for a Grug session
type GrugSession ¶
type GrugSession struct {
Config *GrugConfig // The Grug master config
Commands []Command // All loaded commands
Actions []Action // All actions used by Grug
ActivatorMap map[string]Command // Uniquely maps command name to Command struct
ActionMap map[string]Action // Uniquely maps action name to Action struct
ArgStore map[string]interface{} // Args stored after action executions go in here
}
GrugSession holds all information relevant to the operation of Grug
func (*GrugSession) HandleMessage ¶ added in v0.1.1
func (g *GrugSession) HandleMessage(msgCtx context.Context, msg string)
HandleMessage invokes commands based on the message. msgCtx is ultimately passed to all actions that are executed
func (*GrugSession) Log ¶
func (g *GrugSession) Log(level int, logMsg ...interface{})
Log prints a log message tagged with "GRUG" and the log level
func (*GrugSession) New ¶
func (g *GrugSession) New(cfgPath string)
New sets up a Grug session by parsing its master config, loading commands and establishing a Discord session