bottools

package
v0.0.0-...-f902ab0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: Unlicense Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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 DownloadLatestEggImages

func DownloadLatestEggImages(localDownloadDir string) error

DownloadLatestEggImages downloads the latest image files from a specific GitHub repository directory.

func FindCategoryID

func FindCategoryID(s *discordgo.Session, 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 Parameters:

  • d (time.Duration)

Returns:

  • (string): the duration value as a string.
  • (int): the duration unit as an integer (0: days, 1: hours, 2: minutes, 3: seconds).

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)

GenerateBanner creates a banner image with a background, overlay image, and text

func GenerateSnapshots

func GenerateSnapshots(outputPath, packageName string) error

GenerateSnapshots writes snapshot structs to outputPath for the listed protobuf types. Run this manually with:

go run ./src/bottools/cmd/run_snapshots.go

func GetCommandOptionsMap

GetCommandOptionsMap returns a map of command options subcommand options are stored as "subcommand-option"

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 GetInteractionUserID

func GetInteractionUserID(i *discordgo.InteractionCreate) string

GetInteractionUserID returns the user ID from an interaction, whether in a guild or DM

func GetSlashRemoveMessage

func GetSlashRemoveMessage(cmd string) *discordgo.ApplicationCommand

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 HandleRemoveMessageCommand

func HandleRemoveMessageCommand(s *discordgo.Session, i *discordgo.InteractionCreate)

HandleRemoveMessageCommand handles the remove message command.

func ImportEggImage

func ImportEggImage(s *discordgo.Session, eggID, IconURL string) (string, error)

ImportEggImage will import an egg image into the discord app

func ImportNewEmojis

func ImportNewEmojis(s *discordgo.Session)

ImportNewEmojis will import new emojis from the emoji directory into the discord app

func LoadEmotes

func LoadEmotes(s *discordgo.Session, force bool)

LoadEmotes will load all the emojis from the app

func NewSmallSeparatorComponent

func NewSmallSeparatorComponent(visible bool) *discordgo.Separator

NewSmallSeparatorComponent returns a Discord separator component configured with small spacing and optional visibility.

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 SanitizeStringDuration

func SanitizeStringDuration(s string) string

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

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 (
	// Default        <t:1543392060>      November 28, 2018 9:01 AM            || 28 November 2018 09:01
	TimestampDefault DiscordTimestampFormat = ""
	// Short Time     <t:1543392060:t>    9:01 AM                              || 09:01
	TimestampShortTime DiscordTimestampFormat = "t"
	// Long Time      <t:1543392060:T>    9:01:00 AM                           || 09:01:00
	TimestampLongTime DiscordTimestampFormat = "T"
	// Short Date     <t:1543392060:d>    11/28/2018                           || 28/11/2018
	TimestampShortDate DiscordTimestampFormat = "d"
	// Long Date      <t:1543392060:D>    November 28, 2018                    || 28 November 2018
	TimestampLongDate DiscordTimestampFormat = "D"
	// Short Date/Time<t:1543392060:f>    November 28, 2018 9:01 AM            || 28 November 2018 09:01
	TimestampShortDateTime DiscordTimestampFormat = "f"
	// Long Date/Time <t:1543392060:F>    Wednesday, November 28, 2018 9:01 AM || Wednesday, 28 November 2018 09:01
	TimestampLongDateTime DiscordTimestampFormat = "F"
	// Relative Time  <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