Documentation
¶
Index ¶
- Variables
- func All(vs ...bool) bool
- func Any(vs ...bool) bool
- func CalcHalfLife(timeSince time.Duration, halfLifeTimeDays, weight float64) float64
- func FormatFloatUpToPrec(num float64, prec int) string
- func GetMembersIter(r rest.Rest, guildID snowflake.ID) iter.Seq[IterResult[discord.Member]]
- func HasRole(member discord.Member, roleID snowflake.ID) bool
- func HasRolesAll(member discord.Member, roleIDs ...snowflake.ID) bool
- func HasRolesAny(member discord.Member, roleIDs ...snowflake.ID) bool
- func Iif[T any](cond bool, t, f T) T
- func LogInteraction(namespace string, interaction discord.Interaction)
- func LogInteractionContext(namespace string, interaction discord.Interaction, ctx context.Context)
- func MentionChannelOrDefault(id *snowflake.ID, def string) string
- func MentionRoleOrDefault(id *snowflake.ID, def string) string
- func ParseLongDuration(s string) (time.Duration, error)
- func Ref[T any](v T) *T
- func RefDefault[T any](v *T, def T) T
- func SplitStringToLengthByLine(input string, length int) (output []string)
- func WrapRef[T any](v *T) (T, bool)
- type DiscordTime
- type IterResult
- type MessageTemplateData
- type TemplateGuildData
- type TemplateUserData
Constants ¶
This section is empty.
Variables ¶
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)?$`)
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 CalcHalfLife ¶
func FormatFloatUpToPrec ¶
func GetMembersIter ¶
func LogInteraction ¶
func LogInteraction(namespace string, interaction discord.Interaction)
func LogInteractionContext ¶
func LogInteractionContext(namespace string, interaction discord.Interaction, ctx context.Context)
func MentionChannelOrDefault ¶
MentionChannelOrDefault formats a mention for a channel by its ID. If the ID pointer is nil or zero, use a provided fallback value instead.
func MentionRoleOrDefault ¶
MentionRoleOrDefault formats a mention for a role by its ID. If the ID pointer is nil or zero, use a provided fallback value instead.
func ParseLongDuration ¶
ParseLongDuration parses a string into a time.Duration. It supports the following format:
- 1y2mo3w4d5h6m3s (year, month, week, day, hour, minute, second)
Note: an empty duration string will be a duration of 0.
func RefDefault ¶
func RefDefault[T any](v *T, def T) T
func SplitStringToLengthByLine ¶
SplitStringToLengthByLine splits a string into multiple parts, so that each part is at or below the length limit. However, the split should only occur on newlines, so that most inline and single-line formatting and such are not affected by it.
Usage notes: Use a length of 2000 for a standard Discord message. If you plan to add any formatting before it, reduce this number.
Types ¶
type DiscordTime ¶
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 MessageTemplateData ¶
type MessageTemplateData struct {
User TemplateUserData
Server TemplateGuildData
}
func NewMessageTemplateData ¶
func NewMessageTemplateData(user discord.Member, guild discord.Guild) MessageTemplateData