mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-14 05:45:02 +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,
|
||||
|
@ -12,7 +13,7 @@ import { canActOn } from "src/pluginUtils";
|
|||
import { ModActionsPlugin } from "src/plugins/ModActions/ModActionsPlugin";
|
||||
import { convertDelayStringToMS, 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 banAction(
|
||||
|
@ -20,8 +21,10 @@ async function banAction(
|
|||
duration: string | undefined,
|
||||
reason: string | undefined,
|
||||
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,
|
||||
|
@ -30,13 +33,13 @@ async function banAction(
|
|||
|
||||
const modactions = pluginData.getPlugin(ModActionsPlugin);
|
||||
if (!userCfg.can_use || !(await modactions.hasBanPermission(executingMember, interaction.channelId))) {
|
||||
await interaction.editReply({ content: "Cannot ban: insufficient permissions", embeds: [], components: [] });
|
||||
await interactionToReply.editReply({ content: "Cannot ban: insufficient permissions", embeds: [], components: [] });
|
||||
return;
|
||||
}
|
||||
|
||||
const targetMember = await pluginData.guild.members.fetch(target);
|
||||
if (!canActOn(pluginData, executingMember, targetMember)) {
|
||||
await interaction.editReply({ content: "Cannot ban: insufficient permissions", embeds: [], components: [] });
|
||||
await interactionToReply.editReply({ content: "Cannot ban: insufficient permissions", embeds: [], components: [] });
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -47,7 +50,7 @@ async function banAction(
|
|||
const durationMs = duration ? convertDelayStringToMS(duration)! : undefined;
|
||||
const result = await modactions.banUserId(target, reason, { caseArgs }, durationMs);
|
||||
if (result.status === "failed") {
|
||||
await interaction.editReply({ content: "Error: Failed to ban user", embeds: [], components: [] });
|
||||
await interactionToReply.editReply({ content: "Error: Failed to ban user", embeds: [], components: [] });
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -57,12 +60,12 @@ async function banAction(
|
|||
durationMs ? `for ${humanizeDuration(durationMs)}` : "indefinitely"
|
||||
} (Case #${result.case.case_number})${messageResultText}`;
|
||||
|
||||
await interaction.editReply({ content: banMessage, embeds: [], components: [] });
|
||||
await interactionToReply.editReply({ content: banMessage, embeds: [], components: [] });
|
||||
}
|
||||
|
||||
export async function launchBanActionModal(
|
||||
pluginData: GuildPluginData<ContextMenuPluginType>,
|
||||
interaction: ButtonInteraction,
|
||||
interaction: ButtonInteraction | ContextMenuCommandInteraction,
|
||||
target: string,
|
||||
) {
|
||||
const modal = new ModalBuilder().setCustomId("ban").setTitle("Ban");
|
||||
|
@ -83,11 +86,15 @@ export async function launchBanActionModal(
|
|||
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 duration = submitted.fields.getTextInputValue("duration");
|
||||
const reason = submitted.fields.getTextInputValue("reason");
|
||||
|
||||
await banAction(pluginData, duration, reason, target, interaction);
|
||||
await banAction(pluginData, duration, reason, target, interaction, submitted);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import {
|
|||
} from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { UtilityPlugin } from "../../../plugins/Utility/UtilityPlugin";
|
||||
import { MODAL_TIMEOUT } from "../commands/ModMenuCmd";
|
||||
import { MODAL_TIMEOUT } from "../commands/ModMenuUserCtxCmd";
|
||||
import { ContextMenuPluginType } from "../types";
|
||||
|
||||
export async function cleanAction(
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
ActionRowBuilder,
|
||||
ButtonInteraction,
|
||||
ContextMenuCommandInteraction,
|
||||
ModalBuilder,
|
||||
ModalSubmitInteraction,
|
||||
TextInputBuilder,
|
||||
|
@ -15,7 +16,7 @@ import { convertDelayStringToMS } from "../../../utils";
|
|||
import { CaseArgs } from "../../Cases/types";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { MutesPlugin } from "../../Mutes/MutesPlugin";
|
||||
import { MODAL_TIMEOUT } from "../commands/ModMenuCmd";
|
||||
import { MODAL_TIMEOUT } from "../commands/ModMenuUserCtxCmd";
|
||||
import { ContextMenuPluginType } from "../types";
|
||||
|
||||
async function muteAction(
|
||||
|
@ -23,8 +24,10 @@ async function muteAction(
|
|||
duration: string | undefined,
|
||||
reason: string | undefined,
|
||||
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,
|
||||
|
@ -33,13 +36,21 @@ async function muteAction(
|
|||
|
||||
const modactions = pluginData.getPlugin(ModActionsPlugin);
|
||||
if (!userCfg.can_use || !(await modactions.hasMutePermission(executingMember, interaction.channelId))) {
|
||||
await interaction.editReply({ content: "Cannot mute: insufficient permissions", embeds: [], components: [] });
|
||||
await interactionToReply.editReply({
|
||||
content: "Cannot mute: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const targetMember = await pluginData.guild.members.fetch(target);
|
||||
if (!canActOn(pluginData, executingMember, targetMember)) {
|
||||
await interaction.editReply({ content: "Cannot mute: insufficient permissions", embeds: [], components: [] });
|
||||
await interactionToReply.editReply({
|
||||
content: "Cannot mute: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -57,9 +68,13 @@ async function muteAction(
|
|||
durationMs ? `for ${humanizeDuration(durationMs)}` : "indefinitely"
|
||||
} (Case #${result.case.case_number})${messageResultText}`;
|
||||
|
||||
await interaction.editReply({ content: muteMessage, embeds: [], components: [] });
|
||||
await interactionToReply.editReply({ content: muteMessage, embeds: [], components: [] });
|
||||
} catch (e) {
|
||||
await interaction.editReply({ content: "Plugin error, please check your BOT_ALERTs", embeds: [], components: [] });
|
||||
await interactionToReply.editReply({
|
||||
content: "Plugin error, please check your BOT_ALERTs",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
|
||||
if (e instanceof RecoverablePluginError && e.code === ERRORS.NO_MUTE_ROLE_IN_CONFIG) {
|
||||
pluginData.getPlugin(LogsPlugin).logBotAlert({
|
||||
|
@ -73,7 +88,7 @@ async function muteAction(
|
|||
|
||||
export async function launchMuteActionModal(
|
||||
pluginData: GuildPluginData<ContextMenuPluginType>,
|
||||
interaction: ButtonInteraction,
|
||||
interaction: ButtonInteraction | ContextMenuCommandInteraction,
|
||||
target: string,
|
||||
) {
|
||||
const modal = new ModalBuilder().setCustomId("mute").setTitle("Mute");
|
||||
|
@ -94,11 +109,15 @@ export async function launchMuteActionModal(
|
|||
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 duration = submitted.fields.getTextInputValue("duration");
|
||||
const reason = submitted.fields.getTextInputValue("reason");
|
||||
|
||||
await muteAction(pluginData, duration, reason, target, interaction);
|
||||
await muteAction(pluginData, duration, reason, target, interaction, submitted);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
ActionRowBuilder,
|
||||
ButtonInteraction,
|
||||
ContextMenuCommandInteraction,
|
||||
ModalBuilder,
|
||||
ModalSubmitInteraction,
|
||||
TextInputBuilder,
|
||||
|
@ -13,15 +14,17 @@ import { CaseTypes } from "../../../data/CaseTypes";
|
|||
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
|
||||
import { renderUserUsername } from "../../../utils";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { MODAL_TIMEOUT } from "../commands/ModMenuCmd";
|
||||
import { MODAL_TIMEOUT } from "../commands/ModMenuUserCtxCmd";
|
||||
import { ContextMenuPluginType } from "../types";
|
||||
|
||||
async function noteAction(
|
||||
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,
|
||||
|
@ -30,13 +33,21 @@ async function noteAction(
|
|||
|
||||
const modactions = pluginData.getPlugin(ModActionsPlugin);
|
||||
if (!userCfg.can_use || !(await modactions.hasNotePermission(executingMember, interaction.channelId))) {
|
||||
await interaction.editReply({ content: "Cannot note: insufficient permissions", embeds: [], components: [] });
|
||||
await interactionToReply.editReply({
|
||||
content: "Cannot note: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const targetMember = await pluginData.guild.members.fetch(target);
|
||||
if (!canActOn(pluginData, executingMember, targetMember)) {
|
||||
await interaction.editReply({ content: "Cannot note: insufficient permissions", embeds: [], components: [] });
|
||||
await interactionToReply.editReply({
|
||||
content: "Cannot note: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -56,7 +67,7 @@ async function noteAction(
|
|||
});
|
||||
|
||||
const userName = renderUserUsername(targetMember.user);
|
||||
await interaction.editReply({
|
||||
await interactionToReply.editReply({
|
||||
content: `Note added on **${userName}** (Case #${createdCase.case_number})`,
|
||||
embeds: [],
|
||||
components: [],
|
||||
|
@ -65,7 +76,7 @@ async function noteAction(
|
|||
|
||||
export async function launchNoteActionModal(
|
||||
pluginData: GuildPluginData<ContextMenuPluginType>,
|
||||
interaction: ButtonInteraction,
|
||||
interaction: ButtonInteraction | ContextMenuCommandInteraction,
|
||||
target: string,
|
||||
) {
|
||||
const modal = new ModalBuilder().setCustomId("note").setTitle("Note");
|
||||
|
@ -76,10 +87,14 @@ export async function launchNoteActionModal(
|
|||
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 noteAction(pluginData, reason, target, interaction);
|
||||
await noteAction(pluginData, reason, target, interaction, submitted);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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