3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-17 07:05:03 +00:00

remove evidence

This commit is contained in:
iamshoXy 2023-09-09 16:40:59 +02:00
parent e93f017e8a
commit 4cd95b68a7
3 changed files with 181 additions and 218 deletions

View file

@ -1,11 +1,11 @@
import { import {
ActionRowBuilder, ActionRowBuilder,
ButtonInteraction, ButtonInteraction,
ContextMenuCommandInteraction, ContextMenuCommandInteraction,
ModalBuilder, ModalBuilder,
ModalSubmitInteraction, ModalSubmitInteraction,
TextInputBuilder, TextInputBuilder,
TextInputStyle, TextInputStyle,
} from "discord.js"; } from "discord.js";
import humanizeDuration from "humanize-duration"; import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
@ -16,111 +16,99 @@ import { convertDelayStringToMS, renderUserUsername } from "../../../utils";
import { CaseArgs } from "../../Cases/types"; import { CaseArgs } from "../../Cases/types";
import { MODAL_TIMEOUT } from "../commands/ModMenuUserCtxCmd"; import { MODAL_TIMEOUT } from "../commands/ModMenuUserCtxCmd";
import { ContextMenuPluginType, ModMenuActionType } from "../types"; import { ContextMenuPluginType, ModMenuActionType } from "../types";
import { updateAction } from "./update";
async function banAction( async function banAction(
pluginData: GuildPluginData<ContextMenuPluginType>, pluginData: GuildPluginData<ContextMenuPluginType>,
duration: string | undefined, duration: string | undefined,
reason: string | undefined, reason: string | undefined,
evidence: string | undefined, target: string,
target: string, interaction: ButtonInteraction | ContextMenuCommandInteraction,
interaction: ButtonInteraction | ContextMenuCommandInteraction, submitInteraction: ModalSubmitInteraction,
submitInteraction: ModalSubmitInteraction,
) { ) {
const interactionToReply = interaction.isButton() ? interaction : submitInteraction; const interactionToReply = interaction.isButton() ? interaction : submitInteraction;
const executingMember = await pluginData.guild.members.fetch(interaction.user.id); const executingMember = await pluginData.guild.members.fetch(interaction.user.id);
const userCfg = await pluginData.config.getMatchingConfig({ const userCfg = await pluginData.config.getMatchingConfig({
channelId: interaction.channelId, channelId: interaction.channelId,
member: executingMember, 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<CaseArgs> = {
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 modactions = pluginData.getPlugin(ModActionsPlugin);
if (!userCfg.can_use || !(await modactions.hasBanPermission(executingMember, interaction.channelId))) {
await interactionToReply await interactionToReply
.editReply({ content: banMessage, embeds: [], components: [] }) .editReply({ content: "Cannot ban: insufficient permissions", embeds: [], components: [] })
.catch((err) => logger.error(`Ban interaction reply failed: ${err}`)); .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<CaseArgs> = {
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( export async function launchBanActionModal(
pluginData: GuildPluginData<ContextMenuPluginType>, pluginData: GuildPluginData<ContextMenuPluginType>,
interaction: ButtonInteraction | ContextMenuCommandInteraction, interaction: ButtonInteraction | ContextMenuCommandInteraction,
target: string, target: string,
) { ) {
const modalId = `${ModMenuActionType.BAN}:${interaction.id}`; const modalId = `${ModMenuActionType.BAN}:${interaction.id}`;
const modal = new ModalBuilder().setCustomId(modalId).setTitle("Ban"); const modal = new ModalBuilder().setCustomId(modalId).setTitle("Ban");
const durationIn = new TextInputBuilder() const durationIn = new TextInputBuilder()
.setCustomId("duration") .setCustomId("duration")
.setLabel("Duration (Optional)") .setLabel("Duration (Optional)")
.setRequired(false) .setRequired(false)
.setStyle(TextInputStyle.Short); .setStyle(TextInputStyle.Short);
const reasonIn = new TextInputBuilder() const reasonIn = new TextInputBuilder()
.setCustomId("reason") .setCustomId("reason")
.setLabel("Reason (Optional)") .setLabel("Reason (Optional)")
.setRequired(false) .setRequired(false)
.setStyle(TextInputStyle.Paragraph); .setStyle(TextInputStyle.Paragraph);
const evidenceIn = new TextInputBuilder() const durationRow = new ActionRowBuilder<TextInputBuilder>().addComponents(durationIn);
.setCustomId("evidence") const reasonRow = new ActionRowBuilder<TextInputBuilder>().addComponents(reasonIn);
.setLabel("Evidence (Optional)") modal.addComponents(durationRow, reasonRow);
.setRequired(false)
.setStyle(TextInputStyle.Paragraph);
const durationRow = new ActionRowBuilder<TextInputBuilder>().addComponents(durationIn);
const reasonRow = new ActionRowBuilder<TextInputBuilder>().addComponents(reasonIn);
const evidenceRow = new ActionRowBuilder<TextInputBuilder>().addComponents(evidenceIn);
modal.addComponents(durationRow, reasonRow, evidenceRow);
await interaction.showModal(modal); await interaction.showModal(modal);
await interaction await interaction
.awaitModalSubmit({ time: MODAL_TIMEOUT, filter: (i) => i.customId == modalId }) .awaitModalSubmit({ time: MODAL_TIMEOUT, filter: (i) => i.customId == modalId })
.then(async (submitted) => { .then(async (submitted) => {
if (interaction.isButton()) { if (interaction.isButton()) {
await submitted.deferUpdate().catch((err) => logger.error(`Ban interaction defer failed: ${err}`)); await submitted.deferUpdate().catch((err) => logger.error(`Ban interaction defer failed: ${err}`));
} else if (interaction.isContextMenuCommand()) { } else if (interaction.isContextMenuCommand()) {
await submitted await submitted
.deferReply({ ephemeral: true }) .deferReply({ ephemeral: true })
.catch((err) => logger.error(`Ban interaction defer failed: ${err}`)); .catch((err) => logger.error(`Ban interaction defer failed: ${err}`));
} }
const duration = submitted.fields.getTextInputValue("duration"); const duration = submitted.fields.getTextInputValue("duration");
const reason = submitted.fields.getTextInputValue("reason"); const reason = submitted.fields.getTextInputValue("reason");
const evidence = submitted.fields.getTextInputValue("evidence");
await banAction(pluginData, duration, reason, evidence, target, interaction, submitted); await banAction(pluginData, duration, reason, target, interaction, submitted);
}) })
.catch((err) => logger.error(`Ban modal interaction failed: ${err}`)); .catch((err) => logger.error(`Ban modal interaction failed: ${err}`));
} }

View file

@ -19,13 +19,11 @@ import { LogsPlugin } from "../../Logs/LogsPlugin";
import { MutesPlugin } from "../../Mutes/MutesPlugin"; import { MutesPlugin } from "../../Mutes/MutesPlugin";
import { MODAL_TIMEOUT } from "../commands/ModMenuUserCtxCmd"; import { MODAL_TIMEOUT } from "../commands/ModMenuUserCtxCmd";
import { ContextMenuPluginType, ModMenuActionType } from "../types"; import { ContextMenuPluginType, ModMenuActionType } from "../types";
import { updateAction } from "./update";
async function muteAction( async function muteAction(
pluginData: GuildPluginData<ContextMenuPluginType>, pluginData: GuildPluginData<ContextMenuPluginType>,
duration: string | undefined, duration: string | undefined,
reason: string | undefined, reason: string | undefined,
evidence: string | undefined,
target: string, target: string,
interaction: ButtonInteraction | ContextMenuCommandInteraction, interaction: ButtonInteraction | ContextMenuCommandInteraction,
submitInteraction: ModalSubmitInteraction, submitInteraction: ModalSubmitInteraction,
@ -71,12 +69,9 @@ async function muteAction(
const result = await mutes.muteUser(target, durationMs, reason, { caseArgs }); const result = await mutes.muteUser(target, durationMs, reason, { caseArgs });
const messageResultText = result.notifyResult.text ? ` (${result.notifyResult.text})` : ""; const messageResultText = result.notifyResult.text ? ` (${result.notifyResult.text})` : "";
const muteMessage = `Muted **${result.case.user_name}** ${durationMs ? `for ${humanizeDuration(durationMs)}` : "indefinitely" const muteMessage = `Muted **${result.case.user_name}** ${
} (Case #${result.case.case_number})${messageResultText}`; durationMs ? `for ${humanizeDuration(durationMs)}` : "indefinitely"
} (Case #${result.case.case_number})${messageResultText}`;
if (evidence) {
await updateAction(pluginData, executingMember, result.case, evidence);
}
await interactionToReply await interactionToReply
.editReply({ content: muteMessage, embeds: [], components: [] }) .editReply({ content: muteMessage, embeds: [], components: [] })
@ -117,15 +112,9 @@ export async function launchMuteActionModal(
.setLabel("Reason (Optional)") .setLabel("Reason (Optional)")
.setRequired(false) .setRequired(false)
.setStyle(TextInputStyle.Paragraph); .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 durationRow = new ActionRowBuilder<TextInputBuilder>().addComponents(durationIn);
const reasonRow = new ActionRowBuilder<TextInputBuilder>().addComponents(reasonIn); const reasonRow = new ActionRowBuilder<TextInputBuilder>().addComponents(reasonIn);
const evidenceRow = new ActionRowBuilder<TextInputBuilder>().addComponents(evidenceIn); modal.addComponents(durationRow, reasonRow);
modal.addComponents(durationRow, reasonRow, evidenceRow);
await interaction.showModal(modal); await interaction.showModal(modal);
await interaction await interaction
@ -141,9 +130,8 @@ export async function launchMuteActionModal(
const duration = submitted.fields.getTextInputValue("duration"); const duration = submitted.fields.getTextInputValue("duration");
const reason = submitted.fields.getTextInputValue("reason"); 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}`)); .catch((err) => logger.error(`Mute modal interaction failed: ${err}`));
} }

View file

@ -1,11 +1,11 @@
import { import {
ActionRowBuilder, ActionRowBuilder,
ButtonInteraction, ButtonInteraction,
ContextMenuCommandInteraction, ContextMenuCommandInteraction,
ModalBuilder, ModalBuilder,
ModalSubmitInteraction, ModalSubmitInteraction,
TextInputBuilder, TextInputBuilder,
TextInputStyle, TextInputStyle,
} from "discord.js"; } from "discord.js";
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { canActOn } from "src/pluginUtils"; import { canActOn } from "src/pluginUtils";
@ -15,105 +15,92 @@ import { renderUserUsername } from "../../../utils";
import { CaseArgs } from "../../Cases/types"; import { CaseArgs } from "../../Cases/types";
import { MODAL_TIMEOUT } from "../commands/ModMenuUserCtxCmd"; import { MODAL_TIMEOUT } from "../commands/ModMenuUserCtxCmd";
import { ContextMenuPluginType, ModMenuActionType } from "../types"; import { ContextMenuPluginType, ModMenuActionType } from "../types";
import { updateAction } from "./update";
async function warnAction( async function warnAction(
pluginData: GuildPluginData<ContextMenuPluginType>, pluginData: GuildPluginData<ContextMenuPluginType>,
reason: string, reason: string,
evidence: string | undefined, target: string,
target: string, interaction: ButtonInteraction | ContextMenuCommandInteraction,
interaction: ButtonInteraction | ContextMenuCommandInteraction, submitInteraction: ModalSubmitInteraction,
submitInteraction: ModalSubmitInteraction,
) { ) {
const interactionToReply = interaction.isButton() ? interaction : submitInteraction; const interactionToReply = interaction.isButton() ? interaction : submitInteraction;
const executingMember = await pluginData.guild.members.fetch(interaction.user.id); const executingMember = await pluginData.guild.members.fetch(interaction.user.id);
const userCfg = await pluginData.config.getMatchingConfig({ const userCfg = await pluginData.config.getMatchingConfig({
channelId: interaction.channelId, channelId: interaction.channelId,
member: executingMember, 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<CaseArgs> = {
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 modactions = pluginData.getPlugin(ModActionsPlugin);
if (!userCfg.can_use || !(await modactions.hasWarnPermission(executingMember, interaction.channelId))) {
await interactionToReply await interactionToReply
.editReply({ content: muteMessage, embeds: [], components: [] }) .editReply({
.catch((err) => logger.error(`Warn interaction reply failed: ${err}`)); 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<CaseArgs> = {
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( export async function launchWarnActionModal(
pluginData: GuildPluginData<ContextMenuPluginType>, pluginData: GuildPluginData<ContextMenuPluginType>,
interaction: ButtonInteraction | ContextMenuCommandInteraction, interaction: ButtonInteraction | ContextMenuCommandInteraction,
target: string, target: string,
) { ) {
const modalId = `${ModMenuActionType.WARN}:${interaction.id}`; const modalId = `${ModMenuActionType.WARN}:${interaction.id}`;
const modal = new ModalBuilder().setCustomId(modalId).setTitle("Warn"); const modal = new ModalBuilder().setCustomId(modalId).setTitle("Warn");
const reasonIn = new TextInputBuilder().setCustomId("reason").setLabel("Reason").setStyle(TextInputStyle.Paragraph); const reasonIn = new TextInputBuilder().setCustomId("reason").setLabel("Reason").setStyle(TextInputStyle.Paragraph);
const evidenceIn = new TextInputBuilder() const reasonRow = new ActionRowBuilder<TextInputBuilder>().addComponents(reasonIn);
.setCustomId("evidence") modal.addComponents(reasonRow);
.setLabel("Evidence (Optional)")
.setRequired(false)
.setStyle(TextInputStyle.Paragraph);
const reasonRow = new ActionRowBuilder<TextInputBuilder>().addComponents(reasonIn);
const evidenceRow = new ActionRowBuilder<TextInputBuilder>().addComponents(evidenceIn);
modal.addComponents(reasonRow, evidenceRow);
await interaction.showModal(modal); await interaction.showModal(modal);
await interaction await interaction
.awaitModalSubmit({ time: MODAL_TIMEOUT, filter: (i) => i.customId == modalId }) .awaitModalSubmit({ time: MODAL_TIMEOUT, filter: (i) => i.customId == modalId })
.then(async (submitted) => { .then(async (submitted) => {
if (interaction.isButton()) { if (interaction.isButton()) {
await submitted.deferUpdate().catch((err) => logger.error(`Warn interaction defer failed: ${err}`)); await submitted.deferUpdate().catch((err) => logger.error(`Warn interaction defer failed: ${err}`));
} else if (interaction.isContextMenuCommand()) { } else if (interaction.isContextMenuCommand()) {
await submitted await submitted
.deferReply({ ephemeral: true }) .deferReply({ ephemeral: true })
.catch((err) => logger.error(`Warn interaction defer failed: ${err}`)); .catch((err) => logger.error(`Warn interaction defer failed: ${err}`));
} }
const reason = submitted.fields.getTextInputValue("reason"); const reason = submitted.fields.getTextInputValue("reason");
const evidence = submitted.fields.getTextInputValue("evidence");
await warnAction(pluginData, reason, evidence, target, interaction, submitted); await warnAction(pluginData, reason, target, interaction, submitted);
}) })
.catch((err) => logger.error(`Warn modal interaction failed: ${err}`)); .catch((err) => logger.error(`Warn modal interaction failed: ${err}`));
} }