mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
feat(ContextMenus): add new field to modals for case evidence
This commit is contained in:
parent
26bf9363f9
commit
6689f91a6a
4 changed files with 73 additions and 6 deletions
|
@ -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<ContextMenuPluginType>,
|
||||
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<TextInputBuilder>().addComponents(durationIn);
|
||||
const reasonRow = new ActionRowBuilder<TextInputBuilder>().addComponents(reasonIn);
|
||||
modal.addComponents(durationRow, reasonRow);
|
||||
const evidenceRow = new ActionRowBuilder<TextInputBuilder>().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}`));
|
||||
}
|
||||
|
|
|
@ -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<ContextMenuPluginType>,
|
||||
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<TextInputBuilder>().addComponents(durationIn);
|
||||
const reasonRow = new ActionRowBuilder<TextInputBuilder>().addComponents(reasonIn);
|
||||
modal.addComponents(durationRow, reasonRow);
|
||||
const evidenceRow = new ActionRowBuilder<TextInputBuilder>().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}`));
|
||||
}
|
||||
|
|
28
backend/src/plugins/ContextMenus/actions/update.ts
Normal file
28
backend/src/plugins/ContextMenus/actions/update.ts
Normal file
|
@ -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<ContextMenuPluginType>,
|
||||
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,
|
||||
});
|
||||
}
|
|
@ -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<ContextMenuPluginType>,
|
||||
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<TextInputBuilder>().addComponents(reasonIn);
|
||||
modal.addComponents(reasonRow);
|
||||
const evidenceRow = new ActionRowBuilder<TextInputBuilder>().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}`));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue