mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-07 11:07:19 +00:00
feat: Add user context menu commands for notes, warns, mutes and bans
This commit is contained in:
parent
24b11800f5
commit
454bec6c9f
11 changed files with 135 additions and 39 deletions
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
ActionRowBuilder,
|
||||
ButtonInteraction,
|
||||
ContextMenuCommandInteraction,
|
||||
ModalBuilder,
|
||||
ModalSubmitInteraction,
|
||||
TextInputBuilder,
|
||||
|
@ -11,15 +12,17 @@ import { canActOn } from "src/pluginUtils";
|
|||
import { ModActionsPlugin } from "src/plugins/ModActions/ModActionsPlugin";
|
||||
import { renderUserUsername } from "../../../utils";
|
||||
import { CaseArgs } from "../../Cases/types";
|
||||
import { MODAL_TIMEOUT } from "../commands/ModMenuCmd";
|
||||
import { MODAL_TIMEOUT } from "../commands/ModMenuUserCtxCmd";
|
||||
import { ContextMenuPluginType } from "../types";
|
||||
|
||||
async function warnAction(
|
||||
pluginData: GuildPluginData<ContextMenuPluginType>,
|
||||
reason: string,
|
||||
target: string,
|
||||
interaction: ButtonInteraction,
|
||||
interaction: ButtonInteraction | ContextMenuCommandInteraction,
|
||||
submitInteraction: ModalSubmitInteraction,
|
||||
) {
|
||||
const interactionToReply = interaction instanceof ButtonInteraction ? interaction : submitInteraction;
|
||||
const executingMember = await pluginData.guild.members.fetch(interaction.user.id);
|
||||
const userCfg = await pluginData.config.getMatchingConfig({
|
||||
channelId: interaction.channelId,
|
||||
|
@ -28,13 +31,21 @@ async function warnAction(
|
|||
|
||||
const modactions = pluginData.getPlugin(ModActionsPlugin);
|
||||
if (!userCfg.can_use || !(await modactions.hasWarnPermission(executingMember, interaction.channelId))) {
|
||||
await interaction.editReply({ content: "Cannot warn: insufficient permissions", embeds: [], components: [] });
|
||||
await interactionToReply.editReply({
|
||||
content: "Cannot warn: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const targetMember = await pluginData.guild.members.fetch(target);
|
||||
if (!canActOn(pluginData, executingMember, targetMember)) {
|
||||
await interaction.editReply({ content: "Cannot warn: insufficient permissions", embeds: [], components: [] });
|
||||
await interactionToReply.editReply({
|
||||
content: "Cannot warn: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -44,7 +55,7 @@ async function warnAction(
|
|||
|
||||
const result = await modactions.warnMember(targetMember, reason, { caseArgs });
|
||||
if (result.status === "failed") {
|
||||
await interaction.editReply({ content: "Error: Failed to warn user", embeds: [], components: [] });
|
||||
await interactionToReply.editReply({ content: "Error: Failed to warn user", embeds: [], components: [] });
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -52,12 +63,12 @@ async function warnAction(
|
|||
const messageResultText = result.notifyResult.text ? ` (${result.notifyResult.text})` : "";
|
||||
const muteMessage = `Warned **${userName}** (Case #${result.case.case_number})${messageResultText}`;
|
||||
|
||||
await interaction.editReply({ content: muteMessage, embeds: [], components: [] });
|
||||
await interactionToReply.editReply({ content: muteMessage, embeds: [], components: [] });
|
||||
}
|
||||
|
||||
export async function launchWarnActionModal(
|
||||
pluginData: GuildPluginData<ContextMenuPluginType>,
|
||||
interaction: ButtonInteraction,
|
||||
interaction: ButtonInteraction | ContextMenuCommandInteraction,
|
||||
target: string,
|
||||
) {
|
||||
const modal = new ModalBuilder().setCustomId("warn").setTitle("Warn");
|
||||
|
@ -68,10 +79,14 @@ export async function launchWarnActionModal(
|
|||
await interaction.showModal(modal);
|
||||
const submitted: ModalSubmitInteraction = await interaction.awaitModalSubmit({ time: MODAL_TIMEOUT });
|
||||
if (submitted) {
|
||||
await submitted.deferUpdate();
|
||||
if (interaction instanceof ButtonInteraction) {
|
||||
await submitted.deferUpdate();
|
||||
} else {
|
||||
await submitted.deferReply({ ephemeral: true });
|
||||
}
|
||||
|
||||
const reason = submitted.fields.getTextInputValue("reason");
|
||||
|
||||
await warnAction(pluginData, reason, target, interaction);
|
||||
await warnAction(pluginData, reason, target, interaction, submitted);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue