Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(moderate): note/report replies, actions not working on nonguild users #830

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 50 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 @@ -1332,7 +1339,7 @@ export async function moderate(
}

let description = '';
if (!isNote(command) && !isReport(command)) {
if (command !== 'NOTE' && command !== 'REPORT') {
description = modalInt.fields.getTextInputValue('description');
}
let internalNote = modalInt.fields.getTextInputValue('internalNote');
Expand Down Expand Up @@ -1699,7 +1706,7 @@ export async function moderate(
> ${modalInt.fields.getTextInputValue('internalNote')}

Message sent to user:
> ${modalInt.fields.getTextInputValue('description')}`,
> ${command !== 'NOTE' && command !== 'REPORT' ? modalInt.fields.getTextInputValue('description') : ''}`,
inline: true,
},
);
Expand Down Expand Up @@ -1952,6 +1959,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 +2064,9 @@ export async function modModal(
// log.error(F, `Error: ${err}`);
}
}
await i.editReply(await moderate(interaction, i));
if (command !== 'REPORT' && command !== 'NOTE') {
await i.editReply(await moderate(interaction, i));
}
})
.catch(async err => {
// log.error(F, `Error: ${JSON.stringify(err as DiscordErrorData, null, 2)}`);
Expand Down
Loading