leaderboard

package
v0.0.0-...-740c2d9 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: Unlicense Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LBEarningsBonus  = "eb"
	LBSoulEggs       = "soul_eggs"
	LBProphecyEggs   = "prophecy_eggs"
	LBTerrorEvents   = "terror_events"
	LBEggsDelivered  = "eggs_delivered"
	LBContractExp    = "contract_exp"
	LBEggsTotal      = "eggs_total"
	LBStandardPermit = "std_permit"
	LBDrones         = "drones"
	LBEliteDrones    = "elite_drones"
	LBPrestiges      = "prestiges"
	LBSoulMirrors    = "soul_mirrors"
	LBVirtueShifts   = "virtue_shifts"
	LBTETotal        = "te_total"
	LBCTETotal       = "cte_total"
	LBTEPerShift     = "te_per_shift"
	LBSEPerPrestige  = "se_per_prestige"
	LBCXPWeeklyDelta = "cxp_weekly"
	//LBAAASoloDuration = "aaa_solo_duration"
	LBEggsCuriosity  = "egg_curiosity"
	LBEggsIntegrity  = "egg_integrity"
	LBEggsHumility   = "egg_humility"
	LBEggsResilience = "egg_resilience"
	LBEggsKindness   = "egg_kindness"

	LBLegendaryActuators = "legendary_actuators"
	LBCraftingXP         = "crafting_xp"
	LBArtifactScore      = "artifact_score"

	LBVirtueEggsSum     = "virtue_eggs_sum"
	LBVirtueTEEarnedSum = "virtue_te_earned_sum"

	LBShipChicken1           = "ship_chicken1"
	LBShipChicken9           = "ship_chicken9"
	LBShipChickenHeavy       = "ship_chicken_heavy"
	LBShipBCR                = "ship_bcr"
	LBShipMilleniumChicken   = "ship_millenium_chicken"
	LBShipCorellihenCorvette = "ship_corvette"
	LBShipGaleggtica         = "ship_galeggtica"
	LBShipDefihent           = "ship_defihent"
	LBShipVoyegger           = "ship_voyegger"
	LBShipHenerprise         = "ship_henerprise"
	LBShipAtreggies          = "ship_atreggies"

	LBShipStdChicken1           = "std_ship_chicken1"
	LBShipStdChicken9           = "std_ship_chicken9"
	LBShipStdChickenHeavy       = "std_ship_chicken_heavy"
	LBShipStdBCR                = "std_ship_bcr"
	LBShipStdMilleniumChicken   = "std_ship_millenium_chicken"
	LBShipStdCorellihenCorvette = "std_ship_corvette"
	LBShipStdGaleggtica         = "std_ship_galeggtica"
	LBShipStdDefihent           = "std_ship_defihent"
	LBShipStdVoyegger           = "std_ship_voyegger"
	LBShipStdHenerprise         = "std_ship_henerprise"
	LBShipStdAtreggies          = "std_ship_atreggies"
)

Leaderboard keys constants.

View Source
const OptInAll = "all"

OptInAll represents the option to opt into all available leaderboards.

Variables

View Source
var AllGroups = []LBGroup{
	{
		Key:         "group_core",
		DisplayName: "EB Stats",
		Members:     []string{LBEarningsBonus, LBSoulEggs, LBProphecyEggs, LBTETotal, LBCTETotal, LBVirtueShifts, LBPrestiges},
	},
	{
		Key:         "group_cs_stats",
		DisplayName: "CS Stats",
		Members:     []string{LBContractExp, LBCXPWeeklyDelta},
	},
	{
		Key:         "group_misc",
		DisplayName: "Miscellaneous Stats",
		Members:     []string{LBDrones, LBEliteDrones, LBSoulMirrors},
	},
	{
		Key:         "group_ratios",
		DisplayName: "Ratio Leaderboards",
		Members:     []string{LBTEPerShift, LBSEPerPrestige},
	},
	{
		Key:         "group_artifacts",
		DisplayName: "Artifacts",
		Members:     []string{LBLegendaryActuators, LBCraftingXP, LBArtifactScore},
	},
}

AllGroups defines logical groupings for the UI and posting tasks.

