Documentation ¶
Index ¶
- Constants
- Variables
- func AbsInt(i int) int
- func BytesToUint(a []byte) (x uint)
- func CapString(in string) string
- func CapStringLen(in string, l int) string
- func Clean(unsafe string) string
- func ClearBold(uncleared string) string
- func ClearNonspacing(str string) string
- func CommaAnd(items []string) string
- func CommaAndf(items []string, formatter func(int, string) string) string
- func DiffUint32(x, y uint32) uint32
- func DiscordTag(user *discordgo.User) string
- func FindPrefix(s string, prefixes []string) (prefix string, ok bool)
- func FindSuffix(s string, suffixes []string) (prefix string, ok bool)
- func FormatBytes(size uint64) string
- func FormatDecimal(in int) string
- func FormatDuration(duration time.Duration) string
- func FormatHex(in int64) string
- func GetEmbedImage(message *discordgo.Message) (*discordgo.MessageEmbedImage, string)
- func GetImage(message *discordgo.Message) (*discordgo.MessageAttachment, string)
- func HasSuffixes(s string, suffixes []string) bool
- func IDtoTimestamp(id string) (time.Time, error)
- func IsValidImageURL(url string) (extension string, isValid bool)
- func JoinTo(b *strings.Builder, a []string, sep string)
- func MapIntString(vs []int, f func(int) string) []string
- func MapSlice(vs []string, f func(int, string) string) []string
- func Morning(t int64) int64
- func Normalise(str string) string
- func Ordinal(in int) string
- func ParseDuration(in string) (time.Duration, error)
- func PermStringer(perm int) string
- func Printerr(a ...interface{})
- func Quoter(_ int, s string) string
- func ResolveChannelMention(raw string) string
- func ResolveMention(raw string) string
- func ResolveMentionZWS(raw string) string
- func ResolveRoleMention(raw string) string
- func Similarity(a, b string) float64
- func Sqer(_ int, s string) string
- func UintToBytes(x uint) (out []byte)
- func Wait(seconds time.Duration) <-chan time.Time
- type UserError
Constants ¶
const EPOCH = 1420070400000
EPOCH is Discord's epoch (2015-01-01T00:00:00.000Z)
const Escaped2Asterisks = "*" + string(8203) + "*"
Escaped2Asterisks is "**" with ZWS characters inbetween
const Escaped3Asterisks = "*" + string(8203) + "*" + string(8203) + "*"
Escaped3Asterisks is "***" with ZWS characters inbetween
const Escaped3Backticks = "`" + string(8203) + "`" + string(8203) + "`"
Escaped3Backticks is "````" with ZWS characters inbetween
const EscapedAtEveryone = EscapedAtSign + "everyone"
EscapedAtEveryone is EscapedAtSign followed by "everyone"
const EscapedAtHere = EscapedAtSign + "here"
EscapedAtHere is EscapedAtSign followed by "here"
const EscapedAtSign = "@" + string(8203)
EscapedAtSign is the @ character followed by a ZWS character
const TwoWeeks = time.Duration(14 * day)
TwoWeeks is two weeks in type time.Duration. This is the maximum age for a purge-able message.
Variables ¶
var ChannelMentionRegex = regexp.MustCompile(`^<#(\d{17,19})>$`)
ChannelMentionRegex matches channel mentions
var DiscordIIRegex = regexp.MustCompile("discord[^a-z0-9]*gg")
DiscordIIRegex matches "discord[any symbol but a-z0-9]gg"
var EmojiFinderRegex = regexp.MustCompile(`<(a)?:([a-zA-Z0-9_-]{2,32}):(\d{17,19})>`)
EmojiFinderRegex matches Discord emojis but without str start/end
var EmojiRegex = regexp.MustCompile(`^<(a)?:([a-zA-Z0-9_-]{2,32}):(\d{17,19})>$`)
EmojiRegex matches Discord emojis
var ErrInvalidTime = errors.New("invalid time or out of range")
ErrInvalidTime throws when a bad time string is put into parseTime
var IDRegex = regexp.MustCompile(`^(\d{17,19})$`)
IDRegex matches Discord IDs (17-19 digit numbers)
var MentionRegex = regexp.MustCompile(`^<@!?(\d{17,19})>$`)
MentionRegex matches mentions
var MentionRegexZWS = regexp.MustCompile(`^<@` + string(8203) + `?!?(\d{17,19})>$`)
MentionRegexZWS matches mentions with ZWS
var Perms = [...]int{ discordgo.PermissionAdministrator, discordgo.PermissionViewAuditLogs, discordgo.PermissionManageServer, discordgo.PermissionManageRoles, discordgo.PermissionManageChannels, discordgo.PermissionKickMembers, discordgo.PermissionBanMembers, discordgo.PermissionCreateInstantInvite, discordgo.PermissionChangeNickname, discordgo.PermissionManageNicknames, discordgo.PermissionManageEmojis, discordgo.PermissionManageWebhooks, discordgo.PermissionReadMessages, discordgo.PermissionSendMessages, discordgo.PermissionSendTTSMessages, discordgo.PermissionManageMessages, discordgo.PermissionEmbedLinks, discordgo.PermissionAttachFiles, discordgo.PermissionReadMessageHistory, discordgo.PermissionMentionEveryone, discordgo.PermissionUseExternalEmojis, discordgo.PermissionAddReactions, discordgo.PermissionVoiceConnect, discordgo.PermissionVoiceSpeak, discordgo.PermissionVoiceMuteMembers, discordgo.PermissionVoiceDeafenMembers, discordgo.PermissionVoiceMoveMembers, discordgo.PermissionVoiceUseVAD, }
Perms is an array of permission integers, sorted in an almost identical way to the Discord desktop client
var PermsNames = [...]string{
"Administrator",
"View Audit Logs",
"Manage Server",
"Manage Roles",
"Manage Channels",
"Kick Members",
"Ban Members",
"Create Invite",
"Change Nickname",
"Manage Nicknames",
"Manage Emojis",
"Manage Webhooks",
"Read Messages",
"Send Messages",
"Send TTS Messages",
"Manage Messages",
"Embed Links",
"Attach Files",
"Read Message History",
"Mention Everyone",
"Use External Emojis",
"Add Reactions",
"Connect to VC",
"Speak in VC",
"Mute Members in VC",
"Deafen Members in VC",
"Move Members in VC",
"Use Voice Activity",
}
PermsNames is an array of permission names, sorted identically to Perms
var RegionIndicators = [...]string{
"🇦",
"🇧",
"🇨",
"🇩",
"🇪",
"🇫",
"🇬",
"🇭",
"🇮",
"🇯",
"🇰",
"🇱",
"🇲",
"🇳",
"🇴",
"🇵",
"🇶",
"🇷",
"🇸",
"🇹",
"🇺",
"🇻",
"🇼",
"🇽",
"🇾",
"🇿",
}
RegionIndicators are all known region indicators in alphabetical order
var RoleMentionFinderRegex = regexp.MustCompile(`<@&(\d{17,19})>`)
RoleMentionFinderRegex matches role mentions but without str start/end
var RoleMentionRegex = regexp.MustCompile(`^<@&(\d{17,19})>$`)
RoleMentionRegex matches role mentions
var Spaces = regexp.MustCompile(`[^\S\n]+`)
Spaces matches whitespace characters and newlines
Functions ¶
func CapStringLen ¶ added in v0.1.1
CapStringLen returns in[0:l] + "..." if len(in) > l, else in
func ClearNonspacing ¶ added in v0.1.1
ClearNonspacing removes all non-spacing marks from a string
func DiscordTag ¶
DiscordTag returns the specified user's Discord tag
func FindPrefix ¶
FindPrefix finds the used prefix in a string
func FindSuffix ¶ added in v0.2.3
FindSuffix finds the used suffix in a string
func FormatDecimal ¶
FormatDecimal formats int values to human-readable strings like `12,345,678`
func FormatDuration ¶
FormatDuration humanises type time.Duration
func GetEmbedImage ¶
func GetEmbedImage(message *discordgo.Message) (*discordgo.MessageEmbedImage, string)
GetEmbedImage gets an image from the embed of a message and returns nil if none is found
func GetImage ¶
func GetImage(message *discordgo.Message) (*discordgo.MessageAttachment, string)
GetImage gets an image attachment from a message and returns nil if none is found
func HasSuffixes ¶
HasSuffixes returns whether s has one of suffixes as suffix
func IDtoTimestamp ¶
IDtoTimestamp converts Discord snowflakes to type time.Time
func IsValidImageURL ¶ added in v0.3.0
IsValidImageURL checks if the given url is one that leads to an URL
func MapIntString ¶
MapIntString returns a new slice containing the results of calling f on each int in the original slice
func MapSlice ¶
MapSlice returns a new slice containing the results of calling f on each string in the original slice
func Normalise ¶ added in v0.6.0
Normalise removes all non-spacing marks from a string and replaces all regional indicators with letters
func ParseDuration ¶
ParseDuration turns strings like `2 hours 3 minutes` to type time.Duration
func PermStringer ¶
PermStringer is a macro for utils.Perms[perm]
func ResolveChannelMention ¶
ResolveChannelMention resolves strings like `<#id>` or `id` to `id` and returns a blank string if not resolvable
func ResolveMention ¶
ResolveMention resolves strings like `<@id>` or `id` to `id` and returns a blank string if not resolvable
func ResolveMentionZWS ¶
ResolveMentionZWS resolves strings like `<@id>` or `id` to `id` with zero width spaces taken into account and returns a blank string if not resolvable
func ResolveRoleMention ¶
ResolveRoleMention resolves strings like `<@&id>` or `id` to `id` and returns a blank string if not resolvable
func Similarity ¶
Similarity finds the similarity between a and b Original version at https://github.com/hbakhtiyor/strsim/blob/master/strsim.go
func UintToBytes ¶
UintToBytes converts an uint to a byte slice