mirror of
https://github.com/sern-handler/awesome-plugins
synced 2026-06-12 02:42:24 +00:00
chore: Update JavaScript plugins (#69)
chore: update JavaScript plugins Co-authored-by: EvolutionX-10 <EvolutionX-10@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
98ab449203
commit
b2ee0996f1
@@ -1,4 +1,4 @@
|
||||
// @ts-nocheck
|
||||
//@ts-nocheck
|
||||
|
||||
/**
|
||||
* This is buttonConfirmation plugin, it runs confirmation prompt in the form of buttons.
|
||||
@@ -19,7 +19,7 @@
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
import { PluginType } from "@sern/handler";
|
||||
import { CommandControlPlugin, controller } from "@sern/handler";
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
@@ -27,69 +27,60 @@ import {
|
||||
ComponentType,
|
||||
} from "discord.js";
|
||||
export function confirmation(options) {
|
||||
return {
|
||||
type: PluginType.Event,
|
||||
description: "Confirms",
|
||||
|
||||
async execute([ctx], controller) {
|
||||
options = {
|
||||
content: "Do you want to proceed?",
|
||||
denialMessage: "Cancelled",
|
||||
labels: ["No", "Yes"],
|
||||
time: 60_000,
|
||||
wrongUserResponse: "Not for you!",
|
||||
...options,
|
||||
};
|
||||
const buttons = options.labels.map((l, i) => {
|
||||
return new ButtonBuilder()
|
||||
.setCustomId(l)
|
||||
.setLabel(l)
|
||||
.setStyle(
|
||||
i === 0 ? ButtonStyle.Danger : ButtonStyle.Success
|
||||
);
|
||||
});
|
||||
const sent = await ctx.reply({
|
||||
content: options.content,
|
||||
components: [new ActionRowBuilder().setComponents(buttons)],
|
||||
});
|
||||
const collector = sent.createMessageComponentCollector({
|
||||
componentType: ComponentType.Button,
|
||||
filter: (i) => i.user.id === ctx.user.id,
|
||||
time: options.time,
|
||||
});
|
||||
return new Promise((resolve) => {
|
||||
collector.on("collect", async (i) => {
|
||||
await i.update({
|
||||
components: [],
|
||||
});
|
||||
collector.stop();
|
||||
|
||||
if (i.customId === options.labels[1]) {
|
||||
resolve(controller.next());
|
||||
return;
|
||||
}
|
||||
|
||||
await i.editReply({
|
||||
content: options?.denialMessage,
|
||||
});
|
||||
resolve(controller.stop());
|
||||
return CommandControlPlugin(async (ctx, args) => {
|
||||
options = {
|
||||
content: "Do you want to proceed?",
|
||||
denialMessage: "Cancelled",
|
||||
labels: ["No", "Yes"],
|
||||
time: 60_000,
|
||||
wrongUserResponse: "Not for you!",
|
||||
...options,
|
||||
};
|
||||
const buttons = options.labels.map((l, i) => {
|
||||
return new ButtonBuilder()
|
||||
.setCustomId(l)
|
||||
.setLabel(l)
|
||||
.setStyle(i === 0 ? ButtonStyle.Danger : ButtonStyle.Success);
|
||||
});
|
||||
const sent = await ctx.reply({
|
||||
content: options.content,
|
||||
components: [new ActionRowBuilder().setComponents(buttons)],
|
||||
});
|
||||
const collector = sent.createMessageComponentCollector({
|
||||
componentType: ComponentType.Button,
|
||||
filter: (i) => i.user.id === ctx.user.id,
|
||||
time: options.time,
|
||||
});
|
||||
return new Promise((resolve) => {
|
||||
collector.on("collect", async (i) => {
|
||||
await i.update({
|
||||
components: [],
|
||||
});
|
||||
collector.on("end", async (c) => {
|
||||
if (c.size) return;
|
||||
buttons.forEach((b) => b.setDisabled());
|
||||
await sent.edit({
|
||||
components: [
|
||||
new ActionRowBuilder().setComponents(buttons),
|
||||
],
|
||||
});
|
||||
collector.stop();
|
||||
|
||||
if (i.customId === options.labels[1]) {
|
||||
resolve(controller.next());
|
||||
return;
|
||||
}
|
||||
|
||||
await i.editReply({
|
||||
content: options?.denialMessage,
|
||||
});
|
||||
collector.on("ignore", async (i) => {
|
||||
await i.reply({
|
||||
content: options?.wrongUserResponse,
|
||||
ephemeral: true,
|
||||
});
|
||||
resolve(controller.stop());
|
||||
});
|
||||
collector.on("end", async (c) => {
|
||||
if (c.size) return;
|
||||
buttons.forEach((b) => b.setDisabled());
|
||||
await sent.edit({
|
||||
components: [new ActionRowBuilder().setComponents(buttons)],
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
collector.on("ignore", async (i) => {
|
||||
await i.reply({
|
||||
content: options?.wrongUserResponse,
|
||||
ephemeral: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user