templates

package
v1.24.4 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2020 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxOpsNormal  = 1000000
	MaxOpsPremium = 2500000
)
View Source
const MaxStringLength = 1000000

Variables

View Source
var ErrStringTooLong = errors.NewPlain("String is too long (max 1MB)")
View Source
var ErrTooManyAPICalls = errors.New("Too many potential discord api calls function")
View Source
var ErrTooManyCalls = errors.New("Too many calls to this function")
View Source
var GuildPremiumFunc func(guildID int64) (bool, error)

set by the premium package to return wether this guild is premium or not

View Source
var (
	StandardFuncMap = map[string]interface{}{

		"str":        ToString,
		"toString":   ToString,
		"toInt":      tmplToInt,
		"toInt64":    ToInt64,
		"toFloat":    ToFloat64,
		"toDuration": ToDuration,
		"toRune":     ToRune,
		"toByte":     ToByte,

		"joinStr":   joinStrings,
		"lower":     strings.ToLower,
		"upper":     strings.ToUpper,
		"slice":     slice,
		"urlescape": url.PathEscape,
		"split":     strings.Split,
		"title":     strings.Title,

		"add":               add,
		"sub":               tmplSub,
		"mult":              tmplMult,
		"div":               tmplDiv,
		"mod":               tmplMod,
		"fdiv":              tmplFDiv,
		"sqrt":              tmplSqrt,
		"pow":               tmplPow,
		"log":               tmplLog,
		"round":             tmplRound,
		"roundCeil":         tmplRoundCeil,
		"roundFloor":        tmplRoundFloor,
		"roundEven":         tmplRoundEven,
		"humanizeThousands": tmplHumanizeThousands,

		"dict":               Dictionary,
		"sdict":              StringKeyDictionary,
		"cembed":             CreateEmbed,
		"cslice":             CreateSlice,
		"complexMessage":     CreateMessageSend,
		"complexMessageEdit": CreateMessageEdit,

		"formatTime":  tmplFormatTime,
		"json":        tmplJson,
		"in":          in,
		"inFold":      inFold,
		"roleAbove":   roleIsAbove,
		"adjective":   common.RandomAdjective,
		"noun":        common.RandomNoun,
		"randInt":     randInt,
		"shuffle":     shuffle,
		"seq":         sequence,
		"currentTime": tmplCurrentTime,
		"newDate":     tmplNewDate,

		"escapeHere": func(s string) (string, error) {
			return "", errors.New("function is removed in favor of better direct control over mentions, join support server and read the announcements for more info.")
		},
		"escapeEveryone": func(s string) (string, error) {
			return "", errors.New("function is removed in favor of better direct control over mentions, join support server and read the announcements for more info.")
		},
		"escapeEveryoneHere": func(s string) (string, error) {
			return "", errors.New("function is removed in favor of better direct control over mentions, join support server and read the announcements for more info.")
		},

		"humanizeDurationHours":   tmplHumanizeDurationHours,
		"humanizeDurationMinutes": tmplHumanizeDurationMinutes,
		"humanizeDurationSeconds": tmplHumanizeDurationSeconds,
		"humanizeTimeSinceDays":   tmplHumanizeTimeSinceDays,
	}
)

Functions

func CreateEmbed added in v1.4.1

func CreateEmbed(values ...interface{}) (*discordgo.MessageEmbed, error)

func CreateMessageEdit added in v1.23.0

func CreateMessageEdit(values ...interface{}) (*discordgo.MessageEdit, error)

func CreateMessageSend added in v1.22.2

func CreateMessageSend(values ...interface{}) (*discordgo.MessageSend, error)

func Dictionary

func Dictionary(values ...interface{}) (map[interface{}]interface{}, error)

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 LimitWriter added in v1.10.1

func LimitWriter(w io.Writer, n int64) io.Writer

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.

func MaybeScheduledDeleteMessage added in v1.13.0

func MaybeScheduledDeleteMessage(guildID, channelID, messageID int64, delaySeconds int)