View Source
var AllLeaderboards = []LBDef{
	{Key: LBSoulEggs, DisplayName: "Soul Eggs", HeaderName: "SE", Description: "Total soul eggs collected.", ValueFmt: "ei", HigherIsBetter: true, Source: SourceFirstContact, RetainRecentOnly: true},
	{Key: LBProphecyEggs, DisplayName: "Prophecy Eggs", HeaderName: "PE", Description: "Total eggs of prophecy collected.", ValueFmt: "int", HigherIsBetter: true, Source: SourceFirstContact, RetainRecentOnly: true},
	{Key: LBEarningsBonus, DisplayName: "Earnings Bonus", Description: "Nekkid and Dressed earnings bonus.", ValueFmt: "eb", HigherIsBetter: true, Source: SourceFirstContact, RetainRecentOnly: true},
	{Key: LBVirtueShifts, DisplayName: "Virtue Shifts", HeaderName: "Shifts", Description: "Total virtue shifts completed.", ValueFmt: "int", HigherIsBetter: true, Source: SourceFirstContact, RetainRecentOnly: true},
	{Key: LBTETotal, DisplayName: "Total Truth Eggs", HeaderName: "TE", Description: "Sum of truth eggs across all virtues.", ValueFmt: "int", HigherIsBetter: true, Source: SourceFirstContact, RetainRecentOnly: true},
	{Key: LBCTETotal, DisplayName: "Total CTE", HeaderName: "CTE", Description: "Clothed Truth Egg equivalent for pending and current TE.", ValueFmt: "int", HigherIsBetter: true, Source: SourceFirstContact, RetainRecentOnly: true},
	{Key: LBTEPerShift, DisplayName: "TE per Shift", HeaderName: "TE/Shift", Description: "Average Truth Eggs earned per Virtue Shift.", ValueFmt: "float", HigherIsBetter: true, Source: SourceFirstContact, RetainRecentOnly: true},
	{Key: LBDrones, DisplayName: "Drones", Description: "Total drones taken down.", ValueFmt: "int", HigherIsBetter: true, Source: SourceFirstContact, RetainRecentOnly: true},
	{Key: LBEliteDrones, DisplayName: "Elite Drones", Description: "Total elite drones taken down.", ValueFmt: "int", HigherIsBetter: true, Source: SourceFirstContact, RetainRecentOnly: true},
	{Key: LBPrestiges, DisplayName: "Prestiges", Description: "Total number of prestiges.", ValueFmt: "int", HigherIsBetter: true, Source: SourceFirstContact, RetainRecentOnly: true},
	{Key: LBSEPerPrestige, DisplayName: "SE per Prestige", HeaderName: "SE/Prestige", Description: "Average Soul Eggs earned per Prestige.", ValueFmt: "ei", HigherIsBetter: true, Source: SourceFirstContact, RetainRecentOnly: true},
	{Key: LBSoulMirrors, DisplayName: "Soul Mirrors", HeaderName: "Score", Description: "Score based on soul mirror inventory of Common, Epic & Legendary worth 1, 2, or 3 points respectively (tokens needed to burn them).", ValueFmt: "int", HigherIsBetter: false, Source: SourceFirstContact, RetainRecentOnly: true},
	{Key: LBContractExp, DisplayName: "Contract Score", HeaderName: "CS", Description: "Total experience earned from contracts.", ValueFmt: "cxp", HigherIsBetter: true, Source: SourceBoth},
	{Key: LBCXPWeeklyDelta, DisplayName: "Weekly CS", HeaderName: "CS Delta", Description: "CS change earned within last 7 days.", ValueFmt: "cxp", HigherIsBetter: true, Source: SourceContractArchive},

	{Key: LBEggsCuriosity, DisplayName: "Curiosity Eggs Delivered", Description: "Curiosity deliveries.", ValueFmt: "ei", HigherIsBetter: true, Source: SourceFirstContact, RetainRecentOnly: true},
	{Key: LBEggsIntegrity, DisplayName: "Integrity Eggs Delivered", Description: "Integrity deliveries.", ValueFmt: "ei", HigherIsBetter: true, Source: SourceFirstContact, RetainRecentOnly: true},
	{Key: LBEggsHumility, DisplayName: "Humility Eggs Delivered", Description: "Humility deliveries.", ValueFmt: "ei", HigherIsBetter: true, Source: SourceFirstContact, RetainRecentOnly: true},
	{Key: LBEggsResilience, DisplayName: "Resilience Eggs Delivered", Description: "Resilience deliveries.", ValueFmt: "ei", HigherIsBetter: true, Source: SourceFirstContact, RetainRecentOnly: true},
	{Key: LBEggsKindness, DisplayName: "Kindness Eggs Delivered", Description: "Kindness deliveries.", ValueFmt: "ei", HigherIsBetter: true, Source: SourceFirstContact, RetainRecentOnly: true},
	{Key: LBLegendaryActuators, DisplayName: "Legendary Actuators", HeaderName: "Actuators", Description: "Total Legendary Actuators across home and virtue farms.", ValueFmt: "int", HigherIsBetter: true, Source: SourceFirstContact, RetainRecentOnly: true},
	{Key: LBCraftingXP, DisplayName: "Crafting XP", HeaderName: "XP", Description: "Total Crafting Experience.", ValueFmt: "int", HigherIsBetter: true, Source: SourceFirstContact, RetainRecentOnly: true},
	{Key: LBArtifactScore, DisplayName: "Artifact Score", HeaderName: "Score", Description: "Calculated Artifact Score based on inventory.", ValueFmt: "float", HigherIsBetter: true, Source: SourceFirstContact, RetainRecentOnly: true},
}

