Documentation ¶
Index ¶
- Constants
- Variables
- func AddRootCommands(cmds ...*YAGCommand)
- func CensorError(err error) string
- func ChannelOverrideMiddleware(...) web.ControllerHandlerFunc
- func CmdNotFound(search string) string
- func ContextMS(ctx context.Context) *dstate.MemberState
- func FilterBadInvites(msg string, guildID int64, replacement string) string
- func FilterResp(in interface{}, guildID int64) interface{}
- func GetCommandPrefix(guild int64) (string, error)
- func HandleCommands(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
- func HandleCreateChannelsOverride(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
- func HandleCreateCommandOverride(w http.ResponseWriter, r *http.Request, ...) (web.TemplateData, error)
- func HandleDeleteChannelsOverride(w http.ResponseWriter, r *http.Request, ...) (web.TemplateData, error)
- func HandleDeleteCommandOverride(w http.ResponseWriter, r *http.Request, ...) (web.TemplateData, error)
- func HandleGuildCreate(evt *eventsystem.EventData)
- func HandlePostCommands(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
- func HandleUpdateChannelsOverride(w http.ResponseWriter, r *http.Request, ...) (web.TemplateData, error)
- func HandleUpdateCommandOVerride(w http.ResponseWriter, r *http.Request, ...) (web.TemplateData, error)
- func InitCommands()
- func ParseDuration(str string) (time.Duration, error)
- func RegisterPlugin()
- func TmplExecCmdFuncs(ctx *templates.Context, maxExec int, dryRun bool) (userCtxCommandExec cmdExecFunc, botCtxCommandExec cmdExecFunc)
- func YAGCommandMiddleware(inner dcmd.RunFunc) dcmd.RunFunc
- type ChannelOverrideForm
- type CommandOverrideForm
- type CommandProvider
- type CommandSettings
- type ContextKey
- type CtxKey
- type DurationArg
- type DurationOutOfRangeError
- type MessageFilterFunc
- type Plugin
- type PublicError
- type YAGCommand
- func (yc *YAGCommand) ArgDefs(data *dcmd.Data) (args []*dcmd.ArgDef, required int, combos [][]int)
- func (yc *YAGCommand) Category() *dcmd.Category
- func (cs *YAGCommand) CooldownLeft(userID int64) (int, error)
- func (yc *YAGCommand) Descriptions(data *dcmd.Data) (short, long string)
- func (cs *YAGCommand) GetSettings(data *dcmd.Data, channelID, channelParentID, guildID int64) (settings *CommandSettings, err error)
- func (yc *YAGCommand) GetTrigger() *dcmd.Trigger
- func (yc *YAGCommand) HumanizeError(err error) string
- func (yc *YAGCommand) Logger(data *dcmd.Data) *log.Entry
- func (yc *YAGCommand) PostCommandExecuted(settings *CommandSettings, cmdData *dcmd.Data, resp interface{}, err error)
- func (yc *YAGCommand) Run(data *dcmd.Data) (interface{}, error)
- func (cs *YAGCommand) SetCooldown(userID int64) error
- func (yc *YAGCommand) Switches() []*dcmd.ArgDef
Constants ¶
const DBSchema = `` /* 1331-byte string literal not displayed */
Variables ¶
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, } )
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 )
var (
CommandSystem *dcmd.System
)
var MessageFilterFuncs []MessageFilterFunc
These functions are called on every message, and should return true if the message should be checked for commands, false otherwise
Functions ¶
func AddRootCommands ¶
func AddRootCommands(cmds ...*YAGCommand)
func CensorError ¶
Keys and other sensitive information shouldnt be sent in error messages, but just in case it is
func ChannelOverrideMiddleware ¶ added in v1.4.1
func ChannelOverrideMiddleware(inner func(w http.ResponseWriter, r *http.Request, override *models.CommandsChannelsOverride) (web.TemplateData, error)) web.ControllerHandlerFunc
Channel override handlers
func CmdNotFound ¶
func FilterBadInvites ¶ added in v1.5.2
func FilterResp ¶ added in v1.6.0
func FilterResp(in interface{}, guildID int64) interface{}
func GetCommandPrefix ¶
func HandleCommands ¶
func HandleCommands(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
Servers the command page with current config
func HandleCreateChannelsOverride ¶ added in v1.4.1
func HandleCreateChannelsOverride(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
func HandleCreateCommandOverride ¶ added in v1.4.1
func HandleCreateCommandOverride(w http.ResponseWriter, r *http.Request, channelOverride *models.CommandsChannelsOverride) (web.TemplateData, error)
Command handlers
func HandleDeleteChannelsOverride ¶ added in v1.4.1
func HandleDeleteChannelsOverride(w http.ResponseWriter, r *http.Request, currentOverride *models.CommandsChannelsOverride) (web.TemplateData, error)
func HandleDeleteCommandOverride ¶ added in v1.4.1
func HandleDeleteCommandOverride(w http.ResponseWriter, r *http.Request, channelOverride *models.CommandsChannelsOverride) (web.TemplateData, error)
func HandleGuildCreate ¶
func HandleGuildCreate(evt *eventsystem.EventData)
func HandlePostCommands ¶
func HandlePostCommands(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
Handles the updating of global and per channel command settings
func HandleUpdateChannelsOverride ¶ added in v1.4.1
func HandleUpdateChannelsOverride(w http.ResponseWriter, r *http.Request, currentOverride *models.CommandsChannelsOverride) (web.TemplateData, error)
func HandleUpdateCommandOVerride ¶ added in v1.4.1
func HandleUpdateCommandOVerride(w http.ResponseWriter, r *http.Request, channelOverride *models.CommandsChannelsOverride) (web.TemplateData, error)
func InitCommands ¶ added in v1.4.1
func InitCommands()
func ParseDuration ¶
Parses a time string like 1day3h
func RegisterPlugin ¶
func RegisterPlugin()
Types ¶
type ChannelOverrideForm ¶ added in v1.4.1
type ChannelOverrideForm struct { Channels []int64 `valid:"channel,true` ChannelCategories []int64 `valid:"channel,true` Global bool CommandsEnabled bool AutodeleteResponse bool AutodeleteTrigger bool AutodeleteResponseDelay int AutodeleteTriggerDelay int RequireRoles []int64 `valid:"role,true"` IgnoreRoles []int64 `valid:"role,true"` }
type CommandOverrideForm ¶ added in v1.4.1
type CommandProvider ¶ added in v1.4.1
type CommandProvider interface {
// This is where you should register your commands, called on both the webserver and the bot
AddCommands()
}
type CommandSettings ¶ added in v1.4.1
type DurationArg ¶
func (*DurationArg) HelpName ¶
func (d *DurationArg) HelpName() string
type DurationOutOfRangeError ¶ added in v1.5.1
func (*DurationOutOfRangeError) Error ¶ added in v1.5.1
func (o *DurationOutOfRangeError) Error() string
type MessageFilterFunc ¶ added in v1.4.8
type PublicError ¶ added in v1.5.1
type PublicError string
func NewPublicError ¶ added in v1.5.1
func NewPublicError(a ...interface{}) PublicError
func NewPublicErrorF ¶ added in v1.5.1
func NewPublicErrorF(f string, a ...interface{}) PublicError
func (PublicError) Error ¶ added in v1.5.1
func (p PublicError) Error() 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 RequireDiscordPerms []int64 // Require users to have one of these permission sets to run the command // 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) 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(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) GetSettings ¶ added in v1.4.1
func (cs *YAGCommand) GetSettings(data *dcmd.Data, channelID, channelParentID, guildID int64) (settings *CommandSettings, err error)
GetSettings returns the settings from the command, generated from the servers channel and command overrides
func (*YAGCommand) GetTrigger ¶
func (yc *YAGCommand) GetTrigger() *dcmd.Trigger
func (*YAGCommand) HumanizeError ¶ added in v1.4.7
func (yc *YAGCommand) HumanizeError(err error) string
func (*YAGCommand) PostCommandExecuted ¶ added in v1.4.1
func (yc *YAGCommand) PostCommandExecuted(settings *CommandSettings, cmdData *dcmd.Data, resp interface{}, err error)
PostCommandExecuted sends the response and handles the trigger and response deletions
func (*YAGCommand) SetCooldown ¶
func (cs *YAGCommand) SetCooldown(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