func RegisterSetupFunc

func RegisterSetupFunc(f ContextSetupFunc)

func TODO

func TODO()

func ToByte added in v1.24.0

func ToByte(from interface{}) []byte

func ToDuration added in v1.17.0

func ToDuration(from interface{}) time.Duration

func ToFloat64 added in v1.15.1

func ToFloat64(from interface{}) float64

func ToInt64

func ToInt64(from interface{}) int64

func ToRune added in v1.24.0

func ToRune(from interface{}) []rune

func ToString

func ToString(from interface{}) string

Types

type Context

type Context struct {
	Name string

	GS      *dstate.GuildState
	MS      *dstate.MemberState
	Msg     *discordgo.Message
	BotUser *discordgo.User

	ContextFuncs map[string]interface{}
	Data         map[string]interface{}
	Counters     map[string]int

	FixedOutput string

	IsPremium bool

	RegexCache map[string]*regexp.Regexp

	CurrentFrame *contextFrame
	// contains filtered or unexported fields
}

func NewContext

func NewContext(gs *dstate.GuildState, cs *dstate.ChannelState, ms *dstate.MemberState) *Context

func (*Context) ChannelArg added in v1.16.0

func (c *Context) ChannelArg(v interface{}) int64

func (*Context) Execute

func (c *Context) Execute(source string) (string, error)

func (*Context) ExecuteAndSendWithErrors added in v1.17.3

func (c *Context) ExecuteAndSendWithErrors(source string, channelID int64) error

func (*Context) IncreaseCheckCallCounter added in v0.29.1

func (c *Context) IncreaseCheckCallCounter(key string, limit int) bool

IncreaseCheckCallCounter Returns true if key is above the limit

func (*Context) IncreaseCheckCallCounterPremium added in v1.17.2

func (c *Context) IncreaseCheckCallCounterPremium(key string, normalLimit, premiumLimit int) bool

IncreaseCheckCallCounter Returns true if key is above the limit

func (*Context) IncreaseCheckGenericAPICall added in v1.16.0

func (c *Context) IncreaseCheckGenericAPICall() bool

func (*Context) IncreaseCheckStateLock added in v1.16.0

func (c *Context) IncreaseCheckStateLock() bool

func (*Context) LogEntry added in v1.17.0

func (c *Context) LogEntry() *logrus.Entry

func (*Context) MessageSend added in v1.24.0

func (c *Context) MessageSend(content string) *discordgo.MessageSend

func (*Context) Parse added in v1.14.0

func (c *Context) Parse(source string) (*template.Template, error)

func (*Context) SendResponse added in v1.24.0

func (c *Context) SendResponse(content string) (*discordgo.Message, error)

SendResponse sends the response and handles reactions and the like

type ContextSetupFunc

type ContextSetupFunc func(ctx *Context)

type SDict added in v1.15.1

type SDict map[string]interface{}

func StringKeyDictionary added in v1.4.1

func StringKeyDictionary(values ...interface{}) (SDict, error)

func (SDict) Del added in v1.20.14

func (d SDict) Del(key string) string

func (SDict) Get added in v1.15.1

func (d SDict) Get(key string) interface{}

func (SDict) Set added in v1.15.1

func (d SDict) Set(key string, value interface{}) string

type Slice added in v1.20.17

type Slice []interface{}

func CreateSlice added in v1.4.1

func CreateSlice(values ...interface{}) (Slice, error)

func (Slice) Append added in v1.20.17

func (s Slice) Append(item interface{}) (interface{}, error)

func (Slice) AppendSlice added in v1.20.17

func (s Slice) AppendSlice(slice interface{}) (interface{}, error)

func (Slice) Set added in v1.20.17

func (s Slice) Set(index int, item interface{}) (string, error)

func (Slice) StringSlice added in v1.22.2

func (s Slice) StringSlice(flag ...bool) interface{}

Jump to

Keyboard shortcuts

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