AllLeaderboards is the registry of all available individual leaderboard types.

Functions

func AddPlayerOptInTypes

func AddPlayerOptInTypes(guildID, userID string, types []string)

AddPlayerOptInTypes adds the given types to the player's opt-in list for a guild.

func DeleteGuildLBConfig

func DeleteGuildLBConfig(guildID, lbType string) error

DeleteGuildLBConfig removes a leaderboard config row.

func DisplayNameForConfigKey

func DisplayNameForConfigKey(key string) string

DisplayNameForConfigKey returns a human-readable name for any config key (individual or group).

func ExpandConfigKey

func ExpandConfigKey(key string) []string

ExpandConfigKey returns the individual lb_type keys that a channel config key resolves to. For group keys this is the group's Members slice; for individual type keys it's a single-element slice containing that key.

func FormatLBDelta

func FormatLBDelta(fmtValue string, delta float64) string

FormatLBDelta formats a numeric difference from the previous week.

func FormatLBValue

func FormatLBValue(fmtValue string, v float64) string

FormatLBValue formats a numeric leaderboard value according to the LBDef.ValueFmt.

func GetAllOptInUserIDs

func GetAllOptInUserIDs() []string

GetAllOptInUserIDs returns all user IDs who have opted into leaderboards in ANY guild.

func GetLatestSnapDate

func GetLatestSnapDate(lbType string) string

GetLatestSnapDate returns the most recent snap_date for a lb_type, or "".

func GetPlayerOptInTypes

func GetPlayerOptInTypes(guildID, userID string) []string

GetPlayerOptInTypes returns the slice of lb_type keys the user is opted into for a guild.

func GetPreviousSnapDate

func GetPreviousSnapDate(lbType, snapDate string) string

GetPreviousSnapDate returns the snap_date immediately before the given one.

func GetSlashAdminLBCommand

func GetSlashAdminLBCommand(cmd string) *discordgo.ApplicationCommand

GetSlashAdminLBCommand returns the /admin-lb command definition.

func GetSlashLBPlayerCommand

func GetSlashLBPlayerCommand(cmd string) *discordgo.ApplicationCommand

GetSlashLBPlayerCommand returns the /lb command definition.

func GetUserOptInGuilds

func GetUserOptInGuilds(userID string) []string

GetUserOptInGuilds returns all guild IDs where the user has at least one opt-in.

func HandleAdminLB

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

HandleAdminLB dispatches the /admin-lb slash command.

func HandleAdminLBAutoComplete

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

HandleAdminLBAutoComplete handles autocomplete for the /admin-lb command.

func HandleLBListComponent

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

HandleLBListComponent handles button clicks for the leaderboard list pagination.

func HandleLBPageButton

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

HandleLBPageButton handles pagination buttons for leaderboard posts.

func HandleLBPlayer

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

HandleLBPlayer dispatches the /lb slash command.

func HandleLBPlayerAutoComplete

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

HandleLBPlayerAutoComplete handles autocomplete for the /lb command.

func HandleLBStatsComponent

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

HandleLBStatsComponent handles button clicks for the leaderboard rankings pagination.

func IsValidConfigKey

func IsValidConfigKey(key string) bool

IsValidConfigKey returns true if key is either an individual LBDef key or a group key — i.e. valid for use in /admin-lb admin set-channel.

func PlayerIsOptedIn

func PlayerIsOptedIn(guildID, userID, lbType string) bool

PlayerIsOptedIn returns true if the user is opted into the given lb_type in the given guild.

func PostLeaderboards

func PostLeaderboards(s *discordgo.Session, snapDate string, guildID string, target string, action string, onProgress func(string))

PostLeaderboards triggers the posting task for all configured guilds (or a specific guild if guildID is provided).

func RemovePlayerOptInTypes

func RemovePlayerOptInTypes(guildID, userID string, types []string)

RemovePlayerOptInTypes removes the given types from the player's opt-in list for a guild.

func RunLeaderboardCollection

func RunLeaderboardCollection(s *discordgo.Session, dryRun bool, guildID string, target string, action string, onProgress func(string))

RunLeaderboardCollection is the main weekly entry point. It fans out API calls through a bounded worker pool, saves results, then posts to Discord. Pass dryRun=true to skip the Discord post step.

func SaveLBEntry

func SaveLBEntry(e LBEntry)

