3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-07-06 18:47:20 +00:00
This commit is contained in:
seeyebe 2025-06-25 22:29:23 +03:00 committed by GitHub
commit 450ac8918e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 13 deletions

View file

@ -1,5 +1,7 @@
import { import {
ActionRowBuilder,
APIEmbed, APIEmbed,
ButtonBuilder,
ChannelType, ChannelType,
ChatInputCommandInteraction, ChatInputCommandInteraction,
Client, Client,
@ -18,6 +20,7 @@ import {
InviteType, InviteType,
LimitedCollection, LimitedCollection,
Message, Message,
MessageActionRowComponentBuilder,
MessageCreateOptions, MessageCreateOptions,
MessageMentionOptions, MessageMentionOptions,
PartialChannelData, PartialChannelData,
@ -1321,6 +1324,20 @@ export async function confirm(
return waitForButtonConfirm(context, content, { restrictToId: userId }); return waitForButtonConfirm(context, content, { restrictToId: userId });
} }
export function createDisabledButtonRow(
row: ActionRowBuilder<MessageActionRowComponentBuilder>
): ActionRowBuilder<MessageActionRowComponentBuilder> {
const newRow = new ActionRowBuilder<MessageActionRowComponentBuilder>();
for (const component of row.components) {
if (component instanceof ButtonBuilder) {
newRow.addComponents(
ButtonBuilder.from(component).setDisabled(true)
);
}
}
return newRow;
}
export function messageSummary(msg: SavedMessage) { export function messageSummary(msg: SavedMessage) {
// Regular text content // Regular text content
let result = "```\n" + (msg.data.content ? escapeCodeBlock(msg.data.content) : "<no text content>") + "```"; let result = "```\n" + (msg.data.content ? escapeCodeBlock(msg.data.content) : "<no text content>") + "```";

View file

@ -9,7 +9,7 @@ import {
import moment from "moment"; import moment from "moment";
import { v4 as uuidv4 } from "uuid"; import { v4 as uuidv4 } from "uuid";
import { GenericCommandSource, isContextInteraction, sendContextResponse } from "../pluginUtils.js"; import { GenericCommandSource, isContextInteraction, sendContextResponse } from "../pluginUtils.js";
import { noop } from "../utils.js"; import { noop, createDisabledButtonRow } from "../utils.js";
export async function waitForButtonConfirm( export async function waitForButtonConfirm(
context: GenericCommandSource, context: GenericCommandSource,
@ -24,34 +24,42 @@ export async function waitForButtonConfirm(
.setStyle(ButtonStyle.Success) .setStyle(ButtonStyle.Success)
.setLabel(options?.confirmText || "Confirm") .setLabel(options?.confirmText || "Confirm")
.setCustomId(`confirmButton:${idMod}:${uuidv4()}`), .setCustomId(`confirmButton:${idMod}:${uuidv4()}`),
new ButtonBuilder() new ButtonBuilder()
.setStyle(ButtonStyle.Danger) .setStyle(ButtonStyle.Danger)
.setLabel(options?.cancelText || "Cancel") .setLabel(options?.cancelText || "Cancel")
.setCustomId(`cancelButton:${idMod}:${uuidv4()}`), .setCustomId(`cancelButton:${idMod}:${uuidv4()}`),
]); ]);
const message = await sendContextResponse(context, { ...toPost, components: [row] }, true); const message = await sendContextResponse(context, { ...toPost, components: [row] }, true);
const collector = message.createMessageComponentCollector({ time: 10000 }); const collector = message.createMessageComponentCollector({ time: 10000 });
collector.on("collect", (interaction: MessageComponentInteraction) => { collector.on("collect", (interaction: MessageComponentInteraction) => {
if (options?.restrictToId && options.restrictToId !== interaction.user.id) { if (options?.restrictToId && options.restrictToId !== interaction.user.id) {
interaction interaction
.reply({ content: `You are not permitted to use these buttons.`, ephemeral: true }) .reply({ content: `You are not permitted to use these buttons.`, ephemeral: true })
// tslint:disable-next-line no-console .catch(noop);
.catch((err) => console.trace(err.message)); } else if (interaction.customId.startsWith(`confirmButton:${idMod}:`)) {
} else { if (!contextIsInteraction) {
if (interaction.customId.startsWith(`confirmButton:${idMod}:`)) { message.delete().catch(noop);
if (!contextIsInteraction) message.delete(); } else {
resolve(true); interaction.update({ components: [createDisabledButtonRow(row)] }).catch(noop);
} else if (interaction.customId.startsWith(`cancelButton:${idMod}:`)) {
if (!contextIsInteraction) message.delete();
resolve(false);
} }
resolve(true);
} else if (interaction.customId.startsWith(`cancelButton:${idMod}:`)) {
if (!contextIsInteraction) {
message.delete().catch(noop);
} else {
interaction.update({ components: [createDisabledButtonRow(row)] }).catch(noop);
}
resolve(false);
} }
}); });
collector.on("end", () => { collector.on("end", () => {
if (!contextIsInteraction && message.deletable) message.delete().catch(noop); if (!contextIsInteraction) {
if (message.deletable) message.delete().catch(noop);
} else {
message.edit({ components: [createDisabledButtonRow(row)] }).catch(noop);
}
resolve(false); resolve(false);
}); });
}); });