Skip to content

Commit

Permalink
Merge branch 'main' into change-report-msg
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaUrsa authored Aug 25, 2024
2 parents 7a8ed57 + ad3ebd8 commit b53a229
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 52 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
15 changes: 11 additions & 4 deletions src/discord/commands/global/d.ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1712,14 +1712,14 @@ async function agreeToTerms(
embeds: [embedTemplate()
.setTitle('🤖 Welcome to TripBot\'s AI Module! 🤖')
.setDescription(`
Please agree to the following. Use \`/ai help\` for more more information.
Please agree to the following. Use \`/ai help\` for more information.
${termsOfService}
`)
.setFooter(null)],
components: [
new ActionRowBuilder<ButtonBuilder>().addComponents(
buttonAiAgree.setCustomId(`AI~messageAgree~${messageData.id}`),
buttonAiAgree.setCustomId(`AI~messageAgree~${messageData.author.id}`),
),
],
};
Expand Down Expand Up @@ -2397,11 +2397,12 @@ export async function aiButton(
):Promise<void> {
const buttonID = interaction.customId;
log.debug(F, `buttonID: ${buttonID}`);
const [, buttonAction] = buttonID.split('~') as [
const [, buttonAction, messageAuthorId] = buttonID.split('~') as [
null,
'help' | 'personas' | 'setup' | 'agree' | 'privacy' |
'link' | 'unlink' | 'messageAgree' | 'modify' | 'new' |
'create' | 'delete' | 'deleteConfirm' | 'deleteHistory' | 'deleteHistoryConfirm'];
'create' | 'delete' | 'deleteConfirm' | 'deleteHistory' | 'deleteHistoryConfirm',
string];

// eslint-disable-next-line sonarjs/no-small-switch
switch (buttonAction) {
Expand All @@ -2427,6 +2428,12 @@ export async function aiButton(
},
});

// const messageData = await interaction.message.fetchReference();

if (messageAuthorId !== interaction.user.id) {
log.debug(F, `${interaction.user.displayName} tried to accept the AI ToS using someone else's instance of the ToS.`);
return;
}
await aiMessage(interaction.message);
break;
}
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
81 changes: 54 additions & 27 deletions src/discord/commands/guild/d.moderate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,43 +839,50 @@ export async function modResponse(
create: { discord_id: userId },
update: {},
});

actionRow.addComponents(
modButtonNote(userId),
);

let banVerb = 'ban';
let userBan = {} as GuildBan;
try {
userBan = await interaction.guild.bans.fetch(userId);
} catch (err: unknown) {
// log.debug(F, `Error fetching ban: ${err}`);
}
if (userBan.guild) {
if (showModButtons) {
actionRow.addComponents(
modButtonUnBan(userId),
modButtonNote(userId),
);
banVerb = 'un-ban';
} else {

let userBan = {} as GuildBan;
try {
userBan = await interaction.guild.bans.fetch(userId);
} catch (err: unknown) {
// log.debug(F, `Error fetching ban: ${err}`);
}
if (userBan.guild) {
actionRow.addComponents(
modButtonUnBan(userId),
);
banVerb = 'un-ban';
} else {
actionRow.addComponents(
modButtonBan(userId),
);
}

actionRow.addComponents(
modButtonBan(userId),
modButtonInfo(userId),
);
}

actionRow.addComponents(
modButtonInfo(userId),
);

if (isReport(command)) {
if (isReport(command) && showModButtons) {
modEmbedObj.setDescription(stripIndents`
User ID '${userId}' is not in the guild, but I can still Note or ${banVerb} them!`);
} else {
log.debug(F, '[modResponse] generating user info');
const modlogEmbed = await userInfoEmbed(actor, targetObj, targetData, command, showModButtons);
log.debug(F, `modlogEmbed: ${JSON.stringify(modlogEmbed, null, 2)}`);
actionRow.setComponents([
modButtonInfo(userId),
]);
if (showModButtons) {
actionRow.setComponents([
modButtonInfo(userId),
]);
} else {
actionRow.setComponents([
modButtonReport(userId),
]);
}
if (isBan(command)) {
actionRow.addComponents(
modButtonUnBan(userId),
Expand Down Expand Up @@ -1502,6 +1509,10 @@ export async function moderate(
);
}

if (command === 'FULL_BAN') {
internalNote += `\n **Actioned by:** ${actor.displayName}`;
}

let actionData = {
user_id: targetData.id,
guild_id: actor.guild.id,
Expand Down Expand Up @@ -1699,7 +1710,7 @@ export async function moderate(
> ${modalInt.fields.getTextInputValue('internalNote')}
Message sent to user:
> ${modalInt.fields.getTextInputValue('description')}`,
> ${!isNote(command) && !isReport(command) ? modalInt.fields.getTextInputValue('description') : ''}`,
inline: true,
},
);
Expand All @@ -1721,7 +1732,7 @@ export async function moderate(
.setDescription(desc)
.setFooter(null);

if (command !== 'REPORT' && modThread) response.setDescription(`${response.data.description}\nYou can access their thread here: ${modThread}`);
if (!isReport(command) && modThread) response.setDescription(`${response.data.description}\nYou can access their thread here: ${modThread}`);

log.debug(F, `Returning embed: ${JSON.stringify(response, null, 2)}`);
return { embeds: [response] };
Expand Down Expand Up @@ -1952,6 +1963,20 @@ export async function modModal(
return;
}
await i.deferReply({ ephemeral: true });
try {
if (command === 'REPORT' || command === 'NOTE') {
await moderate(interaction, i);
const reportResponseEmbed = embedTemplate()
.setColor(command === 'REPORT' ? Colors.Yellow : Colors.Green)
.setTitle(command === 'REPORT' ? 'Your report was sent!' : 'Your note was added!')
.setDescription(command === 'REPORT' ? 'The moderators have received your report and will look into it. Thanks!' : `Your note was successfully added to ${target}'s thread.`);
await i.editReply({
embeds: [reportResponseEmbed],
});
}
} catch (err) {
log.info(F, `[modModal ModalSubmitInteraction]: ${err}`);
}
// const internalNote = i.fields.getTextInputValue('internalNote'); // eslint-disable-line

// // Only these commands actually have the description input, so only pull it if it exists
Expand Down Expand Up @@ -2043,7 +2068,9 @@ export async function modModal(
// log.error(F, `Error: ${err}`);
}
}
await i.editReply(await moderate(interaction, i));
if (!isNote(command) && !isReport(command)) {
await i.editReply(await moderate(interaction, i));
}
})
.catch(async err => {
// log.error(F, `Error: ${JSON.stringify(err as DiscordErrorData, null, 2)}`);
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 b53a229

Please sign in to comment.