From 50b99b4d73d8bf416a875c7ed81366face2afa03 Mon Sep 17 00:00:00 2001 From: LunaUrsa <1836049+LunaUrsa@users.noreply.github.com> Date: Wed, 21 Aug 2024 18:22:52 -0500 Subject: [PATCH 1/2] fix: Combos --- .vscode/settings.json | 3 ++- src/discord/commands/global/d.combo.ts | 3 ++- src/global/commands/g.combo.ts | 36 ++++++++++++++------------ 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index bc9f27267..8c85ae493 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,8 @@ { + "editor.defaultFormatter": "dbaeumer.vscode-eslint", "eslint.codeActionsOnSave.rules": null, "editor.codeActionsOnSave": { - "source.fixAll.eslint": "explicit" + "source.fixAll.eslint": "always" }, "eslint.validate": [ "javascript", diff --git a/src/discord/commands/global/d.combo.ts b/src/discord/commands/global/d.combo.ts index ddd234aba..d6a3ee6bd 100644 --- a/src/discord/commands/global/d.combo.ts +++ b/src/discord/commands/global/d.combo.ts @@ -26,12 +26,13 @@ export const dCombo: SlashCommand = { .setDescription('Set to "True" to show the response only to you')), async execute(interaction) { log.info(F, await commandContext(interaction)); - const ephemeral:boolean = (interaction.options.getBoolean('ephemeral') === true); + const ephemeral: boolean = (interaction.options.getBoolean('ephemeral') === true); await interaction.deferReply({ ephemeral }); const drugA = interaction.options.getString('first_drug', true); const drugB = interaction.options.getString('second_drug', true); const results = await combo(drugA, drugB); + // log.debug(F, `${JSON.stringify(results, null, 2)}`); if ((results as { err: boolean; diff --git a/src/global/commands/g.combo.ts b/src/global/commands/g.combo.ts index 259b40f2d..7f00e111f 100644 --- a/src/global/commands/g.combo.ts +++ b/src/global/commands/g.combo.ts @@ -57,7 +57,7 @@ export async function combo( let drugBName = drugBInput.toLowerCase(); // Because users can input whatever they want, we need to clean the input - function cleanDrugName(drugName:string):string { + function cleanDrugName(drugName: string): string { // These matches need to come first because otherwise "2x-b" woould be found in the drug DB but not have any interaction info if (/^do.$/i.test(drugName)) { return 'dox'; @@ -92,19 +92,6 @@ export async function combo( if (drug.combos && Object.keys(drug.combos).includes(drugName.toLowerCase())) { return drugName.toLowerCase(); } - - // Otherwise, check the categories - if (drug.categories) { - if (drug.categories.includes('benzodiazepine' as Category)) { - return 'benzodiazepines'; - } - if (drug.categories.includes('opioid' as Category)) { - return 'opioids'; - } - if (drug.categories.includes('ssri' as Category)) { - return 'ssris'; - } - } return drugName.toLowerCase(); } @@ -125,6 +112,23 @@ export async function combo( } } + if (Object.keys(drugData).includes(drugName.toLowerCase())) { + const drug = (drugData as DrugData)[drugName.toLowerCase()] as Drug; + + // Otherwise, check the categories + if (drug.categories) { + if (drug.categories.includes('benzodiazepine' as Category)) { + return 'benzodiazepines'; + } + if (drug.categories.includes('opioid' as Category)) { + return 'opioids'; + } + if (drug.categories.includes('ssri' as Category)) { + return 'ssris'; + } + } + } + return drugName; } @@ -157,8 +161,8 @@ export async function combo( // We use this to show the user all the drugs they can use const allDrugNames = Object.values(drugData as DrugData) - .filter((drug:Drug) => drug.aliases) // Filter drugs without aliases - .map((drug:Drug) => drug.aliases) // Get aliases + .filter((drug: Drug) => drug.aliases) // Filter drugs without aliases + .map((drug: Drug) => drug.aliases) // Get aliases .flat() as string[]; // Flatten array, define as string[] if (!drugAComboData) { From 1bff4b513ccb9394bbe5369fb0cc13530e67ac59 Mon Sep 17 00:00:00 2001 From: LunaUrsa <1836049+LunaUrsa@users.noreply.github.com> Date: Wed, 21 Aug 2024 18:36:50 -0500 Subject: [PATCH 2/2] fix: One more combo fix --- src/global/commands/g.combo.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/global/commands/g.combo.ts b/src/global/commands/g.combo.ts index 7f00e111f..d1d847321 100644 --- a/src/global/commands/g.combo.ts +++ b/src/global/commands/g.combo.ts @@ -92,7 +92,6 @@ export async function combo( if (drug.combos && Object.keys(drug.combos).includes(drugName.toLowerCase())) { return drugName.toLowerCase(); } - return drugName.toLowerCase(); } // If the drug is not in the drug database, check the combo database @@ -135,8 +134,8 @@ export async function combo( drugAName = cleanDrugName(drugAName); drugBName = cleanDrugName(drugBName); - // log.debug(F, `drugAName: ${drugAName}`); - // log.debug(F, `drugBName: ${drugBName}`); + log.debug(F, `drugAName: ${drugAName}`); + log.debug(F, `drugBName: ${drugBName}`); const drugANameString = drugAInput !== drugAName ? ` (converted to '${drugAName}')` : ''; const drugBNameString = drugBInput !== drugBName ? ` (converted to '${drugBName}')` : '';