From 314d786f4719a0628fd6a1e6545b11d5c8853e98 Mon Sep 17 00:00:00 2001 From: Kristofer Date: Fri, 15 Dec 2023 14:58:37 +0100 Subject: [PATCH] Make host a required param when getting settings --- packages/discord-bot/src/handlers/praise.ts | 6 ++++-- packages/discord-bot/src/utils/renderMessage.ts | 2 ++ packages/discord-bot/src/utils/settingsUtil.ts | 3 +-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/discord-bot/src/handlers/praise.ts b/packages/discord-bot/src/handlers/praise.ts index bc6e66529..e615a316e 100644 --- a/packages/discord-bot/src/handlers/praise.ts +++ b/packages/discord-bot/src/handlers/praise.ts @@ -164,7 +164,8 @@ export const praiseHandler: CommandHandler = async ( } } else { const directQuantificationEnanbled = (await getSetting( - 'DISCORD_BOT_DIRECT_PRAISE_QUANTIFICATION_ENABLED' + 'DISCORD_BOT_DIRECT_PRAISE_QUANTIFICATION_ENABLED', + host )) as boolean; // If direct quantification is disabled, give praise directly @@ -186,7 +187,8 @@ export const praiseHandler: CommandHandler = async ( // If direct quantification is enabled, allow user to select a score from a dropdown const allowedScores = (await getSetting( - 'PRAISE_QUANTIFY_ALLOWED_VALUES' + 'PRAISE_QUANTIFY_ALLOWED_VALUES', + host )) as number[]; const select = new StringSelectMenuBuilder() diff --git a/packages/discord-bot/src/utils/renderMessage.ts b/packages/discord-bot/src/utils/renderMessage.ts index 93ff208b7..c629ab53d 100644 --- a/packages/discord-bot/src/utils/renderMessage.ts +++ b/packages/discord-bot/src/utils/renderMessage.ts @@ -18,6 +18,8 @@ export const renderMessage = async ( if (key === 'DM_ERROR' && !host) return "The bot can't be used in DMs, please use commands in the server."; + if (!host) return "Unknown host, can't render message"; + let msg = (await getSetting(key, host)) as string; if (subs) { diff --git a/packages/discord-bot/src/utils/settingsUtil.ts b/packages/discord-bot/src/utils/settingsUtil.ts index 0033eef03..309a06cd0 100644 --- a/packages/discord-bot/src/utils/settingsUtil.ts +++ b/packages/discord-bot/src/utils/settingsUtil.ts @@ -59,13 +59,12 @@ export const getDefaultSetting = ( export const getSetting = async ( key: string, - host?: string + host: string ): Promise => { const setting = await apiGet(`/settings?key=${key}`, { headers: host ? { host: host } : {}, }) .then((res) => { - logger.debug(res.data); return res.data[0].valueRealized ? res.data[0].valueRealized : getDefaultSetting(key);