bottools

package
v0.0.0-...-32c2adb Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Unlicense Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BannerWidth is set to 640 to fit within Discord's maximum banner width of 960 pixels while maintaining a good aspect ratio for most images.
	BannerWidth = 640
	// BannerHeight is set to 85 to maintain a 16:9 aspect ratio while fitting within Discord's maximum banner height of 256 pixels.
	BannerHeight = 85
)
View Source
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

View Source
var RefreshGuildContractsForBannerCallback func(guildID string)

RefreshGuildContractsForBannerCallback is a function hook to refresh/redraw contracts in a guild after its default banner is updated.

View Source
var SyncCustomBannerCallback func(userID string, guildID string, destPath string) bool

SyncCustomBannerCallback is a function hook to sync custom banners from the database to disk.

View Source
var UpdateDashboardDisplays func(client dc.Client, userID string)

UpdateDashboardDisplays is a callback used to notify the dashboard of data changes

Functions

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

func CellANSI(s, color string, width int, right bool) string

CellANSI pads s to width with spaces and applies color to the content only. If right: the content is right-aligned.

func CleanContractTeamNames

func CleanContractTeamNames(raw string) []string

CleanContractTeamNames parses and cleans a raw string (which may be JSON or plain text with conversational preambles/lists) into a slice of team names.

func DownloadAttachmentBytesDC

func DownloadAttachmentBytesDC(att *dc.Attachment) ([]byte, error)

DownloadAttachmentBytesDC downloads the attachment content and returns it as a byte slice, given the dc facade's neutral Attachment form.

func DownloadLatestEggImages

func DownloadLatestEggImages(localDownloadDir string) error

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 EnsureEmojiFromLocalRepoWithClient

func EnsureEmojiFromLocalRepoWithClient(client dc.Client, name string) (ei.Emotes, bool)

EnsureEmojiFromLocalRepoWithClient tries to load a missing emoji from the local emoji directory, uploads it to Discord via the dc facade client, and refreshes the in-memory emoji map.

func EscapeDiscordMarkdown

func EscapeDiscordMarkdown(s string) string

EscapeDiscordMarkdown escapes special characters in a string to prevent Discord from interpreting them as Markdown formatting.

func FindCategoryID

func FindCategoryID(client dc.Client, channelID string) (string, error)

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

func FmtDuration(d time.Duration) string

FmtDuration formats a time.Duration into a human-readable string with seconds precision.

func FmtDurationSingleUnit

func FmtDurationSingleUnit(d time.Duration) (string, int)

FmtDurationSingleUnit formats a time.Duration into a single unit string and its corresponding unit integer

func FormatIntWithCommas

func FormatIntWithCommas[T ~int | ~int64 | ~uint | ~uint32 | ~uint64](v T) string

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 GetDiscordAvatarURL

func GetDiscordAvatarURL(client dc.Client, guildID string, discordID string) string

GetDiscordAvatarURL looks up the avatar image URL for a given Discord user ID.

func GetFormattedCommand

func GetFormattedCommand(command string) string

GetFormattedCommand returns the formatted command string

func GetGistData

func GetGistData(filename string) (string, error)

GetGistData retrieves data from a Gist and unmarshals it into the target interface.

func GetRandomName

func GetRandomName(_ int) string

GetRandomName returns a docker-style random name.

func GetSandboxIHRItemIndices

func GetSandboxIHRItemIndices(artifacts []string) (string, string, string, string)

GetSandboxIHRItemIndices returns the indices for Chalice, Monocle, IHR Defl., and IHR SIAB.

func GetSandboxItemIndices

func GetSandboxItemIndices(artifacts []string) (string, string, string, string)

GetSandboxItemIndices returns the indices for Metro, Comp, Gusset, and Defl.

func GetSlashRemoveMessage

func GetSlashRemoveMessage(cmd string) *dc.Command

GetSlashRemoveMessage returns the slash command for removing a bot message from a DM channel.

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

func GetTokenValue(seconds float64, durationSeconds float64) float64

GetTokenValue calculates the token value based on the given parameters

func HandleRemoveMessage

func HandleRemoveMessage(client dc.Client, e *dc.CommandEvent)

HandleRemoveMessage handles the remove message command against the dc facade.

func ImportEggImageWithClient

func ImportEggImageWithClient(client dc.Client, eggID, IconURL string) (string, error)

ImportEggImageWithClient will import an egg image into the discord app using the dc facade client.

func ImportNewEmojisWithClient

func ImportNewEmojisWithClient(client dc.Client)

ImportNewEmojisWithClient will import new emojis from the emoji directory into the discord app using the dc facade client.

func IsRandomName

func IsRandomName(name string) bool

IsRandomName returns true if name matches the generated docker-style random name format.

func IsValidDiscordID

func IsValidDiscordID(id string) bool

IsValidDiscordID checks if a string is a valid Discord snowflake ID by validating the embedded timestamp is within Discord's operational range

func LoadEmotesWithClient

func LoadEmotesWithClient(client dc.Client, force bool)

LoadEmotesWithClient will load all the emojis from the app using the dc facade client.

func LoadFontFile

func LoadFontFile(name string, size, dpi float64) (font.Face, error)

func NormalizeBannerImage

func NormalizeBannerImage(img image.Image) ([]byte, string, error)

NormalizeBannerImage resizes an image to fill the banner dimensions and center-crops when needed.

func NumberToEmoji

func NumberToEmoji(n int) string

NumberToEmoji converts any non-negative integer to a string of emoji digits

func PutGistData

func PutGistData(filename string, data string) error

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 ReloadEmotes

func ReloadEmotes(client dc.Client) (int, error)

ReloadEmotes removes the cached emoji file, fetches all application emojis from Discord, updates in-memory mapping, and saves the new cache file.

func SanitizeStringDuration

func SanitizeStringDuration(s string) string

SanitizeStringDuration takes an hms string and returns a sanitized version of it

func UpdateCommandMap

func UpdateCommandMap(definitions []*dc.Command, published []dc.CommandRef)

UpdateCommandMap records the ID Discord assigned each published command so GetFormattedCommand can render a "</name:id>" mention link.

The IDs come from what Discord returned; the subcommand paths come from the definitions the bot published, because a CommandRef carries only a name and an ID.

func VisibleLenANSI

func VisibleLenANSI(s string) int

VisibleLenANSI returns the rune length of s excluding ANSI escape codes.

func WrapANSI

func WrapANSI(s, color string) string

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

type FutureToken struct {
	Value float64
	Time  time.Time
}

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
)

type TimestampNumber

type TimestampNumber interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

TimestampNumber is a set of integer types that can be used as Unix timestamps.

Jump to

Keyboard shortcuts

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