mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 22:21:51 +00:00
style(ContextMenus): improve ux
This commit is contained in:
parent
8fcbd50ea1
commit
cdcca8ccbb
5 changed files with 38 additions and 19 deletions
|
@ -1,8 +1,10 @@
|
||||||
|
import { PermissionFlagsBits } from "discord.js";
|
||||||
import { guildPluginUserContextMenuCommand } from "knub";
|
import { guildPluginUserContextMenuCommand } from "knub";
|
||||||
import { launchBanActionModal } from "../actions/ban";
|
import { launchBanActionModal } from "../actions/ban";
|
||||||
|
|
||||||
export const BanCmd = guildPluginUserContextMenuCommand({
|
export const BanCmd = guildPluginUserContextMenuCommand({
|
||||||
name: "Ban",
|
name: "Ban",
|
||||||
|
defaultMemberPermissions: PermissionFlagsBits.BanMembers.toString(),
|
||||||
async run({ pluginData, interaction }) {
|
async run({ pluginData, interaction }) {
|
||||||
await launchBanActionModal(pluginData, interaction, interaction.targetId);
|
await launchBanActionModal(pluginData, interaction, interaction.targetId);
|
||||||
},
|
},
|
||||||
|
|
|
@ -5,11 +5,14 @@ import {
|
||||||
ButtonInteraction,
|
ButtonInteraction,
|
||||||
ButtonStyle,
|
ButtonStyle,
|
||||||
ContextMenuCommandInteraction,
|
ContextMenuCommandInteraction,
|
||||||
|
GuildMember,
|
||||||
|
PermissionFlagsBits,
|
||||||
User,
|
User,
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import { GuildPluginData, guildPluginUserContextMenuCommand } from "knub";
|
import { GuildPluginData, guildPluginUserContextMenuCommand } from "knub";
|
||||||
import { Case } from "../../../data/entities/Case";
|
import { Case } from "../../../data/entities/Case";
|
||||||
import { logger } from "../../../logger";
|
import { logger } from "../../../logger";
|
||||||
|
import { ModActionsPlugin } from "../../../plugins/ModActions/ModActionsPlugin";
|
||||||
import { SECONDS, UnknownUser, emptyEmbedValue, renderUserUsername, resolveUser, trimLines } from "../../../utils";
|
import { SECONDS, UnknownUser, emptyEmbedValue, renderUserUsername, resolveUser, trimLines } from "../../../utils";
|
||||||
import { asyncMap } from "../../../utils/async";
|
import { asyncMap } from "../../../utils/async";
|
||||||
import { getChunkedEmbedFields } from "../../../utils/getChunkedEmbedFields";
|
import { getChunkedEmbedFields } from "../../../utils/getChunkedEmbedFields";
|
||||||
|
@ -18,7 +21,6 @@ import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||||
import { UtilityPlugin } from "../../Utility/UtilityPlugin";
|
import { UtilityPlugin } from "../../Utility/UtilityPlugin";
|
||||||
import { getUserInfoEmbed } from "../../Utility/functions/getUserInfoEmbed";
|
import { getUserInfoEmbed } from "../../Utility/functions/getUserInfoEmbed";
|
||||||
import { launchBanActionModal } from "../actions/ban";
|
import { launchBanActionModal } from "../actions/ban";
|
||||||
import { launchCleanActionModal } from "../actions/clean";
|
|
||||||
import { launchMuteActionModal } from "../actions/mute";
|
import { launchMuteActionModal } from "../actions/mute";
|
||||||
import { launchNoteActionModal } from "../actions/note";
|
import { launchNoteActionModal } from "../actions/note";
|
||||||
import { launchWarnActionModal } from "../actions/warn";
|
import { launchWarnActionModal } from "../actions/warn";
|
||||||
|
@ -36,6 +38,7 @@ const CASES_PER_PAGE = 10;
|
||||||
|
|
||||||
export const ModMenuCmd = guildPluginUserContextMenuCommand({
|
export const ModMenuCmd = guildPluginUserContextMenuCommand({
|
||||||
name: "Mod Menu",
|
name: "Mod Menu",
|
||||||
|
defaultMemberPermissions: PermissionFlagsBits.ViewAuditLog.toString(),
|
||||||
async run({ pluginData, interaction }) {
|
async run({ pluginData, interaction }) {
|
||||||
await interaction
|
await interaction
|
||||||
.deferReply({ ephemeral: true })
|
.deferReply({ ephemeral: true })
|
||||||
|
@ -115,6 +118,7 @@ export const ModMenuCmd = guildPluginUserContextMenuCommand({
|
||||||
return embed;
|
return embed;
|
||||||
},
|
},
|
||||||
infoEmbed,
|
infoEmbed,
|
||||||
|
executingMember,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -125,58 +129,65 @@ async function displayModMenu(
|
||||||
totalPages: number,
|
totalPages: number,
|
||||||
loadPage: LoadModMenuPageFn,
|
loadPage: LoadModMenuPageFn,
|
||||||
infoEmbed: APIEmbed | null,
|
infoEmbed: APIEmbed | null,
|
||||||
|
executingMember: GuildMember,
|
||||||
) {
|
) {
|
||||||
if (interaction.deferred == false) {
|
if (interaction.deferred == false) {
|
||||||
await interaction.deferReply().catch((err) => logger.error(`Mod menu interaction defer failed: ${err}`));
|
await interaction.deferReply().catch((err) => logger.error(`Mod menu interaction defer failed: ${err}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
const firstButton = new ButtonBuilder()
|
const firstButton = new ButtonBuilder()
|
||||||
.setStyle(ButtonStyle.Primary)
|
.setStyle(ButtonStyle.Secondary)
|
||||||
.setLabel("<<")
|
.setEmoji("⏪")
|
||||||
.setCustomId(serializeCustomId({ action: ModMenuActionType.PAGE, target: ModMenuNavigationType.FIRST }))
|
.setCustomId(serializeCustomId({ action: ModMenuActionType.PAGE, target: ModMenuNavigationType.FIRST }))
|
||||||
.setDisabled(true);
|
.setDisabled(true);
|
||||||
const prevButton = new ButtonBuilder()
|
const prevButton = new ButtonBuilder()
|
||||||
.setStyle(ButtonStyle.Primary)
|
.setStyle(ButtonStyle.Secondary)
|
||||||
.setLabel("<")
|
.setEmoji("⬅")
|
||||||
.setCustomId(serializeCustomId({ action: ModMenuActionType.PAGE, target: ModMenuNavigationType.PREV }))
|
.setCustomId(serializeCustomId({ action: ModMenuActionType.PAGE, target: ModMenuNavigationType.PREV }))
|
||||||
.setDisabled(true);
|
.setDisabled(true);
|
||||||
const infoButton = new ButtonBuilder()
|
const infoButton = new ButtonBuilder()
|
||||||
.setStyle(ButtonStyle.Primary)
|
.setStyle(ButtonStyle.Primary)
|
||||||
.setLabel("Info")
|
.setLabel("Info")
|
||||||
|
.setEmoji("ℹ")
|
||||||
.setCustomId(serializeCustomId({ action: ModMenuActionType.PAGE, target: ModMenuNavigationType.INFO }))
|
.setCustomId(serializeCustomId({ action: ModMenuActionType.PAGE, target: ModMenuNavigationType.INFO }))
|
||||||
.setDisabled(infoEmbed != null ? false : true);
|
.setDisabled(infoEmbed != null ? false : true);
|
||||||
const nextButton = new ButtonBuilder()
|
const nextButton = new ButtonBuilder()
|
||||||
.setStyle(ButtonStyle.Primary)
|
.setStyle(ButtonStyle.Secondary)
|
||||||
.setLabel(">")
|
.setEmoji("➡")
|
||||||
.setCustomId(serializeCustomId({ action: ModMenuActionType.PAGE, target: ModMenuNavigationType.NEXT }))
|
.setCustomId(serializeCustomId({ action: ModMenuActionType.PAGE, target: ModMenuNavigationType.NEXT }))
|
||||||
.setDisabled(totalPages > 1 ? false : true);
|
.setDisabled(totalPages > 1 ? false : true);
|
||||||
const lastButton = new ButtonBuilder()
|
const lastButton = new ButtonBuilder()
|
||||||
.setStyle(ButtonStyle.Primary)
|
.setStyle(ButtonStyle.Secondary)
|
||||||
.setLabel(">>")
|
.setEmoji("⏩")
|
||||||
.setCustomId(serializeCustomId({ action: ModMenuActionType.PAGE, target: ModMenuNavigationType.LAST }))
|
.setCustomId(serializeCustomId({ action: ModMenuActionType.PAGE, target: ModMenuNavigationType.LAST }))
|
||||||
.setDisabled(totalPages > 1 ? false : true);
|
.setDisabled(totalPages > 1 ? false : true);
|
||||||
const navigationButtons = [firstButton, prevButton, infoButton, nextButton, lastButton] satisfies ButtonBuilder[];
|
const navigationButtons = [firstButton, prevButton, infoButton, nextButton, lastButton] satisfies ButtonBuilder[];
|
||||||
|
|
||||||
|
const modactions = pluginData.getPlugin(ModActionsPlugin);
|
||||||
const moderationButtons = [
|
const moderationButtons = [
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
.setStyle(ButtonStyle.Secondary)
|
.setStyle(ButtonStyle.Primary)
|
||||||
.setLabel("Note")
|
.setLabel("Note")
|
||||||
|
.setEmoji("📝")
|
||||||
|
.setDisabled(!(await modactions.hasNotePermission(executingMember, interaction.channelId)))
|
||||||
.setCustomId(serializeCustomId({ action: ModMenuActionType.NOTE, target: interaction.targetId })),
|
.setCustomId(serializeCustomId({ action: ModMenuActionType.NOTE, target: interaction.targetId })),
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
.setStyle(ButtonStyle.Secondary)
|
.setStyle(ButtonStyle.Primary)
|
||||||
.setLabel("Warn")
|
.setLabel("Warn")
|
||||||
|
.setEmoji("⚠️")
|
||||||
|
.setDisabled(!(await modactions.hasWarnPermission(executingMember, interaction.channelId)))
|
||||||
.setCustomId(serializeCustomId({ action: ModMenuActionType.WARN, target: interaction.targetId })),
|
.setCustomId(serializeCustomId({ action: ModMenuActionType.WARN, target: interaction.targetId })),
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
.setStyle(ButtonStyle.Secondary)
|
.setStyle(ButtonStyle.Primary)
|
||||||
.setLabel("Clean")
|
|
||||||
.setCustomId(serializeCustomId({ action: ModMenuActionType.CLEAN, target: interaction.targetId })),
|
|
||||||
new ButtonBuilder()
|
|
||||||
.setStyle(ButtonStyle.Secondary)
|
|
||||||
.setLabel("Mute")
|
.setLabel("Mute")
|
||||||
|
.setEmoji("🔇")
|
||||||
|
.setDisabled(!(await modactions.hasMutePermission(executingMember, interaction.channelId)))
|
||||||
.setCustomId(serializeCustomId({ action: ModMenuActionType.MUTE, target: interaction.targetId })),
|
.setCustomId(serializeCustomId({ action: ModMenuActionType.MUTE, target: interaction.targetId })),
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
.setStyle(ButtonStyle.Secondary)
|
.setStyle(ButtonStyle.Primary)
|
||||||
.setLabel("Ban")
|
.setLabel("Ban")
|
||||||
|
.setEmoji("🚫")
|
||||||
|
.setDisabled(!(await modactions.hasBanPermission(executingMember, interaction.channelId)))
|
||||||
.setCustomId(serializeCustomId({ action: ModMenuActionType.BAN, target: interaction.targetId })),
|
.setCustomId(serializeCustomId({ action: ModMenuActionType.BAN, target: interaction.targetId })),
|
||||||
] satisfies ButtonBuilder[];
|
] satisfies ButtonBuilder[];
|
||||||
|
|
||||||
|
@ -204,6 +215,7 @@ async function displayModMenu(
|
||||||
if (opts.action == ModMenuActionType.PAGE && opts.target == ModMenuNavigationType.INFO && infoEmbed != null) {
|
if (opts.action == ModMenuActionType.PAGE && opts.target == ModMenuNavigationType.INFO && infoEmbed != null) {
|
||||||
infoButton
|
infoButton
|
||||||
.setLabel("Cases")
|
.setLabel("Cases")
|
||||||
|
.setEmoji("📋")
|
||||||
.setCustomId(serializeCustomId({ action: ModMenuActionType.PAGE, target: ModMenuNavigationType.CASES }));
|
.setCustomId(serializeCustomId({ action: ModMenuActionType.PAGE, target: ModMenuNavigationType.CASES }));
|
||||||
firstButton.setDisabled(true);
|
firstButton.setDisabled(true);
|
||||||
prevButton.setDisabled(true);
|
prevButton.setDisabled(true);
|
||||||
|
@ -219,6 +231,7 @@ async function displayModMenu(
|
||||||
} else if (opts.action == ModMenuActionType.PAGE && opts.target == ModMenuNavigationType.CASES) {
|
} else if (opts.action == ModMenuActionType.PAGE && opts.target == ModMenuNavigationType.CASES) {
|
||||||
infoButton
|
infoButton
|
||||||
.setLabel("Info")
|
.setLabel("Info")
|
||||||
|
.setEmoji("ℹ")
|
||||||
.setCustomId(serializeCustomId({ action: ModMenuActionType.PAGE, target: ModMenuNavigationType.INFO }));
|
.setCustomId(serializeCustomId({ action: ModMenuActionType.PAGE, target: ModMenuNavigationType.INFO }));
|
||||||
updateNavButtonState(firstButton, prevButton, nextButton, lastButton, page, totalPages);
|
updateNavButtonState(firstButton, prevButton, nextButton, lastButton, page, totalPages);
|
||||||
|
|
||||||
|
@ -264,8 +277,6 @@ async function displayModMenu(
|
||||||
await launchNoteActionModal(pluginData, i as ButtonInteraction, opts.target);
|
await launchNoteActionModal(pluginData, i as ButtonInteraction, opts.target);
|
||||||
} else if (opts.action == ModMenuActionType.WARN) {
|
} else if (opts.action == ModMenuActionType.WARN) {
|
||||||
await launchWarnActionModal(pluginData, i as ButtonInteraction, opts.target);
|
await launchWarnActionModal(pluginData, i as ButtonInteraction, opts.target);
|
||||||
} else if (opts.action == ModMenuActionType.CLEAN) {
|
|
||||||
await launchCleanActionModal(pluginData, i as ButtonInteraction, opts.target);
|
|
||||||
} else if (opts.action == ModMenuActionType.MUTE) {
|
} else if (opts.action == ModMenuActionType.MUTE) {
|
||||||
await launchMuteActionModal(pluginData, i as ButtonInteraction, opts.target);
|
await launchMuteActionModal(pluginData, i as ButtonInteraction, opts.target);
|
||||||
} else if (opts.action == ModMenuActionType.BAN) {
|
} else if (opts.action == ModMenuActionType.BAN) {
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
|
import { PermissionFlagsBits } from "discord.js";
|
||||||
import { guildPluginUserContextMenuCommand } from "knub";
|
import { guildPluginUserContextMenuCommand } from "knub";
|
||||||
import { launchMuteActionModal } from "../actions/mute";
|
import { launchMuteActionModal } from "../actions/mute";
|
||||||
|
|
||||||
export const MuteCmd = guildPluginUserContextMenuCommand({
|
export const MuteCmd = guildPluginUserContextMenuCommand({
|
||||||
name: "Mute",
|
name: "Mute",
|
||||||
|
defaultMemberPermissions: PermissionFlagsBits.ModerateMembers.toString(),
|
||||||
async run({ pluginData, interaction }) {
|
async run({ pluginData, interaction }) {
|
||||||
await launchMuteActionModal(pluginData, interaction, interaction.targetId);
|
await launchMuteActionModal(pluginData, interaction, interaction.targetId);
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
|
import { PermissionFlagsBits } from "discord.js";
|
||||||
import { guildPluginUserContextMenuCommand } from "knub";
|
import { guildPluginUserContextMenuCommand } from "knub";
|
||||||
import { launchNoteActionModal } from "../actions/note";
|
import { launchNoteActionModal } from "../actions/note";
|
||||||
|
|
||||||
export const NoteCmd = guildPluginUserContextMenuCommand({
|
export const NoteCmd = guildPluginUserContextMenuCommand({
|
||||||
name: "Note",
|
name: "Note",
|
||||||
|
defaultMemberPermissions: PermissionFlagsBits.ManageMessages.toString(),
|
||||||
async run({ pluginData, interaction }) {
|
async run({ pluginData, interaction }) {
|
||||||
await launchNoteActionModal(pluginData, interaction, interaction.targetId);
|
await launchNoteActionModal(pluginData, interaction, interaction.targetId);
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
|
import { PermissionFlagsBits } from "discord.js";
|
||||||
import { guildPluginUserContextMenuCommand } from "knub";
|
import { guildPluginUserContextMenuCommand } from "knub";
|
||||||
import { launchWarnActionModal } from "../actions/warn";
|
import { launchWarnActionModal } from "../actions/warn";
|
||||||
|
|
||||||
export const WarnCmd = guildPluginUserContextMenuCommand({
|
export const WarnCmd = guildPluginUserContextMenuCommand({
|
||||||
name: "Warn",
|
name: "Warn",
|
||||||
|
defaultMemberPermissions: PermissionFlagsBits.ManageMessages.toString(),
|
||||||
async run({ pluginData, interaction }) {
|
async run({ pluginData, interaction }) {
|
||||||
await launchWarnActionModal(pluginData, interaction, interaction.targetId);
|
await launchWarnActionModal(pluginData, interaction, interaction.targetId);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue