Skip to content

Commit

Permalink
Make host a required param when getting settings
Browse files Browse the repository at this point in the history
  • Loading branch information
kristoferlund committed Dec 15, 2023
1 parent 9defd2a commit 314d786
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/discord-bot/src/handlers/praise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions packages/discord-bot/src/utils/renderMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions packages/discord-bot/src/utils/settingsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ export const getDefaultSetting = (

export const getSetting = async (
key: string,
host?: string
host: string
): Promise<string | string[] | boolean | number | number[] | undefined> => {
const setting = await apiGet<Setting[]>(`/settings?key=${key}`, {
headers: host ? { host: host } : {},
})
.then((res) => {
logger.debug(res.data);
return res.data[0].valueRealized
? res.data[0].valueRealized
: getDefaultSetting(key);
Expand Down

0 comments on commit 314d786

Please sign in to comment.