diff --git a/backend/src/plugins/ContextMenus/actions/ban.ts b/backend/src/plugins/ContextMenus/actions/ban.ts index 259622a6..f2b391cc 100644 --- a/backend/src/plugins/ContextMenus/actions/ban.ts +++ b/backend/src/plugins/ContextMenus/actions/ban.ts @@ -16,11 +16,13 @@ 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, @@ -67,6 +69,10 @@ async function banAction( durationMs ? `for ${humanizeDuration(durationMs)}` : "indefinitely" } (Case #${result.case.case_number})${messageResultText}`; + if (evidence) { + await updateAction(pluginData, executingMember, result.case, evidence); + } + await interactionToReply .editReply({ content: banMessage, embeds: [], components: [] }) .catch((err) => logger.error(`Ban interaction reply failed: ${err}`)); @@ -89,9 +95,15 @@ export async function launchBanActionModal( .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); - modal.addComponents(durationRow, reasonRow); + const evidenceRow = new ActionRowBuilder().addComponents(evidenceIn); + modal.addComponents(durationRow, reasonRow, evidenceRow); await interaction.showModal(modal); await interaction @@ -107,8 +119,9 @@ export async function launchBanActionModal( const duration = submitted.fields.getTextInputValue("duration"); const reason = submitted.fields.getTextInputValue("reason"); + const evidence = submitted.fields.getTextInputValue("evidence"); - await banAction(pluginData, duration, reason, target, interaction, submitted); + await banAction(pluginData, duration, reason, evidence, 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 b0ea8776..58457cb0 100644 --- a/backend/src/plugins/ContextMenus/actions/mute.ts +++ b/backend/src/plugins/ContextMenus/actions/mute.ts @@ -19,11 +19,13 @@ 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, @@ -73,6 +75,10 @@ async function muteAction( durationMs ? `for ${humanizeDuration(durationMs)}` : "indefinitely" } (Case #${result.case.case_number})${messageResultText}`; + if (evidence) { + await updateAction(pluginData, executingMember, result.case, evidence); + } + await interactionToReply .editReply({ content: muteMessage, embeds: [], components: [] }) .catch((err) => logger.error(`Mute interaction reply failed: ${err}`)); @@ -112,9 +118,15 @@ 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); - modal.addComponents(durationRow, reasonRow); + const evidenceRow = new ActionRowBuilder().addComponents(evidenceIn); + modal.addComponents(durationRow, reasonRow, evidenceRow); await interaction.showModal(modal); await interaction @@ -130,8 +142,9 @@ 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, target, interaction, submitted); + await muteAction(pluginData, duration, reason, evidence, target, interaction, submitted); }) .catch((err) => logger.error(`Mute modal interaction failed: ${err}`)); } diff --git a/backend/src/plugins/ContextMenus/actions/update.ts b/backend/src/plugins/ContextMenus/actions/update.ts new file mode 100644 index 00000000..3365f293 --- /dev/null +++ b/backend/src/plugins/ContextMenus/actions/update.ts @@ -0,0 +1,28 @@ +import { GuildMember } from "discord.js"; +import { GuildPluginData } from "knub"; +import { CaseTypes } from "../../../data/CaseTypes"; +import { Case } from "../../../data/entities/Case"; +import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin"; +import { LogsPlugin } from "../../../plugins/Logs/LogsPlugin"; +import { ContextMenuPluginType } from "../types"; + +export async function updateAction( + pluginData: GuildPluginData, + executingMember: GuildMember, + theCase: Case, + value: string, +) { + const casesPlugin = pluginData.getPlugin(CasesPlugin); + await casesPlugin.createCaseNote({ + caseId: theCase.case_number, + modId: executingMember.id, + body: value, + }); + + pluginData.getPlugin(LogsPlugin).logCaseUpdate({ + mod: executingMember.user, + caseNumber: theCase.case_number, + caseType: CaseTypes[theCase.type], + note: value, + }); +} diff --git a/backend/src/plugins/ContextMenus/actions/warn.ts b/backend/src/plugins/ContextMenus/actions/warn.ts index d8eba234..6fbd40f3 100644 --- a/backend/src/plugins/ContextMenus/actions/warn.ts +++ b/backend/src/plugins/ContextMenus/actions/warn.ts @@ -15,10 +15,12 @@ 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, @@ -70,6 +72,10 @@ async function warnAction( 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); + } + await interactionToReply .editReply({ content: muteMessage, embeds: [], components: [] }) .catch((err) => logger.error(`Warn interaction reply failed: ${err}`)); @@ -83,8 +89,14 @@ export async function launchWarnActionModal( 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); - modal.addComponents(reasonRow); + const evidenceRow = new ActionRowBuilder().addComponents(evidenceIn); + modal.addComponents(reasonRow, evidenceRow); await interaction.showModal(modal); await interaction @@ -99,8 +111,9 @@ export async function launchWarnActionModal( } const reason = submitted.fields.getTextInputValue("reason"); + const evidence = submitted.fields.getTextInputValue("evidence"); - await warnAction(pluginData, reason, target, interaction, submitted); + await warnAction(pluginData, reason, evidence, target, interaction, submitted); }) .catch((err) => logger.error(`Warn modal interaction failed: ${err}`)); }