From b72e9d1bbca2fdae6e621424af7cc7fc894ac6de Mon Sep 17 00:00:00 2001 From: Pfych Date: Sat, 25 Sep 2021 12:29:18 +1000 Subject: [PATCH] Create a getTachiIdByDiscordId stub --- bot/src/config.ts | 3 ++- bot/src/profile/fetch.ts | 3 ++- bot/src/utils/discord-to-tachi.ts | 10 ++++++++++ bot/src/utils/utils.ts | 2 -- 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 bot/src/utils/discord-to-tachi.ts diff --git a/bot/src/config.ts b/bot/src/config.ts index 86bf3e1c4..52ec93b67 100644 --- a/bot/src/config.ts +++ b/bot/src/config.ts @@ -10,5 +10,6 @@ export enum LoggerLayers { tachiFetch = "tachiFetch", profile = "profile", selectInteractionHandler = "selectInteractionHandler", - buildProfileEmbed = "buildProfileEmbed" + buildProfileEmbed = "buildProfileEmbed", + tachiLinker = "tachiLinker" } diff --git a/bot/src/profile/fetch.ts b/bot/src/profile/fetch.ts index 665a91c90..9ef409269 100644 --- a/bot/src/profile/fetch.ts +++ b/bot/src/profile/fetch.ts @@ -2,6 +2,7 @@ import { CommandInteraction } from "discord.js"; import { IDStrings } from "tachi-common"; import { LoggerLayers } from "../config"; import { BotConfig } from "../setup"; +import { getTachiIdByDiscordId } from "../utils/discord-to-tachi"; import { createLayeredLogger } from "../utils/logger"; import { stringToSimpleGameType } from "../utils/utils"; import { buildProfileIntractable } from "./buildProfileEmbed"; @@ -11,7 +12,7 @@ const logger = createLayeredLogger(LoggerLayers.profile); export const getProfileByName = async (interaction: CommandInteraction): Promise => { try { /** @TODO this can be an @User, userId or userName!!! Handle this at some point */ - const userId = interaction.options.getString("user", false) || "TODO FALLBACK TO SELF"; + const userId = interaction.options.getString("user", false) || getTachiIdByDiscordId(interaction.user.id); logger.info(`Fetching user ${userId}`); const optionalGameOption = interaction.options.getString("game", false); diff --git a/bot/src/utils/discord-to-tachi.ts b/bot/src/utils/discord-to-tachi.ts new file mode 100644 index 000000000..6467b6c77 --- /dev/null +++ b/bot/src/utils/discord-to-tachi.ts @@ -0,0 +1,10 @@ +import { LoggerLayers } from "../config"; +import { createLayeredLogger } from "./logger"; +const logger = createLayeredLogger(LoggerLayers.tachiLinker); + +/** @TODO Stub */ +export const getTachiIdByDiscordId = (discordId: string): string => { + /** @TODO Hit an internal database to grab user id */ + logger.info(`Fetching linked ID for ${discordId}`); + return "0"; +}; diff --git a/bot/src/utils/utils.ts b/bot/src/utils/utils.ts index 3ab725258..16df3eafd 100644 --- a/bot/src/utils/utils.ts +++ b/bot/src/utils/utils.ts @@ -29,7 +29,6 @@ export const getPfpUrl = (userId: number): string => { return PrependTachiUrl(`/users/${userId}/pfp`); }; -/** @TODO @zkldi is there somewhere this exists already? */ export const gameIdentifierStrings = [ "iidx:SP", "iidx:DP", @@ -57,7 +56,6 @@ export const formatGameScoreRating = ( value: number ): string => { const gptConfig = GetGamePTConfig(gpt.game, gpt.playtype); - /** @TODO UGSRatingsLookup should be able to cast to ScoreCalculatedDataLookup straight up */ const val = gptConfig.profileRatingAlgFormatters[ratingName]; if (val) { return val(value);