Documentation
¶
Index ¶
- Constants
- Variables
- func CreateButton(values ...any) (*discordgo.Button, error)
- func CreateCheckbox(values ...any) (*discordgo.Checkbox, error)
- func CreateCheckboxGroup(values ...any) (*discordgo.CheckboxGroup, error)
- func CreateComplexMessage(values ...any) (*discordgo.MessageSend, error)
- func CreateComponent(expectedType discordgo.ComponentType, values ...any) (discordgo.MessageComponent, error)
- func CreateComponentArray(msgFiles *[]*discordgo.File, values ...any) ([]discordgo.TopLevelComponent, error)
- func CreateContainer(msgFiles *[]*discordgo.File, values ...any) (*discordgo.Container, error)
- func CreateEmbed(values ...any) (*discordgo.MessageEmbed, error)
- func CreateFile(msgFiles *[]*discordgo.File, values ...any) (*discordgo.ComponentFile, error)
- func CreateGallery(values any) (*discordgo.MediaGallery, error)
- func CreateLabel(values ...any) (*discordgo.Label, error)
- func CreateModal(values ...any) (*discordgo.InteractionResponse, error)
- func CreateRadioGroup(values ...any) (*discordgo.RadioGroup, error)
- func CreateSection(values ...any) (*discordgo.Section, error)
- func CreateSelectMenu(values ...any) (*discordgo.SelectMenu, error)
- func CreateSeparator(large any) *discordgo.Separator
- func CreateTextDisplay(value any) (*discordgo.TextDisplay, error)
- func CreateTextInput(values ...any) (*discordgo.TextInput, error)
- func ExceedsEncodedSize(v any, limit int) bool
- func InitCooldownTracker()
- func KindOf(input any, flag ...bool) (string, error)
- func LimitWriter(w io.Writer, n int64) io.Writer
- func MaybeScheduledDeleteMessage(guildID, channelID, messageID int64, delaySeconds int, token string)
- func RegisterSetupFunc(f ContextSetupFunc)
- func TargetUserID(input any) int64
- func ToByte(from any) []byte
- func ToDuration(from any) time.Duration
- func ToFloat64(from any) float64
- func ToInt64(from any, base ...int) int64
- func ToRune(from any) []rune
- func ToString(from any) string
- type ComponentBuilder
- func (s *ComponentBuilder) Add(key string, value any) (any, error)
- func (s *ComponentBuilder) AddSlice(key string, slice any) (any, error)
- func (s *ComponentBuilder) DecodeMsgpack(dec *msgpack.Decoder) error
- func (s *ComponentBuilder) EncodeMsgpack(enc *msgpack.Encoder) error
- func (s *ComponentBuilder) Get(key string) (result []any)
- func (s *ComponentBuilder) Merge(toMerge *ComponentBuilder) (any, error)
- func (s *ComponentBuilder) ToComplexMessage() (*discordgo.MessageSend, error)
- func (s *ComponentBuilder) ToComplexMessageEdit() (*discordgo.MessageEdit, error)
- type Context
- func (c *Context) ChannelArg(v any) int64
- func (c *Context) ChannelArgNoDM(v any) int64
- func (c *Context) ChannelArgNoDMNoThread(v any) int64
- func (c *Context) Execute(source string) (string, error)
- func (c *Context) ExecuteAndSendWithErrors(source string, channelID int64) error
- func (c *Context) FindRole(role any, accept roleInputType) *discordgo.Role
- func (c *Context) IncreaseCheckCallCounter(key string, limit int) bool
- func (c *Context) IncreaseCheckCallCounterPremium(key string, normalLimit, premiumLimit int) bool
- func (c *Context) IncreaseCheckGenericAPICall() bool
- func (c *Context) LogEntry() *logrus.Entry
- func (c *Context) MessageSend(content string) *discordgo.MessageSend
- func (c *Context) Parse(source string) (*template.Template, error)
- func (c *Context) SendResponse(content string) (m *discordgo.Message, err error)
- func (c *Context) SetCooldown(key string, duration time.Duration) bool
- type ContextFrame
- type ContextSetupFunc
- type CtxChannel
- type CustomCommandInteraction
- type Dict
- type ExecutedFromType
- type ModalBuilder
- type SDict
- type Slice
- type TemplateCooldowns
Constants ¶
const ( MaxOpsNormal = 1000000 MaxOpsPremium = 2500000 MaxOpsEvalNormal = 200000 MaxOpsEvalPremium = 500000 MaxSliceLength = 10000 MaxAllocNormal = 200 << 20 MaxAllocPremium = 500 << 20 MaxAllocEvalNormal = 40 << 20 MaxAllocEvalPremium = 100 << 20 // Runs allocating more than this are logged so the caps above can be tightened from real usage. LogAllocAbove = 25 << 20 )
const DiscordRoleLimit = 250
const MaxStringLength = 1000000
const TemplateCustomIDPrefix = "templates-"
Variables ¶
var ( ErrTooManyCalls = errors.New("too many calls to this function") ErrFuncOnCooldown = errors.New("function is on cooldown") ErrTooManyAPICalls = errors.New("too many potential Discord API calls") ErrRegexCacheLimit = errors.New("too many unique regular expressions (regex)") )
var ErrStringTooLong = errors.NewPlain("String is too long (max 1MB)")
var ErrTooManyInteractionResponses = errors.New("cannot respond to an interaction > 1 time; consider using a followup")
var ErrValueTooLarge = errors.NewPlain("Value is too large (max 1MB)")
var GuildPremiumFunc func(guildID int64) (bool, error)
set by the premium package to return wether this guild is premium or not
var ( StandardFuncMap = map[string]any{ "str": ToString, "toString": ToString, "toInt": tmplToInt, "toInt64": ToInt64, "toFloat": ToFloat64, "toDuration": ToDuration, "toRune": ToRune, "toByte": ToByte, "hasPrefix": strings.HasPrefix, "hasSuffix": strings.HasSuffix, "joinStr": joinStrings, "lower": strings.ToLower, "slice": slice, "split": strings.Split, "title": titleCaser.String, "trimSpace": strings.TrimSpace, "upper": strings.ToUpper, "urlescape": url.PathEscape, "urlunescape": url.PathUnescape, "print": withOutputLimit(fmt.Sprint, MaxStringLength), "println": withOutputLimit(fmt.Sprintln, MaxStringLength), "printf": withOutputLimitF(fmt.Sprintf, MaxStringLength), "sanitizeText": confusables.SanitizeText, "reQuoteMeta": regexp.QuoteMeta, "abs": tmplAbs, "add": add, "cbrt": tmplCbrt, "div": tmplDiv, "fdiv": tmplFDiv, "log": tmplLog, "mathConst": tmplMathConstant, "max": tmplMax, "min": tmplMin, "mod": tmplMod, "mult": tmplMult, "pow": tmplPow, "round": tmplRound, "roundCeil": tmplRoundCeil, "roundEven": tmplRoundEven, "roundFloor": tmplRoundFloor, "sqrt": tmplSqrt, "sub": tmplSub, "bitwiseAnd": tmplBitwiseAnd, "bitwiseOr": tmplBitwiseOr, "bitwiseXor": tmplBitwiseXor, "bitwiseNot": tmplBitwiseNot, "bitwiseAndNot": tmplBitwiseAndNot, "bitwiseLeftShift": tmplBitwiseLeftShift, "bitwiseRightShift": tmplBitwiseRightShift, "componentBuilder": CreateComponentBuilder, "modalBuilder": CreateModalBuilder, "cbutton": CreateButton, "cmenu": CreateSelectMenu, "cmodal": CreateModal, "clabel": CreateLabel, "ctextInput": CreateTextInput, "ctextDisplay": CreateTextDisplay, "cradioGroup": CreateRadioGroup, "ccheckboxGroup": CreateCheckboxGroup, "ccheckbox": CreateCheckbox, "cembed": CreateEmbed, "complexMessage": CreateComplexMessage, "complexMessageEdit": CreateComplexMessage, "humanizeThousands": tmplHumanizeThousands, "dict": Dictionary, "sdict": StringKeyDictionary, "structToSdict": StructToSdict, "cslice": CreateSlice, "kindOf": KindOf, "adjective": common.RandomAdjective, "in": in, "inFold": inFold, "json": tmplJson, "jsonToSdict": tmplJSONToSDict, "noun": common.RandomNoun, "randInt": randInt, "randNorm": randNorm, "roleAbove": roleIsAbove, "seq": sequence, "shuffle": shuffle, "verb": common.RandomVerb, "currentTime": tmplCurrentTime, "parseTime": tmplParseTime, "formatTime": tmplFormatTime, "loadLocation": time.LoadLocation, "newDate": tmplNewDate, "snowflakeToTime": tmplSnowflakeToTime, "timestampToTime": tmplTimestampToTime, "weekNumber": tmplWeekNumber, "humanizeDurationHours": tmplHumanizeDurationHours, "humanizeDurationMinutes": tmplHumanizeDurationMinutes, "humanizeDurationSeconds": tmplHumanizeDurationSeconds, "humanizeTimeSinceDays": tmplHumanizeTimeSinceDays, } )
Functions ¶
func CreateCheckbox ¶ added in v2.74.0
func CreateCheckboxGroup ¶ added in v2.74.0
func CreateCheckboxGroup(values ...any) (*discordgo.CheckboxGroup, error)
func CreateComplexMessage ¶ added in v2.76.0
func CreateComplexMessage(values ...any) (*discordgo.MessageSend, error)
func CreateComponent ¶ added in v2.39.0
func CreateComponent(expectedType discordgo.ComponentType, values ...any) (discordgo.MessageComponent, error)
func CreateComponentArray ¶ added in v2.55.0
func CreateContainer ¶ added in v2.55.0
func CreateEmbed ¶
func CreateEmbed(values ...any) (*discordgo.MessageEmbed, error)
func CreateFile ¶ added in v2.55.0
func CreateGallery ¶ added in v2.55.0
func CreateGallery(values any) (*discordgo.MediaGallery, error)
func CreateModal ¶ added in v2.39.0
func CreateModal(values ...any) (*discordgo.InteractionResponse, error)
func CreateRadioGroup ¶ added in v2.74.0
func CreateRadioGroup(values ...any) (*discordgo.RadioGroup, error)
func CreateSelectMenu ¶ added in v2.39.0
func CreateSelectMenu(values ...any) (*discordgo.SelectMenu, error)
func CreateSeparator ¶ added in v2.55.0
func CreateTextDisplay ¶ added in v2.55.0
func CreateTextDisplay(value any) (*discordgo.TextDisplay, error)
func CreateTextInput ¶ added in v2.66.0
func ExceedsEncodedSize ¶ added in v2.90.0
ExceedsEncodedSize reports whether json or msgpack encoding v would produce more than limit bytes.
func InitCooldownTracker ¶ added in v2.74.5
func InitCooldownTracker()
func LimitWriter ¶
LimitWriter works like io.LimitReader. It writes at most n bytes to the underlying Writer. It returns io.ErrShortWrite if more than n bytes are attempted to be written, unless those bytes are exclusively whitespace, in which case it will not write them and return without error. It will not write leading whitespace.
func RegisterSetupFunc ¶
func RegisterSetupFunc(f ContextSetupFunc)
func TargetUserID ¶ added in v2.24.0
func ToDuration ¶
Types ¶
type ComponentBuilder ¶ added in v2.55.0
func CreateComponentBuilder ¶ added in v2.55.0
func CreateComponentBuilder(values ...any) (compBuilder *ComponentBuilder, err error)
CreateComponentBuilder parses given input of key-value pairs but returns the keys and the values as separate slices. this is used when you need to have duplicate keys and therefore cannot use a map.
func (*ComponentBuilder) Add ¶ added in v2.55.0
func (s *ComponentBuilder) Add(key string, value any) (any, error)
func (*ComponentBuilder) AddSlice ¶ added in v2.55.0
func (s *ComponentBuilder) AddSlice(key string, slice any) (any, error)
func (*ComponentBuilder) DecodeMsgpack ¶ added in v2.89.0
func (s *ComponentBuilder) DecodeMsgpack(dec *msgpack.Decoder) error
func (*ComponentBuilder) EncodeMsgpack ¶ added in v2.89.0
func (s *ComponentBuilder) EncodeMsgpack(enc *msgpack.Encoder) error
func (*ComponentBuilder) Get ¶ added in v2.55.0
func (s *ComponentBuilder) Get(key string) (result []any)
func (*ComponentBuilder) Merge ¶ added in v2.55.0
func (s *ComponentBuilder) Merge(toMerge *ComponentBuilder) (any, error)
func (*ComponentBuilder) ToComplexMessage ¶ added in v2.59.0
func (s *ComponentBuilder) ToComplexMessage() (*discordgo.MessageSend, error)
func (*ComponentBuilder) ToComplexMessageEdit ¶ added in v2.59.0
func (s *ComponentBuilder) ToComplexMessageEdit() (*discordgo.MessageEdit, error)
type Context ¶
type Context struct {
Name string
GS *dstate.GuildSet
MS *dstate.MemberState
Msg *discordgo.Message
BotUser *discordgo.User
DisabledContextFuncs []string
ContextFuncs map[string]any
Data map[string]any
Counters map[string]int
FixedOutput string
IsPremium bool
RegexCache map[string]*regexp.Regexp
CurrentFrame *ContextFrame
ExecutedFrom ExecutedFromType
// contains filtered or unexported fields
}
func NewContext ¶
func NewContext(gs *dstate.GuildSet, cs *dstate.ChannelState, ms *dstate.MemberState) *Context
func (*Context) ChannelArg ¶
ChannelArg converts a variety of types of argument into a channel, verifying that it exists
func (*Context) ChannelArgNoDM ¶
ChannelArgNoDM is the same as ChannelArg but will not accept DM channels
func (*Context) ChannelArgNoDMNoThread ¶
func (*Context) ExecuteAndSendWithErrors ¶
func (*Context) FindRole ¶ added in v2.39.0
FindRole tries to resolve the argument to a role. `accept` specifies the set of allowed input types, tested in the following order: ID, role mention, role name, role object.
func (*Context) IncreaseCheckCallCounter ¶
IncreaseCheckCallCounter Returns true if key is above the limit
func (*Context) IncreaseCheckCallCounterPremium ¶
IncreaseCheckCallCounter Returns true if key is above the limit
func (*Context) IncreaseCheckGenericAPICall ¶
func (*Context) MessageSend ¶
func (c *Context) MessageSend(content string) *discordgo.MessageSend
func (*Context) SendResponse ¶
SendResponse sends the response and handles reactions and the like
type ContextFrame ¶ added in v2.4.0
type ContextFrame struct {
CS *dstate.ChannelState `json:"cs"`
MentionEveryone bool `json:"mention_everyone"`
MentionHere bool `json:"mention_here"`
MentionRoles []int64 `json:"mention_roles"`
DelResponse bool `json:"del_response"`
PublishResponse bool `json:"publish_response"`
EphemeralResponse bool `json:"ephemeral_response"`
DelResponseDelay int `json:"del_response_delay"`
EmbedsToSend []*discordgo.MessageEmbed `json:"embeds_to_send"`
ComponentsToSend []discordgo.TopLevelComponent `json:"components_to_send"`
AddResponseReactionNames []string `json:"add_response_reaction_names"`
IsNestedTemplate bool `json:"is_nested_template"`
SendResponseInDM bool `json:"send_response_in_dm"`
Interaction *CustomCommandInteraction `json:"interaction"`
// contains filtered or unexported fields
}
type ContextSetupFunc ¶
type ContextSetupFunc func(ctx *Context)
type CtxChannel ¶
type CtxChannel struct {
// These fields never change
ID int64
GuildID int64
IsPrivate bool
IsThread bool
IsForum bool
Name string `json:"name"`
Type discordgo.ChannelType `json:"type"`
Topic string `json:"topic"`
NSFW bool `json:"nsfw"`
Position int `json:"position"`
Bitrate int `json:"bitrate"`
PermissionOverwrites []*discordgo.PermissionOverwrite `json:"permission_overwrites"`
ParentID int64 `json:"parent_id"`
OwnerID int64 `json:"owner_id"`
AvailableTags []discordgo.ForumTag `json:"available_tags"`
AppliedTags []int64 `json:"applied_tags"`
Flags discordgo.ChannelFlags `json:"flags"`
ThreadMetadata *discordgo.ThreadMetadata `json:"thread_metadata,omitempty"`
}
CtxChannel is almost a 1:1 copy of dstate.ChannelState, its needed because we cant axpose all those state methods we also cant use discordgo.Channel because that would likely break a lot of custom commands at this point.
func CtxChannelFromCS ¶
func CtxChannelFromCS(cs *dstate.ChannelState) *CtxChannel
func (*CtxChannel) Mention ¶
func (c *CtxChannel) Mention() (string, error)
type CustomCommandInteraction ¶ added in v2.39.0
type CustomCommandInteraction struct {
*discordgo.Interaction `json:"interaction"`
RespondedTo bool `json:"responded_to"`
Deferred bool `json:"deferred"`
}
func (*CustomCommandInteraction) UnmarshalJSON ¶ added in v2.76.0
func (c *CustomCommandInteraction) UnmarshalJSON(data []byte) error
type Dict ¶
func Dictionary ¶
dictionary creates a map[string]interface{} from the given parameters by walking the parameters and treating them as key-value pairs. The number of parameters must be even.
func (Dict) MarshalJSON ¶
type ExecutedFromType ¶ added in v2.30.0
type ExecutedFromType int
Defines where a template was executed from to enable certain restrictions
const ( ExecutedFromStandard ExecutedFromType = 0 ExecutedFromJoin ExecutedFromType = 1 ExecutedFromLeave ExecutedFromType = 2 ExecutedFromEvalCC ExecutedFromType = 3 ExecutedFromCommandTemplate ExecutedFromType = 4 ExecutedFromNestedCommandTemplate ExecutedFromType = 5 )
type ModalBuilder ¶ added in v2.66.0
type ModalBuilder struct {
Title string
CustomID string
Components []discordgo.TopLevelComponent
}
func CreateModalBuilder ¶ added in v2.66.0
func CreateModalBuilder(customID string, title string, components ...any) (*ModalBuilder, error)
func (*ModalBuilder) AddComponents ¶ added in v2.66.0
func (s *ModalBuilder) AddComponents(comps ...any) (*ModalBuilder, error)
func (*ModalBuilder) Set ¶ added in v2.66.2
func (s *ModalBuilder) Set(key string, value any) (*ModalBuilder, error)
type TemplateCooldowns ¶ added in v2.74.5
func (*TemplateCooldowns) Set ¶ added in v2.74.5
func (tc *TemplateCooldowns) Set(key string, duration time.Duration) bool
func (*TemplateCooldowns) Tick ¶ added in v2.74.5
func (tc *TemplateCooldowns) Tick()