xernerx 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/utils/CommandUtil.d.ts +15 -1
- package/dist/utils/CommandUtil.js +77 -2
- package/package.json +1 -1
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
import { Interaction, Message, MessagePayload } from "discord.js";
|
|
1
|
+
import { ActionRowBuilder, ButtonBuilder, EmbedBuilder, Interaction, Message, MessagePayload } from "discord.js";
|
|
2
2
|
import XernerxClient from "../client/XernerxClient.js";
|
|
3
3
|
import { XernerxMessage } from "../interfaces/HandlerInterfaces.js";
|
|
4
|
+
interface ButtonOptions {
|
|
5
|
+
index?: number;
|
|
6
|
+
buttons?: Array<string>;
|
|
7
|
+
reply?: boolean;
|
|
8
|
+
row?: ActionRowBuilder;
|
|
9
|
+
component?: ButtonBuilder;
|
|
10
|
+
components?: object[];
|
|
11
|
+
id?: string;
|
|
12
|
+
filter?: any;
|
|
13
|
+
time?: number;
|
|
14
|
+
ephemeral?: boolean;
|
|
15
|
+
}
|
|
4
16
|
export declare class MessageCommandUtil {
|
|
5
17
|
#private;
|
|
6
18
|
client: XernerxClient;
|
|
@@ -20,5 +32,7 @@ export declare class InteractionCommandUtil {
|
|
|
20
32
|
reply(content: MessagePayload | string): any;
|
|
21
33
|
defer(time: number): Promise<unknown>;
|
|
22
34
|
getCommands(): import("@discordjs/collection").Collection<string, object>;
|
|
35
|
+
buttonPaginator(embeds: Array<EmbedBuilder>, options: ButtonOptions): void;
|
|
23
36
|
isOwner(): boolean;
|
|
24
37
|
}
|
|
38
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionRowBuilder, EmbedBuilder, SelectMenuBuilder, } from "discord.js";
|
|
1
|
+
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, SelectMenuBuilder, } from "discord.js";
|
|
2
2
|
export class MessageCommandUtil {
|
|
3
3
|
client;
|
|
4
4
|
message;
|
|
@@ -154,7 +154,82 @@ export class InteractionCommandUtil {
|
|
|
154
154
|
? this.interaction.util.reply(content)
|
|
155
155
|
: this.interaction.channel.send(content);
|
|
156
156
|
}
|
|
157
|
-
|
|
157
|
+
buttonPaginator(embeds, options) {
|
|
158
|
+
if (!Array.isArray(embeds))
|
|
159
|
+
throw new Error(`Expected embeds to be of type array, received ${typeof embeds} instead.`);
|
|
160
|
+
if (embeds.length <= 0)
|
|
161
|
+
throw new Error(`The minimum embeds is 1.`);
|
|
162
|
+
if (typeof options !== "object")
|
|
163
|
+
options = {};
|
|
164
|
+
if (!Array.isArray(options.components))
|
|
165
|
+
options.components = [];
|
|
166
|
+
if (!options.row) {
|
|
167
|
+
options.row = new ActionRowBuilder();
|
|
168
|
+
if (!options.id)
|
|
169
|
+
options.id = `${this.interaction.id}-menu`;
|
|
170
|
+
}
|
|
171
|
+
if (!options.buttons)
|
|
172
|
+
options.buttons = ["⏮️", "◀️", "⏹️", "▶️", "⏭️"];
|
|
173
|
+
for (const button of options.buttons) {
|
|
174
|
+
options.row.addComponents(new ButtonBuilder()
|
|
175
|
+
.setCustomId(`${this.interaction.id}-${options.buttons.indexOf(button)}`)
|
|
176
|
+
.setEmoji(button)
|
|
177
|
+
.setStyle(ButtonStyle.Primary));
|
|
178
|
+
}
|
|
179
|
+
let embed = embeds[options.index || 0];
|
|
180
|
+
const content = {
|
|
181
|
+
embeds: [embed],
|
|
182
|
+
components: [options.row, ...options.components],
|
|
183
|
+
ephemeral: !!options.ephemeral,
|
|
184
|
+
};
|
|
185
|
+
(options.reply === undefined || options.reply === true
|
|
186
|
+
? this.interaction.util.reply(content)
|
|
187
|
+
: this.interaction.channel.send(content)).then((message) => {
|
|
188
|
+
const collector = message.channel
|
|
189
|
+
.createMessageComponentCollector({
|
|
190
|
+
filter: options.filter,
|
|
191
|
+
time: options?.time || 60000,
|
|
192
|
+
})
|
|
193
|
+
.on("collect", (interaction) => {
|
|
194
|
+
let stop = false;
|
|
195
|
+
if (interaction.customId.startsWith(this.interaction.id)) {
|
|
196
|
+
switch (Number(interaction.customId.split(/-/).pop())) {
|
|
197
|
+
case 0: {
|
|
198
|
+
embed = embeds[0];
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
case 1: {
|
|
202
|
+
embed =
|
|
203
|
+
embeds[embeds.indexOf(embed) >= 1 ? embeds.indexOf(embed) - 1 : 0];
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
case 2: {
|
|
207
|
+
collector.stop();
|
|
208
|
+
stop = true;
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
case 3: {
|
|
212
|
+
embed =
|
|
213
|
+
embeds[embeds.indexOf(embed) < embeds.length - 1
|
|
214
|
+
? embeds.indexOf(embed) + 1
|
|
215
|
+
: embeds.length - 1];
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
case 4: {
|
|
219
|
+
embed = embeds[embeds.length - 1];
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
stop
|
|
224
|
+
? interaction.update({ embeds: [embed], components: [] })
|
|
225
|
+
: interaction.update({ embeds: [embed] });
|
|
226
|
+
}
|
|
227
|
+
})
|
|
228
|
+
.on("end", () => {
|
|
229
|
+
this.interaction.editReply({ components: [] });
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
}
|
|
158
233
|
#buttonMenuPaginator(embeds, options) { }
|
|
159
234
|
isOwner() {
|
|
160
235
|
return this.client.util.isOwner(this.interaction.user.id);
|