Documentation ¶
Index ¶
- Constants
- Variables
- func BotCachedGetCommandsWithMessageTriggers(gs *dstate.GuildState, ctx context.Context) ([]*models.CustomCommand, error)
- func CalcNextRunTime(cc *models.CustomCommand, now time.Time) time.Time
- func CheckGuildDBLimit(gs *dstate.GuildState) (bool, error)
- func CheckIntervalLimits(ctx context.Context, guildID int64, cmdID int64, templateData web.TemplateData) (ok bool, err error)
- func CheckLimits(in ...string) bool
- func CheckMatch(globalPrefix string, cmd *models.CustomCommand, msg string) (match bool, stripped string, args []string)
- func CmdRunsForUser(cc *models.CustomCommand, ms *dstate.MemberState) bool
- func CmdRunsInChannel(cc *models.CustomCommand, channel int64) bool
- func DelNextRunEvent(guildID int64, cmdID int64) error
- func ExecuteCustomCommand(cmd *models.CustomCommand, tmplCtx *templates.Context) error
- func ExecuteCustomCommandFromMessage(cmd *models.CustomCommand, member *dstate.MemberState, cs *dstate.ChannelState, ...) error
- func FindCommands(ccs []*models.CustomCommand, data *dcmd.Data) (foundCCS []*models.CustomCommand, provided bool)
- func HandleCommands(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
- func HandleDeleteCommand(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
- func HandleDeleteGroup(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
- func HandleGetCommandsGroup(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
- func HandleMessageCreate(evt *eventsystem.EventData)
- func HandleNewCommand(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
- func HandleNewGroup(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
- func HandleUpdateCommand(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
- func HandleUpdateGroup(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
- func KeyCommands(guildID int64) string
- func MaxCommandsForContext(ctx context.Context) int
- func RegisterPlugin()
- func ServeGroupSelected(r *http.Request, templateData web.TemplateData, groupID int64, guildID int64) (web.TemplateData, error)
- func StringCommands(ccs []*models.CustomCommand) string
- func UpdateCommandNextRunTime(cc *models.CustomCommand, updateLastRun bool) error
- type CCExecKey
- type CacheKey
- type CommandTriggerType
- type CustomCommand
- type CustomCommandSlice
- type DelayedRunCCData
- type DelayedRunLimitKey
- type GroupForm
- type LightDBEntry
- type NextRunScheduledEvent
- type ParsedArgs
- type Plugin
Constants ¶
const ( MaxCommands = 100 MaxCommandsPremium = 250 MaxUserMessages = 20 MaxGroups = 50 )
const DBSchema = `` /* 1801-byte string literal not displayed */
Variables ¶
var ( CCExecLock = keylock.NewKeyLock() DelayedCCRunLimit = multiratelimit.NewMultiRatelimiter(0.1, 10) )
var ( AllTriggerTypes = []CommandTriggerType{ CommandTriggerCommand, CommandTriggerStartsWith, CommandTriggerContains, CommandTriggerRegex, CommandTriggerExact, CommandTriggerInterval, } )
var (
RegexCache = *ccache.New(ccache.Configure())
)
Functions ¶
func BotCachedGetCommandsWithMessageTriggers ¶ added in v1.14.0
func BotCachedGetCommandsWithMessageTriggers(gs *dstate.GuildState, ctx context.Context) ([]*models.CustomCommand, error)
func CalcNextRunTime ¶ added in v1.14.0
func CheckGuildDBLimit ¶ added in v1.17.0
func CheckGuildDBLimit(gs *dstate.GuildState) (bool, error)
returns true if were above db limit for the specified guild
func CheckIntervalLimits ¶ added in v1.14.0
func CheckIntervalLimits(ctx context.Context, guildID int64, cmdID int64, templateData web.TemplateData) (ok bool, err error)
allow for max 5 triggers with intervals of less than 10 minutes
func CheckLimits ¶
func CheckMatch ¶
func CheckMatch(globalPrefix string, cmd *models.CustomCommand, msg string) (match bool, stripped string, args []string)
CheckMatch returns true if the given cmd matches, as well as the arguments following the command trigger (arg 0 being the message up to, and including, the trigger).
func CmdRunsForUser ¶ added in v1.14.0
func CmdRunsForUser(cc *models.CustomCommand, ms *dstate.MemberState) bool
func CmdRunsInChannel ¶ added in v1.14.0
func CmdRunsInChannel(cc *models.CustomCommand, channel int64) bool
func DelNextRunEvent ¶ added in v1.14.0
func ExecuteCustomCommand ¶
func ExecuteCustomCommand(cmd *models.CustomCommand, tmplCtx *templates.Context) error
func ExecuteCustomCommand(cmd *models.CustomCommand, cmdArgs []string, stripped string, s *discordgo.Session, m *discordgo.MessageCreate) (resp string, tmplCtx *templates.Context, err error) {
func ExecuteCustomCommandFromMessage ¶ added in v1.14.0
func ExecuteCustomCommandFromMessage(cmd *models.CustomCommand, member *dstate.MemberState, cs *dstate.ChannelState, cmdArgs []string, stripped string, m *discordgo.Message) error
func FindCommands ¶
func FindCommands(ccs []*models.CustomCommand, data *dcmd.Data) (foundCCS []*models.CustomCommand, provided bool)
func HandleCommands ¶
func HandleCommands(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
func HandleDeleteCommand ¶
func HandleDeleteCommand(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
func HandleDeleteGroup ¶ added in v1.14.0
func HandleDeleteGroup(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
func HandleGetCommandsGroup ¶ added in v1.14.0
func HandleGetCommandsGroup(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
func HandleMessageCreate ¶
func HandleMessageCreate(evt *eventsystem.EventData)
func HandleNewCommand ¶
func HandleNewCommand(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
func HandleNewGroup ¶ added in v1.14.0
func HandleNewGroup(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
func HandleUpdateCommand ¶
func HandleUpdateCommand(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
func HandleUpdateGroup ¶ added in v1.14.0
func HandleUpdateGroup(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
func KeyCommands ¶
func MaxCommandsForContext ¶ added in v1.6.0
func RegisterPlugin ¶
func RegisterPlugin()
func ServeGroupSelected ¶ added in v1.14.0
func ServeGroupSelected(r *http.Request, templateData web.TemplateData, groupID int64, guildID int64) (web.TemplateData, error)
func StringCommands ¶
func StringCommands(ccs []*models.CustomCommand) string
func UpdateCommandNextRunTime ¶ added in v1.14.0
func UpdateCommandNextRunTime(cc *models.CustomCommand, updateLastRun bool) error
TODO: Run this all in a transaction?
Types ¶
type CommandTriggerType ¶
type CommandTriggerType int
const ( CommandTriggerCommand CommandTriggerType = 0 CommandTriggerStartsWith CommandTriggerType = 1 CommandTriggerContains CommandTriggerType = 2 CommandTriggerRegex CommandTriggerType = 3 CommandTriggerExact CommandTriggerType = 4 CommandTriggerInterval CommandTriggerType = 5 )
func TriggerTypeFromForm ¶
func TriggerTypeFromForm(str string) CommandTriggerType
func (CommandTriggerType) String ¶
func (t CommandTriggerType) String() string
type CustomCommand ¶
type CustomCommand struct { TriggerType CommandTriggerType `json:"trigger_type"` TriggerTypeForm string `json:"-" schema:"type"` Trigger string `json:"trigger" schema:"trigger" valid:",0,1000"` // TODO: Retire the legacy Response field. Response string `json:"response,omitempty" schema:"response" valid:"template,10000"` Responses []string `json:"responses" schema:"responses" valid:"template,10000"` CaseSensitive bool `json:"case_sensitive" schema:"case_sensitive"` ID int64 `json:"id"` ContextChannel int64 `schema:"context_channel" valid:"channel,true"` TimeTriggerInterval int `schema:"time_trigger_interval"` TimeTriggerExcludingDays []int64 `schema:"time_trigger_excluding_days"` TimeTriggerExcludingHours []int64 `schema:"time_trigger_excluding_hours"` // If set, then the following channels are required, otherwise they are ignored RequireChannels bool `json:"require_channels" schema:"require_channels"` Channels []int64 `json:"channels" schema:"channels"` // If set, then one of the following channels are required, otherwise they are ignored RequireRoles bool `json:"require_roles" schema:"require_roles"` Roles []int64 `json:"roles" schema:"roles"` GroupID int64 }
func LegacyGetCommands ¶ added in v1.14.0
func LegacyGetCommands(guild int64) ([]*CustomCommand, int64, error)
func (*CustomCommand) Migrate ¶ added in v0.29.1
func (cc *CustomCommand) Migrate() *CustomCommand
Migrate modifies a CustomCommand to remove legacy fields.
func (*CustomCommand) ToDBModel ¶ added in v1.14.0
func (cc *CustomCommand) ToDBModel() *models.CustomCommand
func (*CustomCommand) Validate ¶ added in v1.14.0
func (cc *CustomCommand) Validate(tmpl web.TemplateData) (ok bool)
type CustomCommandSlice ¶
type CustomCommandSlice []*CustomCommand
func (CustomCommandSlice) Len ¶
func (c CustomCommandSlice) Len() int
Len is the number of elements in the collection.
func (CustomCommandSlice) Less ¶
func (c CustomCommandSlice) Less(i, j int) bool
Less reports whether the element with index i should sort before the element with index j.
func (CustomCommandSlice) Swap ¶
func (c CustomCommandSlice) Swap(i, j int)
Swap swaps the elements with indexes i and j.
type DelayedRunCCData ¶ added in v1.16.0
type DelayedRunLimitKey ¶ added in v1.16.0
type LightDBEntry ¶ added in v1.17.0
type LightDBEntry struct { ID int64 GuildID int64 UserID int64 CreatedAt time.Time UpdatedAt time.Time Key string Value interface{} User discordgo.User ExpiresAt time.Time }
func ToLightDBEntry ¶ added in v1.17.0
func ToLightDBEntry(m *models.TemplatesUserDatabase) (*LightDBEntry, error)
type NextRunScheduledEvent ¶ added in v1.14.0
type NextRunScheduledEvent struct {
CmdID int64 `json:"cmd_id"`
}
type ParsedArgs ¶ added in v1.12.0
type ParsedArgs struct {
// contains filtered or unexported fields
}
func (*ParsedArgs) Get ¶ added in v1.12.0
func (pa *ParsedArgs) Get(index int) interface{}
func (*ParsedArgs) IsSet ¶ added in v1.12.0
func (pa *ParsedArgs) IsSet(index int) interface{}
type Plugin ¶
type Plugin struct{}
func (*Plugin) AddCommands ¶ added in v1.4.1
func (p *Plugin) AddCommands()
func (*Plugin) LoadServerHomeWidget ¶ added in v1.17.0
func (p *Plugin) LoadServerHomeWidget(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
func (*Plugin) PluginInfo ¶ added in v1.17.0
func (p *Plugin) PluginInfo() *common.PluginInfo