diff --git a/bot/src/profile/buildProfileEmbed.ts b/bot/src/profile/buildProfileEmbed.ts index 9eadf151f..1877aeac0 100644 --- a/bot/src/profile/buildProfileEmbed.ts +++ b/bot/src/profile/buildProfileEmbed.ts @@ -1,11 +1,17 @@ import { InteractionReplyOptions, MessageActionRow, MessageEmbed, MessagePayload, MessageSelectMenu } from "discord.js"; import { Game, UserGameStats } from "tachi-common"; -import { IDStrings, UGSRatingsLookup } from "tachi-common/js/types"; +import { IDStrings, PublicUserDocument, UGSRatingsLookup } from "tachi-common/js/types"; import { find } from "lodash"; import { LoggerLayers } from "../config"; import { TachiServerV1Get } from "../utils/fetch-tachi"; import { createLayeredLogger } from "../utils/logger"; -import { formatGameWrapper, prettyRatingString, SimpleGameType, simpleGameTypeToString } from "../utils/utils"; +import { + formatGameWrapper, + getPfpUrl, + prettyRatingString, + SimpleGameType, + simpleGameTypeToString +} from "../utils/utils"; const logger = createLayeredLogger(LoggerLayers.buildProfileEmbed); @@ -23,14 +29,32 @@ const pullRatings = ( return allRatings; }; -export const buildProfileEmbed = (data: UserGameStats[], game?: SimpleGameType): MessageEmbed => { +export const fetchUserDetails = async (userId: number): Promise => { + try { + logger.info(`Fetching public user document for ${userId}`); + const data = (await TachiServerV1Get(`/users/${userId}`))?.body; + if (data) { + return data; + } else { + throw new Error(`Could not find public user document for ${userId}`); + } + } catch (e) { + logger.error("Unable to fetch user details"); + throw new Error("Unable to fetch user details"); + } +}; + +export const buildProfileEmbed = async (data: UserGameStats[], game?: SimpleGameType): Promise => { const embed = new MessageEmbed().setColor("#cc527a"); - /** @TODO FETCH USERS ACTUAL DETAILS */ - embed.addField("Foo", "Foo"); - embed.addField("Bar", "Bar"); - embed.addField("Baz", "Baz"); - embed.setThumbnail("https://cdn.mos.cms.futurecdn.net/mrArzwHcNuQbRwbEmuiwdJ.jpg"); + const userId = data[0].userID; + const userDetails = await fetchUserDetails(userId); + const pfp = userDetails.customPfp + ? getPfpUrl(userId) + : "https://cdn.mos.cms.futurecdn.net/mrArzwHcNuQbRwbEmuiwdJ.jpg"; + embed.setTitle(`${userDetails.username}'s Profile`); + embed.setThumbnail(pfp); + embed.setAuthor(`@${userDetails.username}`, pfp); if (game) { const specificData: UserGameStats | undefined = find( @@ -72,7 +96,7 @@ export const buildProfileIntractable = async ( ) ); - return { embeds: [buildProfileEmbed(data, game)], components: [dropdown] }; + return { embeds: [await buildProfileEmbed(data, game)], components: [dropdown] }; } else { throw new Error(`No data found for user ${userId}`); } diff --git a/bot/src/utils/utils.ts b/bot/src/utils/utils.ts index b9e0b70e3..db80da880 100644 --- a/bot/src/utils/utils.ts +++ b/bot/src/utils/utils.ts @@ -1,5 +1,7 @@ import { FormatGame, Game, Playtypes } from "tachi-common"; import { IDStrings, UGSRatingsLookup } from "tachi-common/js/types"; +import { ProcessEnv } from "../setup"; +import { PrependTachiUrl } from "./fetch-tachi"; export interface SimpleGameType { game: T; @@ -26,10 +28,17 @@ export const prettyRatingString = (rating: UGSR case "VF6": return "Volforce"; case "BPI": - return "BPI"; + return "Beat Power Index"; case "MFCP": - return "???"; + return "MFCs"; default: return "Skill"; } }; + +export const getPfpUrl = (userId: number): string => { + if (ProcessEnv.ENV !== "prod") { + return `https://kamaitachi.xyz/static/images/users/${userId}-pfp.png`; + } + return PrependTachiUrl(`/users/${userId}/pfp`); +};