From 4cd95b68a7aa748eb58e300f6fab65984053900c Mon Sep 17 00:00:00 2001 From: iamshoXy Date: Sat, 9 Sep 2023 16:40:59 +0200 Subject: [PATCH] remove evidence --- .../src/plugins/ContextMenus/actions/ban.ts | 194 ++++++++---------- .../src/plugins/ContextMenus/actions/mute.ts | 24 +-- .../src/plugins/ContextMenus/actions/warn.ts | 181 ++++++++-------- 3 files changed, 181 insertions(+), 218 deletions(-) diff --git a/backend/src/plugins/ContextMenus/actions/ban.ts b/backend/src/plugins/ContextMenus/actions/ban.ts index 7798b64d..259622a6 100644 --- a/backend/src/plugins/ContextMenus/actions/ban.ts +++ b/backend/src/plugins/ContextMenus/actions/ban.ts @@ -1,11 +1,11 @@ import { - ActionRowBuilder, - ButtonInteraction, - ContextMenuCommandInteraction, - ModalBuilder, - ModalSubmitInteraction, - TextInputBuilder, - TextInputStyle, + ActionRowBuilder, + ButtonInteraction, + ContextMenuCommandInteraction, + ModalBuilder, + ModalSubmitInteraction, + TextInputBuilder, + TextInputStyle, } from "discord.js"; import humanizeDuration from "humanize-duration"; import { GuildPluginData } from "knub"; @@ -16,111 +16,99 @@ import { convertDelayStringToMS, renderUserUsername } from "../../../utils"; import { CaseArgs } from "../../Cases/types"; import { MODAL_TIMEOUT } from "../commands/ModMenuUserCtxCmd"; import { ContextMenuPluginType, ModMenuActionType } from "../types"; -import { updateAction } from "./update"; async function banAction( - pluginData: GuildPluginData, - duration: string | undefined, - reason: string | undefined, - evidence: string | undefined, - target: string, - interaction: ButtonInteraction | ContextMenuCommandInteraction, - submitInteraction: ModalSubmitInteraction, + pluginData: GuildPluginData, + duration: string | undefined, + reason: string | undefined, + target: string, + interaction: ButtonInteraction | ContextMenuCommandInteraction, + submitInteraction: ModalSubmitInteraction, ) { - const interactionToReply = interaction.isButton() ? interaction : submitInteraction; - const executingMember = await pluginData.guild.members.fetch(interaction.user.id); - const userCfg = await pluginData.config.getMatchingConfig({ - channelId: interaction.channelId, - member: executingMember, - }); - - const modactions = pluginData.getPlugin(ModActionsPlugin); - if (!userCfg.can_use || !(await modactions.hasBanPermission(executingMember, interaction.channelId))) { - await interactionToReply - .editReply({ content: "Cannot ban: insufficient permissions", embeds: [], components: [] }) - .catch((err) => logger.error(`Ban interaction reply failed: ${err}`)); - return; - } - - const targetMember = await pluginData.guild.members.fetch(target); - if (!canActOn(pluginData, executingMember, targetMember)) { - await interactionToReply - .editReply({ content: "Cannot ban: insufficient permissions", embeds: [], components: [] }) - .catch((err) => logger.error(`Ban interaction reply failed: ${err}`)); - return; - } - - const caseArgs: Partial = { - modId: executingMember.id, - }; - - const durationMs = duration ? convertDelayStringToMS(duration)! : undefined; - const result = await modactions.banUserId(target, reason, { caseArgs }, durationMs); - if (result.status === "failed") { - await interactionToReply - .editReply({ content: "Error: Failed to ban user", embeds: [], components: [] }) - .catch((err) => logger.error(`Ban interaction reply failed: ${err}`)); - return; - } - - const userName = renderUserUsername(targetMember.user); - const messageResultText = result.notifyResult.text ? ` (${result.notifyResult.text})` : ""; - const banMessage = `Banned **${userName}** ${durationMs ? `for ${humanizeDuration(durationMs)}` : "indefinitely" - } (Case #${result.case.case_number})${messageResultText}`; - - if (evidence) { - await updateAction(pluginData, executingMember, result.case, evidence); - } + const interactionToReply = interaction.isButton() ? interaction : submitInteraction; + const executingMember = await pluginData.guild.members.fetch(interaction.user.id); + const userCfg = await pluginData.config.getMatchingConfig({ + channelId: interaction.channelId, + member: executingMember, + }); + const modactions = pluginData.getPlugin(ModActionsPlugin); + if (!userCfg.can_use || !(await modactions.hasBanPermission(executingMember, interaction.channelId))) { await interactionToReply - .editReply({ content: banMessage, embeds: [], components: [] }) - .catch((err) => logger.error(`Ban interaction reply failed: ${err}`)); + .editReply({ content: "Cannot ban: insufficient permissions", embeds: [], components: [] }) + .catch((err) => logger.error(`Ban interaction reply failed: ${err}`)); + return; + } + + const targetMember = await pluginData.guild.members.fetch(target); + if (!canActOn(pluginData, executingMember, targetMember)) { + await interactionToReply + .editReply({ content: "Cannot ban: insufficient permissions", embeds: [], components: [] }) + .catch((err) => logger.error(`Ban interaction reply failed: ${err}`)); + return; + } + + const caseArgs: Partial = { + modId: executingMember.id, + }; + + const durationMs = duration ? convertDelayStringToMS(duration)! : undefined; + const result = await modactions.banUserId(target, reason, { caseArgs }, durationMs); + if (result.status === "failed") { + await interactionToReply + .editReply({ content: "Error: Failed to ban user", embeds: [], components: [] }) + .catch((err) => logger.error(`Ban interaction reply failed: ${err}`)); + return; + } + + const userName = renderUserUsername(targetMember.user); + const messageResultText = result.notifyResult.text ? ` (${result.notifyResult.text})` : ""; + const banMessage = `Banned **${userName}** ${ + durationMs ? `for ${humanizeDuration(durationMs)}` : "indefinitely" + } (Case #${result.case.case_number})${messageResultText}`; + + await interactionToReply + .editReply({ content: banMessage, embeds: [], components: [] }) + .catch((err) => logger.error(`Ban interaction reply failed: ${err}`)); } export async function launchBanActionModal( - pluginData: GuildPluginData, - interaction: ButtonInteraction | ContextMenuCommandInteraction, - target: string, + pluginData: GuildPluginData, + interaction: ButtonInteraction | ContextMenuCommandInteraction, + target: string, ) { - const modalId = `${ModMenuActionType.BAN}:${interaction.id}`; - const modal = new ModalBuilder().setCustomId(modalId).setTitle("Ban"); - const durationIn = new TextInputBuilder() - .setCustomId("duration") - .setLabel("Duration (Optional)") - .setRequired(false) - .setStyle(TextInputStyle.Short); - const reasonIn = new TextInputBuilder() - .setCustomId("reason") - .setLabel("Reason (Optional)") - .setRequired(false) - .setStyle(TextInputStyle.Paragraph); - const evidenceIn = new TextInputBuilder() - .setCustomId("evidence") - .setLabel("Evidence (Optional)") - .setRequired(false) - .setStyle(TextInputStyle.Paragraph); - const durationRow = new ActionRowBuilder().addComponents(durationIn); - const reasonRow = new ActionRowBuilder().addComponents(reasonIn); - const evidenceRow = new ActionRowBuilder().addComponents(evidenceIn); - modal.addComponents(durationRow, reasonRow, evidenceRow); + const modalId = `${ModMenuActionType.BAN}:${interaction.id}`; + const modal = new ModalBuilder().setCustomId(modalId).setTitle("Ban"); + const durationIn = new TextInputBuilder() + .setCustomId("duration") + .setLabel("Duration (Optional)") + .setRequired(false) + .setStyle(TextInputStyle.Short); + const reasonIn = new TextInputBuilder() + .setCustomId("reason") + .setLabel("Reason (Optional)") + .setRequired(false) + .setStyle(TextInputStyle.Paragraph); + const durationRow = new ActionRowBuilder().addComponents(durationIn); + const reasonRow = new ActionRowBuilder().addComponents(reasonIn); + modal.addComponents(durationRow, reasonRow); - await interaction.showModal(modal); - await interaction - .awaitModalSubmit({ time: MODAL_TIMEOUT, filter: (i) => i.customId == modalId }) - .then(async (submitted) => { - if (interaction.isButton()) { - await submitted.deferUpdate().catch((err) => logger.error(`Ban interaction defer failed: ${err}`)); - } else if (interaction.isContextMenuCommand()) { - await submitted - .deferReply({ ephemeral: true }) - .catch((err) => logger.error(`Ban interaction defer failed: ${err}`)); - } + await interaction.showModal(modal); + await interaction + .awaitModalSubmit({ time: MODAL_TIMEOUT, filter: (i) => i.customId == modalId }) + .then(async (submitted) => { + if (interaction.isButton()) { + await submitted.deferUpdate().catch((err) => logger.error(`Ban interaction defer failed: ${err}`)); + } else if (interaction.isContextMenuCommand()) { + await submitted + .deferReply({ ephemeral: true }) + .catch((err) => logger.error(`Ban interaction defer failed: ${err}`)); + } - const duration = submitted.fields.getTextInputValue("duration"); - const reason = submitted.fields.getTextInputValue("reason"); - const evidence = submitted.fields.getTextInputValue("evidence"); + const duration = submitted.fields.getTextInputValue("duration"); + const reason = submitted.fields.getTextInputValue("reason"); - await banAction(pluginData, duration, reason, evidence, target, interaction, submitted); - }) - .catch((err) => logger.error(`Ban modal interaction failed: ${err}`)); -} \ No newline at end of file + await banAction(pluginData, duration, reason, target, interaction, submitted); + }) + .catch((err) => logger.error(`Ban modal interaction failed: ${err}`)); +} diff --git a/backend/src/plugins/ContextMenus/actions/mute.ts b/backend/src/plugins/ContextMenus/actions/mute.ts index b7ef9b6e..b0ea8776 100644 --- a/backend/src/plugins/ContextMenus/actions/mute.ts +++ b/backend/src/plugins/ContextMenus/actions/mute.ts @@ -19,13 +19,11 @@ import { LogsPlugin } from "../../Logs/LogsPlugin"; import { MutesPlugin } from "../../Mutes/MutesPlugin"; import { MODAL_TIMEOUT } from "../commands/ModMenuUserCtxCmd"; import { ContextMenuPluginType, ModMenuActionType } from "../types"; -import { updateAction } from "./update"; async function muteAction( pluginData: GuildPluginData, duration: string | undefined, reason: string | undefined, - evidence: string | undefined, target: string, interaction: ButtonInteraction | ContextMenuCommandInteraction, submitInteraction: ModalSubmitInteraction, @@ -71,12 +69,9 @@ async function muteAction( const result = await mutes.muteUser(target, durationMs, reason, { caseArgs }); const messageResultText = result.notifyResult.text ? ` (${result.notifyResult.text})` : ""; - const muteMessage = `Muted **${result.case.user_name}** ${durationMs ? `for ${humanizeDuration(durationMs)}` : "indefinitely" - } (Case #${result.case.case_number})${messageResultText}`; - - if (evidence) { - await updateAction(pluginData, executingMember, result.case, evidence); - } + const muteMessage = `Muted **${result.case.user_name}** ${ + durationMs ? `for ${humanizeDuration(durationMs)}` : "indefinitely" + } (Case #${result.case.case_number})${messageResultText}`; await interactionToReply .editReply({ content: muteMessage, embeds: [], components: [] }) @@ -117,15 +112,9 @@ export async function launchMuteActionModal( .setLabel("Reason (Optional)") .setRequired(false) .setStyle(TextInputStyle.Paragraph); - const evidenceIn = new TextInputBuilder() - .setCustomId("evidence") - .setLabel("Evidence (Optional)") - .setRequired(false) - .setStyle(TextInputStyle.Paragraph); const durationRow = new ActionRowBuilder().addComponents(durationIn); const reasonRow = new ActionRowBuilder().addComponents(reasonIn); - const evidenceRow = new ActionRowBuilder().addComponents(evidenceIn); - modal.addComponents(durationRow, reasonRow, evidenceRow); + modal.addComponents(durationRow, reasonRow); await interaction.showModal(modal); await interaction @@ -141,9 +130,8 @@ export async function launchMuteActionModal( const duration = submitted.fields.getTextInputValue("duration"); const reason = submitted.fields.getTextInputValue("reason"); - const evidence = submitted.fields.getTextInputValue("evidence"); - await muteAction(pluginData, duration, reason, evidence, target, interaction, submitted); + await muteAction(pluginData, duration, reason, target, interaction, submitted); }) .catch((err) => logger.error(`Mute modal interaction failed: ${err}`)); -} \ No newline at end of file +} diff --git a/backend/src/plugins/ContextMenus/actions/warn.ts b/backend/src/plugins/ContextMenus/actions/warn.ts index c2971035..d8eba234 100644 --- a/backend/src/plugins/ContextMenus/actions/warn.ts +++ b/backend/src/plugins/ContextMenus/actions/warn.ts @@ -1,11 +1,11 @@ import { - ActionRowBuilder, - ButtonInteraction, - ContextMenuCommandInteraction, - ModalBuilder, - ModalSubmitInteraction, - TextInputBuilder, - TextInputStyle, + ActionRowBuilder, + ButtonInteraction, + ContextMenuCommandInteraction, + ModalBuilder, + ModalSubmitInteraction, + TextInputBuilder, + TextInputStyle, } from "discord.js"; import { GuildPluginData } from "knub"; import { canActOn } from "src/pluginUtils"; @@ -15,105 +15,92 @@ import { renderUserUsername } from "../../../utils"; import { CaseArgs } from "../../Cases/types"; import { MODAL_TIMEOUT } from "../commands/ModMenuUserCtxCmd"; import { ContextMenuPluginType, ModMenuActionType } from "../types"; -import { updateAction } from "./update"; async function warnAction( - pluginData: GuildPluginData, - reason: string, - evidence: string | undefined, - target: string, - interaction: ButtonInteraction | ContextMenuCommandInteraction, - submitInteraction: ModalSubmitInteraction, + pluginData: GuildPluginData, + reason: string, + target: string, + interaction: ButtonInteraction | ContextMenuCommandInteraction, + submitInteraction: ModalSubmitInteraction, ) { - const interactionToReply = interaction.isButton() ? interaction : submitInteraction; - const executingMember = await pluginData.guild.members.fetch(interaction.user.id); - const userCfg = await pluginData.config.getMatchingConfig({ - channelId: interaction.channelId, - member: executingMember, - }); - - const modactions = pluginData.getPlugin(ModActionsPlugin); - if (!userCfg.can_use || !(await modactions.hasWarnPermission(executingMember, interaction.channelId))) { - await interactionToReply - .editReply({ - content: "Cannot warn: insufficient permissions", - embeds: [], - components: [], - }) - .catch((err) => logger.error(`Warn interaction reply failed: ${err}`)); - return; - } - - const targetMember = await pluginData.guild.members.fetch(target); - if (!canActOn(pluginData, executingMember, targetMember)) { - await interactionToReply - .editReply({ - content: "Cannot warn: insufficient permissions", - embeds: [], - components: [], - }) - .catch((err) => logger.error(`Warn interaction reply failed: ${err}`)); - return; - } - - const caseArgs: Partial = { - modId: executingMember.id, - }; - - const result = await modactions.warnMember(targetMember, reason, { caseArgs }); - if (result.status === "failed") { - await interactionToReply - .editReply({ content: "Error: Failed to warn user", embeds: [], components: [] }) - .catch((err) => logger.error(`Warn interaction reply failed: ${err}`)); - return; - } - - const userName = renderUserUsername(targetMember.user); - const messageResultText = result.notifyResult.text ? ` (${result.notifyResult.text})` : ""; - const muteMessage = `Warned **${userName}** (Case #${result.case.case_number})${messageResultText}`; - - if (evidence) { - await updateAction(pluginData, executingMember, result.case, evidence); - } + const interactionToReply = interaction.isButton() ? interaction : submitInteraction; + const executingMember = await pluginData.guild.members.fetch(interaction.user.id); + const userCfg = await pluginData.config.getMatchingConfig({ + channelId: interaction.channelId, + member: executingMember, + }); + const modactions = pluginData.getPlugin(ModActionsPlugin); + if (!userCfg.can_use || !(await modactions.hasWarnPermission(executingMember, interaction.channelId))) { await interactionToReply - .editReply({ content: muteMessage, embeds: [], components: [] }) - .catch((err) => logger.error(`Warn interaction reply failed: ${err}`)); + .editReply({ + content: "Cannot warn: insufficient permissions", + embeds: [], + components: [], + }) + .catch((err) => logger.error(`Warn interaction reply failed: ${err}`)); + return; + } + + const targetMember = await pluginData.guild.members.fetch(target); + if (!canActOn(pluginData, executingMember, targetMember)) { + await interactionToReply + .editReply({ + content: "Cannot warn: insufficient permissions", + embeds: [], + components: [], + }) + .catch((err) => logger.error(`Warn interaction reply failed: ${err}`)); + return; + } + + const caseArgs: Partial = { + modId: executingMember.id, + }; + + const result = await modactions.warnMember(targetMember, reason, { caseArgs }); + if (result.status === "failed") { + await interactionToReply + .editReply({ content: "Error: Failed to warn user", embeds: [], components: [] }) + .catch((err) => logger.error(`Warn interaction reply failed: ${err}`)); + return; + } + + const userName = renderUserUsername(targetMember.user); + const messageResultText = result.notifyResult.text ? ` (${result.notifyResult.text})` : ""; + const muteMessage = `Warned **${userName}** (Case #${result.case.case_number})${messageResultText}`; + + await interactionToReply + .editReply({ content: muteMessage, embeds: [], components: [] }) + .catch((err) => logger.error(`Warn interaction reply failed: ${err}`)); } export async function launchWarnActionModal( - pluginData: GuildPluginData, - interaction: ButtonInteraction | ContextMenuCommandInteraction, - target: string, + pluginData: GuildPluginData, + interaction: ButtonInteraction | ContextMenuCommandInteraction, + target: string, ) { - const modalId = `${ModMenuActionType.WARN}:${interaction.id}`; - const modal = new ModalBuilder().setCustomId(modalId).setTitle("Warn"); - const reasonIn = new TextInputBuilder().setCustomId("reason").setLabel("Reason").setStyle(TextInputStyle.Paragraph); - const evidenceIn = new TextInputBuilder() - .setCustomId("evidence") - .setLabel("Evidence (Optional)") - .setRequired(false) - .setStyle(TextInputStyle.Paragraph); - const reasonRow = new ActionRowBuilder().addComponents(reasonIn); - const evidenceRow = new ActionRowBuilder().addComponents(evidenceIn); - modal.addComponents(reasonRow, evidenceRow); + const modalId = `${ModMenuActionType.WARN}:${interaction.id}`; + const modal = new ModalBuilder().setCustomId(modalId).setTitle("Warn"); + const reasonIn = new TextInputBuilder().setCustomId("reason").setLabel("Reason").setStyle(TextInputStyle.Paragraph); + const reasonRow = new ActionRowBuilder().addComponents(reasonIn); + modal.addComponents(reasonRow); - await interaction.showModal(modal); - await interaction - .awaitModalSubmit({ time: MODAL_TIMEOUT, filter: (i) => i.customId == modalId }) - .then(async (submitted) => { - if (interaction.isButton()) { - await submitted.deferUpdate().catch((err) => logger.error(`Warn interaction defer failed: ${err}`)); - } else if (interaction.isContextMenuCommand()) { - await submitted - .deferReply({ ephemeral: true }) - .catch((err) => logger.error(`Warn interaction defer failed: ${err}`)); - } + await interaction.showModal(modal); + await interaction + .awaitModalSubmit({ time: MODAL_TIMEOUT, filter: (i) => i.customId == modalId }) + .then(async (submitted) => { + if (interaction.isButton()) { + await submitted.deferUpdate().catch((err) => logger.error(`Warn interaction defer failed: ${err}`)); + } else if (interaction.isContextMenuCommand()) { + await submitted + .deferReply({ ephemeral: true }) + .catch((err) => logger.error(`Warn interaction defer failed: ${err}`)); + } - const reason = submitted.fields.getTextInputValue("reason"); - const evidence = submitted.fields.getTextInputValue("evidence"); + const reason = submitted.fields.getTextInputValue("reason"); - await warnAction(pluginData, reason, evidence, target, interaction, submitted); - }) - .catch((err) => logger.error(`Warn modal interaction failed: ${err}`)); -} \ No newline at end of file + await warnAction(pluginData, reason, target, interaction, submitted); + }) + .catch((err) => logger.error(`Warn modal interaction failed: ${err}`)); +}