3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 04:25:01 +00:00

Update djs & knub (#395)

* update pkgs

Signed-off-by: GitHub <noreply@github.com>

* new knub typings

Signed-off-by: GitHub <noreply@github.com>

* more pkg updates

Signed-off-by: GitHub <noreply@github.com>

* more fixes

Signed-off-by: GitHub <noreply@github.com>

* channel typings

Signed-off-by: GitHub <noreply@github.com>

* more message utils typings fixes

Signed-off-by: GitHub <noreply@github.com>

* migrate permissions

Signed-off-by: GitHub <noreply@github.com>

* fix: InternalPoster webhookables

Signed-off-by: GitHub <noreply@github.com>

* djs typings: Attachment & Util

Signed-off-by: GitHub <noreply@github.com>

* more typings

Signed-off-by: GitHub <noreply@github.com>

* fix: rename permissionNames

Signed-off-by: GitHub <noreply@github.com>

* more fixes

Signed-off-by: GitHub <noreply@github.com>

* half the number of errors

* knub commands => messageCommands

Signed-off-by: GitHub <noreply@github.com>

* configPreprocessor => configParser

Signed-off-by: GitHub <noreply@github.com>

* fix channel.messages

Signed-off-by: GitHub <noreply@github.com>

* revert automod any typing

Signed-off-by: GitHub <noreply@github.com>

* more configParser typings

Signed-off-by: GitHub <noreply@github.com>

* revert

Signed-off-by: GitHub <noreply@github.com>

* remove knub type params

Signed-off-by: GitHub <noreply@github.com>

* fix more MessageEmbed / MessageOptions

Signed-off-by: GitHub <noreply@github.com>

* dumb commit for @almeidx to see why this is stupid

Signed-off-by: GitHub <noreply@github.com>

* temp disable custom_events

Signed-off-by: GitHub <noreply@github.com>

* more minor typings fixes - 23 err left

Signed-off-by: GitHub <noreply@github.com>

* update djs dep

* +debug build method (revert this)

Signed-off-by: GitHub <noreply@github.com>

* Revert "+debug build method (revert this)"

This reverts commit a80af1e729.

* Redo +debug build (Revert this)

Signed-off-by: GitHub <noreply@github.com>

* uniform before/after Load shorthands

Signed-off-by: GitHub <noreply@github.com>

* remove unused imports & add prettier plugin

Signed-off-by: GitHub <noreply@github.com>

* env fixes for web platform hosting

Signed-off-by: GitHub <noreply@github.com>

* feat: knub v32-next; related fixes

* fix: allow legacy keys in change_perms action

* fix: request Message Content intent

* fix: use Knub's config validation logic in API

* fix(dashboard): fix error when there are no message and/or slash commands in a plugin

* fix(automod): start_thread action thread options

* fix(CustomEvents): message command types

* chore: remove unneeded type annotation

* feat: add forum channel icon; use thread icon for news threads

* chore: make tslint happy

* chore: fix formatting

---------

Signed-off-by: GitHub <noreply@github.com>
Co-authored-by: almeidx <almeidx@pm.me>
Co-authored-by: Dragory <2606411+Dragory@users.noreply.github.com>
This commit is contained in:
Tiago R 2023-04-01 12:58:17 +01:00 committed by GitHub
parent 293115af22
commit 06877e90cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
476 changed files with 2965 additions and 3251 deletions

View file

@ -1,6 +1,6 @@
import { StrictMessageContent } from "../utils";
import Timeout = NodeJS.Timeout;
import { calculateEmbedSize } from "./calculateEmbedSize";
import Timeout = NodeJS.Timeout;
type ConsumeFn = (part: StrictMessageContent) => void;

View file

@ -1,4 +1,4 @@
import { Awaitable } from "knub/dist/utils";
import { Awaitable } from "./typeUtils";
export async function asyncReduce<T, V>(
arr: T[],

View file

@ -1,4 +1,4 @@
import { MessageEmbedOptions } from "discord.js";
import { APIEmbed, EmbedData } from "discord.js";
function sumStringLengthsRecursively(obj: any): number {
if (obj == null) return 0;
@ -12,6 +12,6 @@ function sumStringLengthsRecursively(obj: any): number {
return 0;
}
export function calculateEmbedSize(embed: MessageEmbedOptions): number {
export function calculateEmbedSize(embed: APIEmbed | EmbedData): number {
return sumStringLengthsRecursively(embed);
}

View file

@ -1,9 +1,9 @@
import { Guild, GuildMember, Permissions, Role, Snowflake } from "discord.js";
import { Guild, GuildMember, PermissionsBitField, Role, Snowflake } from "discord.js";
import { getMissingPermissions } from "./getMissingPermissions";
import { hasDiscordPermissions } from "./hasDiscordPermissions";
export function canAssignRole(guild: Guild, member: GuildMember, roleId: string) {
if (getMissingPermissions(member.permissions, Permissions.FLAGS.MANAGE_ROLES)) {
if (getMissingPermissions(member.permissions, PermissionsBitField.Flags.ManageRoles)) {
return false;
}
@ -18,7 +18,7 @@ export function canAssignRole(guild: Guild, member: GuildMember, roleId: string)
const memberRoles = member.roles.cache;
const highestRoleWithManageRoles = memberRoles.reduce<Role | null>((highest, role) => {
if (!hasDiscordPermissions(role.permissions, Permissions.FLAGS.MANAGE_ROLES)) return highest;
if (!hasDiscordPermissions(role.permissions, PermissionsBitField.Flags.ManageRoles)) return highest;
if (highest == null) return role;
if (role.position > highest.position) return role;
return highest;

View file

@ -1,19 +1,19 @@
import {
Client,
Message,
MessageCreateOptions,
MessageEditOptions,
MessageOptions,
MessageReaction,
PartialMessageReaction,
PartialUser,
TextChannel,
TextBasedChannel,
User,
} from "discord.js";
import { Awaitable } from "knub/dist/utils";
import { MINUTES, noop } from "../utils";
import { Awaitable } from "./typeUtils";
import Timeout = NodeJS.Timeout;
export type LoadPageFn = (page: number) => Awaitable<MessageOptions & MessageEditOptions>;
export type LoadPageFn = (page: number) => Awaitable<MessageCreateOptions & MessageEditOptions>;
export interface PaginateMessageOpts {
timeout: number;
@ -27,7 +27,7 @@ const defaultOpts: PaginateMessageOpts = {
export async function createPaginatedMessage(
client: Client,
channel: TextChannel | User,
channel: TextBasedChannel | User,
totalPages: number,
loadPageFn: LoadPageFn,
opts: Partial<PaginateMessageOpts> = {},

View file

@ -1,7 +1,6 @@
import { spawn, Worker, Pool } from "threads";
import type { CryptFns } from "./cryptWorker";
import { MINUTES } from "../utils";
import { Pool, spawn, Worker } from "threads";
import { env } from "../env";
import { MINUTES } from "../utils";
const pool = Pool(() => spawn(new Worker("./cryptWorker"), { timeout: 10 * MINUTES }), 8);

View file

@ -1,6 +1,8 @@
import { Profiler } from "knub/dist/Profiler";
import type { Knub } from "knub";
import { performance } from "perf_hooks";
import { SECONDS, noop } from "../utils";
import { noop, SECONDS } from "../utils";
type Profiler = Knub["profiler"];
let _profilingEnabled = false;

View file

@ -6,7 +6,7 @@ type FilterResult<T> = {
* Filter an object's properties based on its values and keys
* @return New object with filtered properties
*/
export function filterObject<T>(
export function filterObject<T extends object>(
object: T,
filterFn: <K extends keyof T>(value: T[K], key: K) => boolean,
): FilterResult<T> {

View file

@ -1,4 +1,4 @@
import { Guild, GuildAuditLogsAction, GuildAuditLogsEntry } from "discord.js";
import { AuditLogEvent, Guild, GuildAuditLogsEntry } from "discord.js";
import { SECONDS, sleep } from "../utils";
const BATCH_DEBOUNCE_TIME = 2 * SECONDS;
@ -19,7 +19,7 @@ const batches = new Map<string, Batch>();
*/
export async function findMatchingAuditLogEntry(
guild: Guild,
action?: GuildAuditLogsAction,
action?: AuditLogEvent,
targetId?: string,
): Promise<GuildAuditLogsEntry | undefined> {
let candidates: GuildAuditLogsEntry[];
@ -49,7 +49,8 @@ export async function findMatchingAuditLogEntry(
const _candidates = Array.from(result?.entries.values() ?? []);
batches.delete(guild.id);
resolve(_candidates);
// TODO: Figure out the type
resolve(_candidates as any);
}),
join() {
batch._waitUntil = Date.now() + BATCH_DEBOUNCE_TIME;

View file

@ -1,6 +1,5 @@
import { GuildPluginData } from "knub";
import { getDefaultPrefix } from "knub/dist/commands/commandUtils";
import { getDefaultMessageCommandPrefix, GuildPluginData } from "knub";
export function getGuildPrefix(pluginData: GuildPluginData<any>) {
return pluginData.fullConfig.prefix || getDefaultPrefix(pluginData.client);
return pluginData.fullConfig.prefix || getDefaultMessageCommandPrefix(pluginData.client);
}

View file

@ -1,4 +1,4 @@
import { Permissions } from "discord.js";
import { PermissionsBitField } from "discord.js";
/**
* @param resolvedPermissions A Permission object from e.g. GuildChannel#permissionsFor() or Member#permission
@ -6,13 +6,13 @@ import { Permissions } from "discord.js";
* @return Bitmask of missing permissions
*/
export function getMissingPermissions(
resolvedPermissions: Permissions | Readonly<Permissions>,
resolvedPermissions: PermissionsBitField | Readonly<PermissionsBitField>,
requiredPermissions: number | bigint,
): bigint {
const allowedPermissions = resolvedPermissions;
const nRequiredPermissions = requiredPermissions;
if (Boolean(allowedPermissions.bitfield & Permissions.FLAGS.ADMINISTRATOR)) {
if (Boolean(allowedPermissions.bitfield & PermissionsBitField.Flags.Administrator)) {
return BigInt(0);
}

View file

@ -1,11 +1,11 @@
import { Permissions } from "discord.js";
import { PermissionsBitField } from "discord.js";
const permissionNumberToName: Map<bigint, string> = new Map();
const ignoredPermissionConstants = ["all", "allGuild", "allText", "allVoice"];
for (const key in Permissions.FLAGS) {
for (const key in PermissionsBitField.Flags) {
if (ignoredPermissionConstants.includes(key)) continue;
permissionNumberToName.set(BigInt(Permissions.FLAGS[key]), key);
permissionNumberToName.set(BigInt(PermissionsBitField.Flags[key]), key);
}
/**

View file

@ -1,18 +1,18 @@
import { Permissions, PermissionString } from "discord.js";
import { PermissionsBitField } from "discord.js";
/**
* @param resolvedPermissions A Permission object from e.g. GuildChannel#permissionsOf() or Member#permission
* @param requiredPermissions Bitmask of required permissions
*/
export function hasDiscordPermissions(
resolvedPermissions: Permissions | Readonly<Permissions> | null,
resolvedPermissions: PermissionsBitField | Readonly<PermissionsBitField> | null,
requiredPermissions: number | bigint,
) {
if (resolvedPermissions == null) {
return false;
}
if (resolvedPermissions.has(Permissions.FLAGS.ADMINISTRATOR)) {
if (resolvedPermissions.has(PermissionsBitField.Flags.Administrator)) {
return true;
}

View file

@ -1,6 +1,6 @@
import { Snowflake, SnowflakeUtil } from "discord.js";
export function idToTimestamp(id: string) {
export function idToTimestamp(id: string): string | null {
if (typeof id === "number") return null;
return SnowflakeUtil.deconstruct(id as Snowflake).timestamp;
return SnowflakeUtil.deconstruct(id as Snowflake).timestamp.toString();
}

View file

@ -1,6 +1,5 @@
import { Channel, DMChannel } from "discord.js";
import { ChannelTypeStrings } from "src/types";
import type { Channel, DMChannel } from "discord.js";
export function isDmChannel(channel: Channel): channel is DMChannel {
return channel.type === ChannelTypeStrings.DM || channel.type === ChannelTypeStrings.GROUP;
return channel.isDMBased();
}

View file

@ -1,5 +1,5 @@
import { Channel, GuildChannel } from "discord.js";
import type { Channel, GuildBasedChannel } from "discord.js";
export function isGuildChannel(channel: Channel): channel is GuildChannel {
return channel.type.startsWith("GUILD_");
export function isGuildChannel(channel: Channel): channel is GuildBasedChannel {
return "guild" in channel && channel.guild !== null;
}

View file

@ -1,10 +1,5 @@
import { Channel, ThreadChannel } from "discord.js";
import { ChannelTypeStrings } from "src/types";
import type { AnyThreadChannel, Channel } from "discord.js";
export function isThreadChannel(channel: Channel): channel is ThreadChannel {
return (
channel.type === ChannelTypeStrings.NEWS_THREAD ||
channel.type === ChannelTypeStrings.PUBLIC_THREAD ||
channel.type === ChannelTypeStrings.PRIVATE_THREAD
);
export function isThreadChannel(channel: Channel): channel is AnyThreadChannel {
return channel.isThread();
}

View file

@ -1,4 +1,5 @@
import { MessageOptions } from "discord.js";
import { MessageCreateOptions } from "discord.js";
import { StrictMessageContent } from "../utils.js";
function embedHasContent(embed: any) {
for (const [key, value] of Object.entries(embed)) {
@ -18,7 +19,7 @@ function embedHasContent(embed: any) {
return false;
}
export function messageHasContent(content: string | MessageOptions): boolean {
export function messageHasContent(content: string | MessageCreateOptions | StrictMessageContent): boolean {
if (typeof content === "string") {
return content.trim() !== "";
}

View file

@ -1,6 +1,7 @@
import { MessageOptions } from "discord.js";
import { MessageCreateOptions } from "discord.js";
import { StrictMessageContent } from "../utils.js";
import { messageHasContent } from "./messageHasContent";
export function messageIsEmpty(content: string | MessageOptions): boolean {
export function messageIsEmpty(content: string | MessageCreateOptions | StrictMessageContent): boolean {
return !messageHasContent(content);
}

View file

@ -1,48 +1,46 @@
import { PermissionFlags } from "discord.js";
import type { PermissionFlagsBits } from "discord.js";
import { EMPTY_CHAR } from "../utils";
export const PERMISSION_NAMES: Record<keyof PermissionFlags, string> = {
ADD_REACTIONS: "Add Reactions",
ADMINISTRATOR: "Administrator",
ATTACH_FILES: "Attach Files",
BAN_MEMBERS: "Ban Members",
CHANGE_NICKNAME: "Change Nickname",
CONNECT: "Connect",
CREATE_INSTANT_INVITE: "Create Invite",
CREATE_PRIVATE_THREADS: "Create Private Threads",
CREATE_PUBLIC_THREADS: "Create Public Threads",
DEAFEN_MEMBERS: "Deafen Members",
EMBED_LINKS: "Embed Links",
KICK_MEMBERS: "Kick Members",
MANAGE_CHANNELS: "Manage Channels",
MANAGE_EMOJIS_AND_STICKERS: "Manage Emojis and Stickers",
MANAGE_GUILD: "Manage Server",
MANAGE_MESSAGES: "Manage Messages",
MANAGE_NICKNAMES: "Manage Nicknames",
MANAGE_ROLES: "Manage Roles",
MANAGE_THREADS: "Manage Threads",
MANAGE_WEBHOOKS: "Manage Webhooks",
MENTION_EVERYONE: `Mention @${EMPTY_CHAR}everyone, @${EMPTY_CHAR}here, and All Roles`,
MOVE_MEMBERS: "Move Members",
MUTE_MEMBERS: "Mute Members",
PRIORITY_SPEAKER: "Priority Speaker",
READ_MESSAGE_HISTORY: "Read Message History",
REQUEST_TO_SPEAK: "Request to Speak",
SEND_MESSAGES: "Send Messages",
SEND_MESSAGES_IN_THREADS: "Send Messages in Threads",
SEND_TTS_MESSAGES: "Send Text-To-Speech Messages",
SPEAK: "Speak",
START_EMBEDDED_ACTIVITIES: "Start Embedded Activities",
STREAM: "Video",
USE_APPLICATION_COMMANDS: "Use Application Commands",
USE_EXTERNAL_EMOJIS: "Use External Emoji",
USE_EXTERNAL_STICKERS: "Use External Stickers",
USE_PRIVATE_THREADS: "Use Private Threads",
USE_PUBLIC_THREADS: "Use Public Threads",
USE_VAD: "Use Voice Activity",
VIEW_AUDIT_LOG: "View Audit Log",
VIEW_CHANNEL: "View Channels",
VIEW_GUILD_INSIGHTS: "View Guild Insights",
MODERATE_MEMBERS: "Moderate Members",
MANAGE_EVENTS: "Manage Events",
};
export const PERMISSION_NAMES = {
AddReactions: "Add Reactions",
Administrator: "Administrator",
AttachFiles: "Attach Files",
BanMembers: "Ban Members",
ChangeNickname: "Change Nickname",
Connect: "Connect",
CreateInstantInvite: "Create Invite",
CreatePrivateThreads: "Create Private Threads",
CreatePublicThreads: "Create Public Threads",
DeafenMembers: "Deafen Members",
EmbedLinks: "Embed Links",
KickMembers: "Kick Members",
ManageChannels: "Manage Channels",
ManageEmojisAndStickers: "Manage Emojis and Stickers",
ManageGuild: "Manage Server",
ManageMessages: "Manage Messages",
ManageNicknames: "Manage Nicknames",
ManageRoles: "Manage Roles",
ManageThreads: "Manage Threads",
ManageWebhooks: "Manage Webhooks",
MentionEveryone: `Mention @${EMPTY_CHAR}everyone, @${EMPTY_CHAR}here, and All Roles`,
MoveMembers: "Move Members",
MuteMembers: "Mute Members",
PrioritySpeaker: "Priority Speaker",
ReadMessageHistory: "Read Message History",
RequestToSpeak: "Request to Speak",
SendMessages: "Send Messages",
SendMessagesInThreads: "Send Messages in Threads",
SendTTSMessages: "Send Text-To-Speech Messages",
Speak: "Speak",
UseEmbeddedActivities: "Start Embedded Activities",
Stream: "Video",
UseApplicationCommands: "Use Application Commands",
UseExternalEmojis: "Use External Emoji",
UseExternalStickers: "Use External Stickers",
UseVAD: "Use Voice Activity",
ViewAuditLog: "View Audit Log",
ViewChannel: "View Channels",
ViewGuildInsights: "View Guild Insights",
ModerateMembers: "Moderate Members",
ManageEvents: "Manage Events",
} as const satisfies Record<keyof typeof PermissionFlagsBits, string>;

View file

@ -1,9 +1,10 @@
import { Permissions } from "discord.js";
import { PermissionsBitField } from "discord.js";
/**
* Bitmask of permissions required to read messages in a channel
*/
export const readChannelPermissions = Permissions.FLAGS.VIEW_CHANNEL | Permissions.FLAGS.READ_MESSAGE_HISTORY;
export const readChannelPermissions =
PermissionsBitField.Flags.ViewChannel | PermissionsBitField.Flags.ReadMessageHistory;
/**
* Bitmask of permissions required to read messages in a channel (bigint)

View file

@ -1,7 +1,4 @@
import { ChannelType } from "discord-api-types/v9";
import { CategoryChannel, Channel } from "discord.js";
import { ChannelTypes } from "discord.js/typings/enums";
import { ChannelTypeStrings } from "src/types";
import { isDmChannel } from "./isDmChannel";
import { isGuildChannel } from "./isGuildChannel";
import { isThreadChannel } from "./isThreadChannel";

View file

@ -1,4 +1,4 @@
import { GuildTextBasedChannel, Snowflake, TextChannel } from "discord.js";
import { GuildTextBasedChannel, Snowflake } from "discord.js";
import { GuildPluginData } from "knub";
import { getChannelIdFromMessageId } from "../data/getChannelIdFromMessageId";
import { isSnowflake } from "../utils";
@ -47,7 +47,7 @@ export async function resolveMessageTarget(pluginData: GuildPluginData<any>, val
}
const channel = pluginData.guild.channels.resolve(result.channelId as Snowflake);
if (!channel?.isText()) {
if (!channel?.isTextBased()) {
return null;
}

View file

@ -1,7 +1,7 @@
import {
Emoji,
Guild,
GuildChannel,
GuildBasedChannel,
GuildMember,
Message,
PartialGuildMember,
@ -9,12 +9,12 @@ import {
Snowflake,
StageInstance,
Sticker,
ThreadChannel,
StickerFormatType,
User,
} from "discord.js";
import { UnknownUser } from "src/utils";
import { GuildPluginData } from "knub";
import { TemplateSafeValueContainer, TypedTemplateSafeValueContainer } from "../templateFormatter";
import { UnknownUser } from "src/utils";
import { Case } from "../data/entities/Case";
import {
ISavedMessageAttachmentData,
ISavedMessageData,
@ -22,7 +22,7 @@ import {
ISavedMessageStickerData,
SavedMessage,
} from "../data/entities/SavedMessage";
import { Case } from "../data/entities/Case";
import { TemplateSafeValueContainer, TypedTemplateSafeValueContainer } from "../templateFormatter";
type InputProps<T> = Omit<
{
@ -239,7 +239,7 @@ export function userToTemplateSafeUser(user: User | UnknownUser): TemplateSafeUs
discriminator: user.discriminator,
mention: `<@${user.id}>`,
tag: user.tag,
avatarURL: user.displayAvatarURL?.({ dynamic: true }),
avatarURL: user.displayAvatarURL?.(),
bot: user.bot,
createdAt: user.createdTimestamp,
});
@ -268,7 +268,7 @@ export function memberToTemplateSafeMember(member: GuildMember | PartialGuildMem
});
}
export function channelToTemplateSafeChannel(channel: GuildChannel | ThreadChannel): TemplateSafeChannel {
export function channelToTemplateSafeChannel(channel: GuildBasedChannel): TemplateSafeChannel {
return new TemplateSafeChannel({
id: channel.id,
name: channel.name,
@ -305,9 +305,9 @@ export function stickerToTemplateSafeSticker(sticker: Sticker): TemplateSafeStic
packId: sticker.packId ?? undefined,
name: sticker.name,
description: sticker.description ?? "",
tags: sticker.tags?.join(", ") ?? "",
tags: sticker.tags ?? "",
format: sticker.format,
animated: sticker.format === "PNG" ? false : true,
animated: sticker.format === StickerFormatType.PNG ? false : true,
url: sticker.url,
});
}
@ -448,7 +448,7 @@ export function messageToTemplateSafeMessage(message: Message): TemplateSafeMess
id: message.id,
content: message.content,
author: userToTemplateSafeUser(message.author),
channel: channelToTemplateSafeChannel(message.channel as GuildChannel | ThreadChannel),
channel: channelToTemplateSafeChannel(message.channel as GuildBasedChannel),
});
}

View file

@ -8,3 +8,9 @@ export declare type WithRequiredProps<T, K extends keyof T> = T & {
// https://devblogs.microsoft.com/typescript/announcing-typescript-4-1/
export type Awaited<T> = T extends PromiseLike<infer U> ? Awaited<U> : T;
export type Awaitable<T = unknown> = T | Promise<T>;
export type DeepMutable<T> = {
-readonly [P in keyof T]: DeepMutable<T[P]>;
};

View file

@ -1,5 +1,3 @@
import { Not } from "../utils";
const scalarTypes = ["string", "number", "boolean", "bigint"];
export class ObjectAliasError extends Error {}

View file

@ -1,23 +1,31 @@
import { MessageActionRow, MessageButton, MessageComponentInteraction, MessageOptions, TextChannel } from "discord.js";
import { noop } from "knub/dist/utils";
import {
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
GuildTextBasedChannel,
MessageActionRowComponentBuilder,
MessageComponentInteraction,
MessageCreateOptions,
} from "discord.js";
import moment from "moment";
import uuidv4 from "uuid/v4";
import { noop } from "../utils";
export async function waitForButtonConfirm(
channel: TextChannel,
toPost: MessageOptions,
channel: GuildTextBasedChannel,
toPost: MessageCreateOptions,
options?: WaitForOptions,
): Promise<boolean> {
return new Promise(async (resolve) => {
const idMod = `${channel.guild.id}-${moment.utc().valueOf()}`;
const row = new MessageActionRow().addComponents([
new MessageButton()
.setStyle("SUCCESS")
const row = new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents([
new ButtonBuilder()
.setStyle(ButtonStyle.Success)
.setLabel(options?.confirmText || "Confirm")
.setCustomId(`confirmButton:${idMod}:${uuidv4()}`),
new MessageButton()
.setStyle("DANGER")
new ButtonBuilder()
.setStyle(ButtonStyle.Danger)
.setLabel(options?.cancelText || "Cancel")
.setCustomId(`cancelButton:${idMod}:${uuidv4()}`),
]);
@ -29,6 +37,7 @@ export async function waitForButtonConfirm(
if (options?.restrictToId && options.restrictToId !== interaction.user.id) {
interaction
.reply({ content: `You are not permitted to use these buttons.`, ephemeral: true })
// tslint:disable-next-line no-console
.catch((err) => console.trace(err.message));
} else {
if (interaction.customId.startsWith(`confirmButton:${idMod}:`)) {
@ -41,7 +50,7 @@ export async function waitForButtonConfirm(
}
});
collector.on("end", () => {
if (!message.deleted) message.delete().catch(noop);
if (message.deletable) message.delete().catch(noop);
resolve(false);
});
});