SaveLBEntry persists one leaderboard stat row.

func ScheduleWeeklyCollection

func ScheduleWeeklyCollection(s *discordgo.Session)

ScheduleWeeklyCollection registers the Friday 15:00 PT collection cron job. Call this from tasks.ExecuteCronJob.

func SnapDateNow

func SnapDateNow() string

SnapDateNow returns today's ISO date string used as the snap_date primary key.

func UpdateGuildLBConfigMessageIDs

func UpdateGuildLBConfigMessageIDs(guildID, lbType string, messageIDs []string)

UpdateGuildLBConfigMessageIDs persists message IDs after a post run.

func UpsertGuildLBConfig

func UpsertGuildLBConfig(cfg LBConfig) error

UpsertGuildLBConfig saves or updates a leaderboard config row.

Types

type LBConfig

type LBConfig struct {
	LBType     string
	GuildID    string
	ChannelID  string
	MessageIDs []string // JSON-decoded message ID list
}

LBConfig holds one row from the leaderboard_config table.

func GetAllConfigs

func GetAllConfigs() ([]LBConfig, error)

GetAllConfigs retrieves every configured leaderboard in the system.

func GetAllLBConfigs

func GetAllLBConfigs() ([]LBConfig, error)

GetAllLBConfigs retrieves every leaderboard config (used by the weekly task).

func GetGuildLBConfig

func GetGuildLBConfig(guildID, lbType string) (*LBConfig, error)

GetGuildLBConfig retrieves a single config row.

func GetGuildLBConfigs

func GetGuildLBConfigs(guildID string) ([]LBConfig, error)

GetGuildLBConfigs retrieves all leaderboard configs for a single guild.

type LBDef

type LBDef struct {
	Key              string
	DisplayName      string
	HeaderName       string // optional column header override for posting (defaults to DisplayName)
	Description      string
	ValueFmt         string // "int", "float", "ei", "eb", "cxp"
	HigherIsBetter   bool
	Source           LBSource
	RetainRecentOnly bool // Only keep the most recent set of LB records
}

LBDef defines a single leaderboard metric.

func LBDefByKey

func LBDefByKey(key string) (LBDef, bool)

LBDefByKey looks up a definition by its unique key.

type LBEntry

type LBEntry struct {
	LBType   string
	Player   string // Discord user ID
	GameName string // Egg Inc in-game name
	SnapDate string // ISO date "YYYY-MM-DD"
	Value    float64
	Details  string // human-readable extra info
}

LBEntry is a collected data row for one player on one leaderboard.

func GetLeaderboardRows

func GetLeaderboardRows(lbType, snapDate, guildID string) []LBEntry

GetLeaderboardRows returns all rows for a lb_type on a given snap_date for a guild, ranked by value.

func GetPriorStatForPlayer

func GetPriorStatForPlayer(lbType, playerID string) *LBEntry

GetPriorStatForPlayer returns the most recent stored stat for a player+lbType.

func RunCalculators

func RunCalculators(
	userID string,
	backup *ei.Backup,
	archive []*ei.LocalContract,
	optedIn []string,
	snapDate string,
	priorCXPTotal float64,
) []LBEntry

RunCalculators evaluates all opted-in leaderboard types for a single player from their first-contact backup.

archive is the contract archive result (used only for SourceContractArchive types). Pass nil for archive if only SourceFirstContact types are being evaluated.

snapDate is the ISO date string "YYYY-MM-DD" for this collection run. priorCXPTotal is the total CXP from the previous collection, used for delta calculation.

type LBGroup

type LBGroup struct {
	Key         string
	DisplayName string
	Members     []string // Slice of LBDef.Key
}

LBGroup defines a collection of leaderboard metrics that are posted together.

func GroupByKey

func GroupByKey(key string) (LBGroup, bool)

GroupByKey looks up a group by its unique key.

type LBSource

type LBSource int

LBSource represents the backend data source required to calculate a metric.

const (
	SourceFirstContact LBSource = iota
	SourceContractArchive
	SourceBoth
)

Data source constants.

type PlayerStat

type PlayerStat struct {
	Def     LBDef
	Current LBEntry
	HasPrev bool
	PrevVal float64
	Rank    int
}

PlayerStat holds a single metric's latest value and its previous week's value for comparison.

func GetPlayerStats

func GetPlayerStats(guildID, playerID string) []PlayerStat

GetPlayerStats retrieves the latest data for every leaderboard type for a given player in a guild.

type PostProgress

type PostProgress struct {
	TotalMetrics  int
	PostedMetrics int
	TotalDuration time.Duration
}

PostProgress tracks the progress of posting multiple leaderboards, allowing for ETA estimation and progress reporting.

Jump to

Keyboard shortcuts

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