utils

package
v0.0.0-...-1e0fa90 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LongDurationRegex = regexp.MustCompile(`^(?:(?P<years>\d+)y)? *(?:(?P<months>\d+)mo)? *(?:(?P<weeks>\d+)w)? *(?:(?P<days>\d+)d)? *(?:(?P<hours>\d+)h)? *(?:(?P<minutes>\d+)m)? *(?:(?P<seconds>\d+)s)?$`)
View Source
var MessageTemplateInfo = "The following placeholders can be used in join/leave/approval messages " +
	"and will be replaced with the appropriate values." +
	"\n" +
	"\n" +
	"**Username:** `{{User.Username}}` will show as \"Username#1234\" or  \"username\"\n" +
	"**Global name:** `{{User.GlobalName}}` will show the user's global display name\n" +
	"**Server name:** `{{User.ServerName}}` will show the user's server nickname, if any\n" +
	"**Resolved name:** `{{User.ResolvedName}}` will show the user's resolved name, which is" +
	"the server nickname if set, otherwise the global name, or username if neither is set\n" +
	"**Mention:** `{{User.Mention}}` will mention the user if it is used\n" +
	"**User ID:** `{{User.ID}}` will show the user's ID\n" +
	"**Server name:** `{{Server.Name}}` will show the server name\n" +
	"**Server ID:** `{{Server.ID}}` will show the server ID\n"

Functions

func All

func All(vs ...bool) bool

func Any

func Any(vs ...bool) bool

func CalcHalfLife

func CalcHalfLife(timeSince time.Duration, halfLifeTimeDays, weight float64) float64

func FormatFloatUpToPrec

func FormatFloatUpToPrec(num float64, prec int) string

func GetMembersIter

func GetMembersIter(r rest.Rest, guildID snowflake.ID) iter.Seq[IterResult[discord.Member]]

func HasRole

func HasRole(member discord.Member, roleID snowflake.ID) bool

func HasRolesAll

func HasRolesAll(member discord.Member, roleIDs ...snowflake.ID) bool

func HasRolesAny

func HasRolesAny(member discord.Member, roleIDs ...snowflake.ID) bool

func Iif

func Iif[T any](cond bool, t, f T) T

func LogInteraction

func LogInteraction(interactionName string, interaction discord.Interaction)

func LogInteractionContext

func LogInteractionContext(interactionName string, interaction discord.Interaction, ctx context.Context)

func Max

func Max[T cmp.Ordered](a, b T) T

func Min

func Min[T cmp.Ordered](a, b T) T

func ParseLongDuration

func ParseLongDuration(s string) (time.Duration, error)

ParseLongDuration parses a string into a time.Duration. It supports the following format:

  • 1y2mo3w4d5h6m3s (year, month, week, day, hour, minute, second)

func Ref

func Ref[T any](v T) *T

func RefDefault

func RefDefault[T any](v *T, def T) T

func WrapRef

func WrapRef[T any](v *T) (T, bool)

Types

type DiscordTime

type DiscordTime struct {
	time.Time
}

func (DiscordTime) ToLongDate

func (t DiscordTime) ToLongDate() string

func (DiscordTime) ToLongDateTime

func (t DiscordTime) ToLongDateTime() string

func (DiscordTime) ToLongTime

func (t DiscordTime) ToLongTime() string

func (DiscordTime) ToRelative

func (t DiscordTime) ToRelative() string

func (DiscordTime) ToShortDate

func (t DiscordTime) ToShortDate() string

func (DiscordTime) ToShortDateTime

func (t DiscordTime) ToShortDateTime() string

func (DiscordTime) ToShortTime

func (t DiscordTime) ToShortTime() string

type IterResult

type IterResult[T any] struct {
	Value T
	Error error
}

type MessageTemplateData

type MessageTemplateData struct {
	User   TemplateUserData
	Server TemplateGuildData
}

func NewMessageTemplateData

func NewMessageTemplateData(user discord.Member, guild discord.Guild) MessageTemplateData

type TemplateGuildData

type TemplateGuildData struct {
	Name string
	ID   snowflake.ID
}

type TemplateUserData

type TemplateUserData struct {
	Username      string
	GlobalName    string
	ServerName    string
	ResolvedName  string
	Mention       string
	Discriminator uint8
	IsBot         bool
	ID            snowflake.ID
}

Jump to

Keyboard shortcuts

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