Skip to content

Commit

Permalink
Merge https://github.com/tripsit/TripBot into pr/LunaUrsa/830
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaUrsa committed Aug 25, 2024
2 parents b4c5df0 + 1bff4b5 commit 6dc7f2c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/discord/commands/global/d.combo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
41 changes: 22 additions & 19 deletions src/global/commands/g.combo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -92,20 +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();
}

// If the drug is not in the drug database, check the combo database
Expand All @@ -125,14 +111,31 @@ 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;
}

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}')` : '';
Expand All @@ -157,8 +160,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) {
Expand Down

0 comments on commit 6dc7f2c

Please sign in to comment.