Documentation
¶
Index ¶
- Constants
- Variables
- func AcknowledgeResponse(s *discordgo.Session, i *discordgo.InteractionCreate, ...)
- func AlignString(str string, width int, alignment StringAlign) string
- func CalculateFutureTokenLogs(maxEntries int, startTime time.Time, minutesPerToken int, ...) ([]FutureToken, []FutureToken)
- func CalculateTcountTtime(tokenValue float64, tval float64, valueLog []FutureToken) (string, string, int)
- func CellANSI(s, color string, width int, right bool) string
- func DownloadAttachmentBytes(att *discordgo.MessageAttachment) ([]byte, error)
- func DownloadLatestEggImages(localDownloadDir string) error
- func FindCategoryID(s *discordgo.Session, channelID string) (string, error)
- func FitString(str string, width int, alignment StringAlign) string
- func FmtDuration(d time.Duration) string
- func FmtDurationSingleUnit(d time.Duration) (string, int)
- func FormatIntWithCommas[T ~int | ~int64 | ~uint | ~uint32 | ~uint64](v T) string
- func GenerateBanner(ID string, eggName string, text string, creatorID string, guildID string, ...)
- func GetCommandAttachment(i *discordgo.InteractionCreate, ...) *discordgo.MessageAttachment
- func GetCommandOptionsMap(i *discordgo.InteractionCreate) map[string]*discordgo.ApplicationCommandInteractionDataOption
- func GetFormattedCommand(command string) string
- func GetGistData(filename string) (string, error)
- func GetInteractionUserID(i *discordgo.InteractionCreate) string
- func GetRandomName(_ int) string
- func GetSlashRemoveMessage(cmd string) *discordgo.ApplicationCommand
- func GetStaabmiaLink(darkMode bool, modifierType ei.GameModifier_GameDimension, ...) string
- func GetTokenValue(seconds float64, durationSeconds float64) float64
- func HandleRemoveMessageCommand(s *discordgo.Session, i *discordgo.InteractionCreate)
- func ImportEggImage(s *discordgo.Session, eggID, IconURL string) (string, error)
- func ImportNewEmojis(s *discordgo.Session)
- func IsRandomName(name string) bool
- func IsValidDiscordID(id string) bool
- func LoadEmotes(s *discordgo.Session, force bool)
- func NewSmallSeparatorComponent(visible bool) *discordgo.Separator
- func NumberToEmoji(n int) string
- func PutGistData(filename string, data string) error
- func RefreshMap[K comparable, V any](m map[K]V) map[K]V
- func SanitizeStringDuration(s string) string
- func UpdateCommandMap(commands []*discordgo.ApplicationCommand)
- func VisibleLenANSI(s string) int
- func WrapANSI(s, color string) string
- func WrapTimestamp[N TimestampNumber](ts N, format DiscordTimestampFormat) string
- type DiscordTimestampFormat
- type FutureToken
- type StringAlign
- type TimestampNumber
Constants ¶
const ( // MaxAnimateFileBytes defines the maximum allowed file size for attachments to be processed by the bot. MaxAnimateFileBytes = 10 * 1024 * 1024 // MintPreviewMaxAge defines how long a mint preview is considered valid before it should be refreshed. MintPreviewMaxAge = 20 * time.Minute )
Variables ¶
var SyncCustomBannerCallback func(userID string, guildID string, destPath string) bool
SyncCustomBannerCallback is a function hook to sync custom banners from the database to disk.
var UpdateDashboardDisplays func(s *discordgo.Session, userID string)
UpdateDashboardDisplays is a callback used to notify the dashboard of data changes
Functions ¶
func AcknowledgeResponse ¶
func AcknowledgeResponse(s *discordgo.Session, i *discordgo.InteractionCreate, flags discordgo.MessageFlags)
AcknowledgeResponse sends a deferred response to acknowledge the interaction with the given flags.
func AlignString ¶
func AlignString(str string, width int, alignment StringAlign) string
AlignString aligns a string to the left, center, or right within a given width
func CalculateFutureTokenLogs ¶
func CalculateFutureTokenLogs(maxEntries int, startTime time.Time, minutesPerToken int, duration time.Duration, rateSecondPerTokens float64) ([]FutureToken, []FutureToken)
CalculateFutureTokenLogs calculates the future token logs based on the given parameters
func CalculateTcountTtime ¶
func CalculateTcountTtime(tokenValue float64, tval float64, valueLog []FutureToken) (string, string, int)
CalculateTcountTtime calculates the token count and time based on the given parameters
func CellANSI ¶
CellANSI pads s to width with spaces and applies color to the content only. If right: the content is right-aligned.
func DownloadAttachmentBytes ¶
func DownloadAttachmentBytes(att *discordgo.MessageAttachment) ([]byte, error)
DownloadAttachmentBytes downloads the attachment content and returns it as a byte slice.
func DownloadLatestEggImages ¶
DownloadLatestEggImages downloads the latest image files from a specific GitHub repository directory. Once downloaded, files are considered permanent — a sentinel file gates re-scanning for 7 days to avoid hitting the GitHub API rate limit on dev restarts.
func FindCategoryID ¶
FindCategoryID walks up the parent chain until it finds the category. Returns the category ID, or "" if err.
func FitString ¶
func FitString(str string, width int, alignment StringAlign) string
FitString truncates and pads left or right
func FmtDuration ¶
FmtDuration formats a time.Duration into a human-readable string with seconds precision.
func FmtDurationSingleUnit ¶
FmtDurationSingleUnit formats a time.Duration into a single unit string and its corresponding unit integer
func FormatIntWithCommas ¶
FormatIntWithCommas formats any integer value with commas as thousands separators
func GenerateBanner ¶
func GenerateBanner(ID string, eggName string, text string, creatorID string, guildID string, styleOverride string)
GenerateBanner creates a banner image with a background, overlay image, and text
func GetCommandAttachment ¶
func GetCommandAttachment(i *discordgo.InteractionCreate, opt *discordgo.ApplicationCommandInteractionDataOption) *discordgo.MessageAttachment
GetCommandAttachment retrieves the attachment from the interaction options if it exists and is of the correct type.
func GetCommandOptionsMap ¶
func GetCommandOptionsMap(i *discordgo.InteractionCreate) map[string]*discordgo.ApplicationCommandInteractionDataOption
GetCommandOptionsMap returns a map of command options subcommand options are stored as "subcommand-option" nested subcommands are stored as "group-subcommand-option"
func GetFormattedCommand ¶
GetFormattedCommand returns the formatted command string
func GetGistData ¶
GetGistData retrieves data from a Gist and unmarshals it into the target interface.
func GetInteractionUserID ¶
func GetInteractionUserID(i *discordgo.InteractionCreate) string
GetInteractionUserID returns the user ID from an interaction, whether in a guild or DM
func GetRandomName ¶
GetRandomName returns a docker-style random name.
func GetSlashRemoveMessage ¶
func GetSlashRemoveMessage(cmd string) *discordgo.ApplicationCommand
GetSlashRemoveMessage returns the slash command for removing a bot message from a DM channel.
func GetStaabmiaLink ¶
func GetStaabmiaLink(darkMode bool, modifierType ei.GameModifier_GameDimension, modifierMult float64, coopDeflectorBonus int, artifacts []string, shippingRate, elrRate, habCap float64) string
GetStaabmiaLink returns a link to the Staabia calculator.
func GetTokenValue ¶
GetTokenValue calculates the token value based on the given parameters
func HandleRemoveMessageCommand ¶
func HandleRemoveMessageCommand(s *discordgo.Session, i *discordgo.InteractionCreate)
HandleRemoveMessageCommand handles the remove message command.
func ImportEggImage ¶
ImportEggImage will import an egg image into the discord app
func ImportNewEmojis ¶
ImportNewEmojis will import new emojis from the emoji directory into the discord app
func IsRandomName ¶
IsRandomName returns true if name matches the generated docker-style random name format.
func IsValidDiscordID ¶
IsValidDiscordID checks if a string is a valid Discord snowflake ID by validating the embedded timestamp is within Discord's operational range
func LoadEmotes ¶
LoadEmotes will load all the emojis from the app
func NewSmallSeparatorComponent ¶
NewSmallSeparatorComponent returns a Discord separator component configured with small spacing and optional visibility.
func NumberToEmoji ¶
NumberToEmoji converts any non-negative integer to a string of emoji digits
func PutGistData ¶
PutGistData uploads data to a Gist.
func RefreshMap ¶
func RefreshMap[K comparable, V any](m map[K]V) map[K]V
RefreshMap creates and returns a shallow copy of the given map
func SanitizeStringDuration ¶
SanitizeStringDuration takes an hms string and returns a sanitized version of it
func UpdateCommandMap ¶
func UpdateCommandMap(commands []*discordgo.ApplicationCommand)
UpdateCommandMap updates the command map
func VisibleLenANSI ¶
VisibleLenANSI returns the rune length of s excluding ANSI escape codes.
func WrapANSI ¶
WrapANSI wraps s with an ANSI color by name ("red", "green", "blue"). Unknown color returns s unchanged.
func WrapTimestamp ¶
func WrapTimestamp[N TimestampNumber](ts N, format DiscordTimestampFormat) string
WrapTimestamp returns ts formatted as a Discord timestamp string.
ts can be any integer type assumed to be a Unix timestamp in seconds. format is one of the DiscordTimestampFormat constants. If format is TimestampDefault, it returns "<t:ts>". Otherwise it returns "<t:ts:format>".
Types ¶
type DiscordTimestampFormat ¶
type DiscordTimestampFormat string
DiscordTimestampFormat holds the style postfixes for Discord timestamp formatting.
const ( // TimestampDefault <t:1543392060> November 28, 2018 9:01 AM || 28 November 2018 09:01 TimestampDefault DiscordTimestampFormat = "" // TimestampShortTime <t:1543392060:t> 9:01 AM || 09:01 TimestampShortTime DiscordTimestampFormat = "t" // TimestampLongTime <t:1543392060:T> 9:01:00 AM || 09:01:00 TimestampLongTime DiscordTimestampFormat = "T" // TimestampShortDate <t:1543392060:d> 11/28/2018 || 28/11/2018 TimestampShortDate DiscordTimestampFormat = "d" // TimestampLongDate <t:1543392060:D> November 28, 2018 || 28 November 2018 TimestampLongDate DiscordTimestampFormat = "D" // TimestampShortDateTime <t:1543392060:f> November 28, 2018 9:01 AM || 28 November 2018 09:01 TimestampShortDateTime DiscordTimestampFormat = "f" // TimestampLongDateTime <t:1543392060:F> Wednesday, November 28, 2018 9:01 AM || Wednesday, 28 November 2018 09:01 TimestampLongDateTime DiscordTimestampFormat = "F" // TimestampRelativeTime <t:1543392060:R> 3 years ago || 3 years ago TimestampRelativeTime DiscordTimestampFormat = "R" )
type FutureToken ¶
FutureToken represents a token with its value and time
type StringAlign ¶
type StringAlign int
StringAlign is an enum for string alignment
const ( // StringAlignLeft aligns the string to the left StringAlignLeft StringAlign = iota // StringAlignCenter aligns the string to the center (left biased) StringAlignCenter // StringAlignRight aligns the string to the right StringAlignRight // StringAlignCenterRight aligns the string to the center (right biased) StringAlignCenterRight )