diff --git a/bot/src/profile/buildProfileEmbed.ts b/bot/src/profile/buildProfileEmbed.ts index 5021fa24e..aeacd2e73 100644 --- a/bot/src/profile/buildProfileEmbed.ts +++ b/bot/src/profile/buildProfileEmbed.ts @@ -1,11 +1,12 @@ import { InteractionReplyOptions, MessageActionRow, MessageEmbed, MessagePayload, MessageSelectMenu } from "discord.js"; -import { Game, UserGameStats } from "tachi-common"; -import { IDStrings, PublicUserDocument, UGSRatingsLookup } from "tachi-common/js/types"; +import { Game, UserGameStats, IDStrings, PublicUserDocument, UGSRatingsLookup } from "tachi-common"; import { find } from "lodash"; +import { ScoreCalculatedDataLookup } from "tachi-common/js/types"; import { LoggerLayers } from "../config"; import { TachiServerV1Get } from "../utils/fetch-tachi"; import { createLayeredLogger } from "../utils/logger"; import { + formatGameScoreRating, formatGameWrapper, getPfpUrl, prettyRatingString, @@ -16,14 +17,15 @@ import { const logger = createLayeredLogger(LoggerLayers.buildProfileEmbed); const pullRatings = ( + gpt: SimpleGameType, ratings: Partial> ): string[] => { const allRatings: string[] = []; const RatingKeys = Object.keys(ratings); - RatingKeys.map((rating) => { - const ratingValue: number = ratings[rating] || 0; - allRatings.push(`${prettyRatingString(rating)}: ${Math.round((ratingValue + Number.EPSILON) * 100) / 100}`); + RatingKeys.forEach((rating) => { + const ratingValue: string = formatGameScoreRating(gpt, rating, ratings[rating] || 0); + allRatings.push(`${prettyRatingString(rating)}: ${ratingValue}`); }); return allRatings; @@ -68,7 +70,7 @@ export const buildProfileEmbed = async (data: UserGameStats[], game?: SimpleGame if (specificData) { embed.addField( `Stats for: ${formatGameWrapper(game)}`, - `${pullRatings(specificData.ratings).join("\n")}` + `${pullRatings(game, specificData.ratings).join("\n")}` ); } else { embed.addField("Select a game to see stats", `No stats for ${formatGameWrapper(game)}`); diff --git a/bot/src/profile/fetch.ts b/bot/src/profile/fetch.ts index 42893ac62..665a91c90 100644 --- a/bot/src/profile/fetch.ts +++ b/bot/src/profile/fetch.ts @@ -1,5 +1,5 @@ import { CommandInteraction } from "discord.js"; -import { IDStrings } from "tachi-common/js/types"; +import { IDStrings } from "tachi-common"; import { LoggerLayers } from "../config"; import { BotConfig } from "../setup"; import { createLayeredLogger } from "../utils/logger"; diff --git a/bot/src/utils/utils.ts b/bot/src/utils/utils.ts index 9f64b5074..cdd57c7e0 100644 --- a/bot/src/utils/utils.ts +++ b/bot/src/utils/utils.ts @@ -1,4 +1,5 @@ -import { FormatGame, Game, Playtypes, IDStrings, UGSRatingsLookup } from "tachi-common"; +import { FormatGame, Game, Playtypes, IDStrings, UGSRatingsLookup, GetGamePTConfig } from "tachi-common"; +import { ScoreCalculatedDataLookup } from "tachi-common/js/types"; import { ProcessEnv } from "../setup"; import { PrependTachiUrl } from "./fetch-tachi"; @@ -50,3 +51,17 @@ export const gamesToChoicesObject = (): [name: string, value: string][] => { return [formatGameWrapper(stringToSimpleGameType(identifier)), identifier]; }); }; + +export const formatGameScoreRating = ( + gpt: SimpleGameType, + ratingName: UGSRatingsLookup[I], + value: number +): string => { + const gptConfig = GetGamePTConfig(gpt.game, gpt.playtype); + /** @TODO UGSRatingsLookup should be able to cast to ScoreCalculatedDataLookup straight up */ + const val = gptConfig.scoreRatingAlgFormatters[ratingName as unknown as ScoreCalculatedDataLookup[I]]; + if (val) { + return val(value); + } + return value.toFixed(2); +};