djs-builder 0.5.10 → 0.5.31
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/.tsbuildinfo +1 -1
- package/dist/discord/builder/system/Pagination.d.ts +60 -57
- package/dist/discord/builder/system/Pagination.d.ts.map +1 -1
- package/dist/discord/builder/system/Pagination.js +197 -193
- package/dist/discord/builder/system/Pagination.js.map +1 -1
- package/dist/discord/events-handler/events.d.ts.map +1 -1
- package/dist/discord/events-handler/events.js.map +1 -1
- package/dist/discord/events-handler/login.d.ts +6 -2
- package/dist/discord/events-handler/login.d.ts.map +1 -1
- package/dist/discord/events-handler/login.js +86 -5
- package/dist/discord/events-handler/login.js.map +1 -1
- package/lib/discord/builder/system/Pagination.ts +300 -299
- package/lib/discord/events-handler/events.ts +1 -0
- package/lib/discord/events-handler/login.ts +102 -10
- package/package.json +1 -1
- package/dist/discord/builder/components/Pagination.d.ts +0 -65
- package/dist/discord/builder/components/Pagination.d.ts.map +0 -1
- package/dist/discord/builder/components/Pagination.js +0 -189
- package/dist/discord/builder/components/Pagination.js.map +0 -1
- package/dist/discord/events-handler/events loader.d.ts +0 -3
- package/dist/discord/events-handler/events loader.d.ts.map +0 -1
- package/dist/discord/events-handler/events loader.js +0 -20
- package/dist/discord/events-handler/events loader.js.map +0 -1
|
@@ -1,321 +1,322 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ActionRowBuilder,
|
|
3
2
|
ButtonBuilder,
|
|
3
|
+
ActionRowBuilder,
|
|
4
4
|
EmbedBuilder,
|
|
5
|
+
Message,
|
|
6
|
+
MessageComponentInteraction,
|
|
7
|
+
MessageActionRowComponentBuilder,
|
|
5
8
|
ButtonStyle,
|
|
6
9
|
StringSelectMenuBuilder,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
style: ButtonStyle;
|
|
17
|
-
emoji?: string;
|
|
18
|
-
onClick?: () => void;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
interface EmbedOptions {
|
|
22
|
-
homePage: number;
|
|
23
|
-
embeds: EmbedBuilder[];
|
|
24
|
-
defaultPage: number;
|
|
25
|
-
dynamicUpdate?: (currentPage: number) => EmbedBuilder;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface TimeoutOptions {
|
|
29
|
-
duration: number;
|
|
30
|
-
disableComponents: boolean;
|
|
31
|
-
onTimeout?: () => void;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface PaginationOptions {
|
|
35
|
-
embedOptions: EmbedOptions;
|
|
36
|
-
timeoutOptions?: TimeoutOptions;
|
|
37
|
-
restrictToUser?: string | null;
|
|
38
|
-
navigationMenu?: boolean;
|
|
39
|
-
loopNavigation?: boolean;
|
|
40
|
-
buttonSettings?: {
|
|
41
|
-
first?: ButtonSettings;
|
|
42
|
-
previous?: ButtonSettings;
|
|
43
|
-
home?: ButtonSettings;
|
|
44
|
-
next?: ButtonSettings;
|
|
45
|
-
last?: ButtonSettings;
|
|
10
|
+
} from "discord.js";
|
|
11
|
+
|
|
12
|
+
interface PagerOptions {
|
|
13
|
+
firstLast?: boolean;
|
|
14
|
+
deleteOption?: boolean;
|
|
15
|
+
otherComponents?: ActionRowBuilder<MessageActionRowComponentBuilder>[];
|
|
16
|
+
home?: {
|
|
17
|
+
home_Option?: boolean;
|
|
18
|
+
home_page?: number;
|
|
46
19
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
autoRefresh?: {
|
|
53
|
-
interval: number;
|
|
54
|
-
updateContent: () => void;
|
|
20
|
+
timeOption?: {
|
|
21
|
+
timeOut?: number;
|
|
22
|
+
disable?: boolean;
|
|
23
|
+
deletes?: boolean;
|
|
24
|
+
custom?: (() => void);
|
|
55
25
|
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
private embedOptions: EmbedOptions;
|
|
60
|
-
private timeoutOptions: TimeoutOptions;
|
|
61
|
-
private restrictToUser: string | null;
|
|
62
|
-
private navigationMenu: boolean;
|
|
63
|
-
private loopNavigation: boolean;
|
|
64
|
-
private buttonSettings: {
|
|
65
|
-
first?: ButtonSettings;
|
|
66
|
-
previous?: ButtonSettings;
|
|
67
|
-
home?: ButtonSettings;
|
|
68
|
-
next?: ButtonSettings;
|
|
69
|
-
last?: ButtonSettings;
|
|
26
|
+
user_only?: {
|
|
27
|
+
user_status?: boolean;
|
|
28
|
+
reply?: string;
|
|
70
29
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
private components: ActionRowBuilder<any>[];
|
|
77
|
-
private message?: Message;
|
|
78
|
-
private autoRefresh?: {
|
|
79
|
-
interval: number;
|
|
80
|
-
updateContent: () => void;
|
|
30
|
+
style?: {
|
|
31
|
+
nextAndBack?: ButtonStyle;
|
|
32
|
+
firstAndLast?: ButtonStyle;
|
|
33
|
+
homeStyle?: ButtonStyle;
|
|
34
|
+
deleteStyle?: ButtonStyle;
|
|
81
35
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
36
|
+
label?: {
|
|
37
|
+
labelNext?: string | null;
|
|
38
|
+
labelBack?: string | null;
|
|
39
|
+
labelFirst?: string | null;
|
|
40
|
+
labelLast?: string | null;
|
|
41
|
+
labelHome?: string | null;
|
|
42
|
+
labelDelete?: string | null;
|
|
43
|
+
};
|
|
44
|
+
emoji?: {
|
|
45
|
+
emojiNext?: string;
|
|
46
|
+
emojiBack?: string;
|
|
47
|
+
emojiFirst?: string;
|
|
48
|
+
emojiLast?: string;
|
|
49
|
+
emojiHome?: string;
|
|
50
|
+
emojiDelete?: string;
|
|
51
|
+
};
|
|
52
|
+
pages?: {
|
|
53
|
+
embeds?: EmbedBuilder[];
|
|
54
|
+
attachment?: (string | Buffer)[];
|
|
55
|
+
content?: string[];
|
|
56
|
+
};
|
|
57
|
+
navigationMenu?: {
|
|
58
|
+
enabled?: boolean;
|
|
59
|
+
placeHolder?: string;
|
|
60
|
+
selects?: string[];
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const CUSTOM_IDS = {
|
|
65
|
+
NEXT: "next-djs-builder",
|
|
66
|
+
BACK: "back-djs-builder",
|
|
67
|
+
FIRST: "first-djs-builder",
|
|
68
|
+
LAST: "last-djs-builder",
|
|
69
|
+
DELETE: "delete-djs-builder",
|
|
70
|
+
HOME: "home-djs-builder",
|
|
71
|
+
SELECT: "select-djs-builder"
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const VALID_BUTTON_STYLES = [
|
|
75
|
+
ButtonStyle.Primary,
|
|
76
|
+
ButtonStyle.Secondary,
|
|
77
|
+
ButtonStyle.Success,
|
|
78
|
+
ButtonStyle.Danger
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
const isValidEmoji = (emoji: string | undefined): boolean => {
|
|
82
|
+
if (!emoji) return false;
|
|
83
|
+
const unicodeEmojiPattern = /^[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F700}-\u{1F77F}\u{1F780}-\u{1F7FF}\u{1F800}-\u{1F8FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA6F}\u{1FA70}-\u{1FAFF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{2300}-\u{23FF}\u{2B50}\u{2934}\u{2935}\u{3030}]+$/u;
|
|
84
|
+
return unicodeEmojiPattern.test(emoji) || /^\d+$/.test(emoji);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export class Pagination {
|
|
88
|
+
private message: Message;
|
|
89
|
+
private options: Required<PagerOptions>;
|
|
90
|
+
private buttons: ButtonBuilder[];
|
|
91
|
+
private components: ActionRowBuilder<MessageActionRowComponentBuilder>[];
|
|
92
|
+
private naw_page: number = 0;
|
|
93
|
+
|
|
94
|
+
constructor(message: Message, options: PagerOptions) {
|
|
95
|
+
this.message = message;
|
|
96
|
+
this.options = {
|
|
97
|
+
firstLast: false,
|
|
98
|
+
deleteOption: false,
|
|
99
|
+
otherComponents: [],
|
|
100
|
+
home: { home_Option: false, home_page: 0 },
|
|
101
|
+
timeOption: { timeOut: 86400000, disable: false, deletes: false, custom: undefined },
|
|
102
|
+
user_only: { user_status: false, reply: "You are not the command owner" },
|
|
103
|
+
style: { nextAndBack: ButtonStyle.Primary, firstAndLast: ButtonStyle.Secondary, homeStyle: ButtonStyle.Success, deleteStyle: ButtonStyle.Danger },
|
|
104
|
+
label: {},
|
|
105
|
+
emoji: { emojiNext: "➡", emojiBack: "⬅", emojiFirst: "⏪", emojiLast: "⏩", emojiHome: "🏠", emojiDelete: "🗑" },
|
|
106
|
+
pages: { embeds: [], attachment: [], content: [] },
|
|
107
|
+
navigationMenu: { enabled: false, placeHolder: "Choose a page", selects: [] },
|
|
108
|
+
...options,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
this.validateOptions();
|
|
112
|
+
this.buttons = this.createButtons();
|
|
113
|
+
this.components = this.createComponents();
|
|
114
|
+
}
|
|
115
|
+
private validateOptions() {
|
|
116
|
+
const { emoji } = this.options;
|
|
117
|
+
if (!Object.values(emoji).every(isValidEmoji)) {
|
|
118
|
+
throw new Error("Invalid emoji format. Must be either Unicode emojis or valid emoji IDs.");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const { style } = this.options;
|
|
122
|
+
if (!Object.values(style).every(style => VALID_BUTTON_STYLES.includes(style))) {
|
|
123
|
+
throw new Error("Invalid button style. Must be one of the predefined ButtonStyle values.");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (this.options.deleteOption && this.options.home?.home_Option) {
|
|
127
|
+
throw new Error("You can't use 'home' and 'delete' together.");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (this.options.timeOption?.disable && this.options.timeOption?.deletes) {
|
|
131
|
+
throw new Error("You can't use 'disable' and 'deletes' together.");
|
|
132
|
+
}
|
|
159
133
|
}
|
|
160
|
-
|
|
161
|
-
private
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
134
|
+
|
|
135
|
+
private createButtons(): ButtonBuilder[] {
|
|
136
|
+
const {
|
|
137
|
+
nextAndBack,
|
|
138
|
+
firstAndLast,
|
|
139
|
+
homeStyle,
|
|
140
|
+
deleteStyle,
|
|
141
|
+
} = this.options.style;
|
|
142
|
+
|
|
143
|
+
const {
|
|
144
|
+
emojiNext,
|
|
145
|
+
emojiBack,
|
|
146
|
+
emojiFirst,
|
|
147
|
+
emojiLast,
|
|
148
|
+
emojiHome,
|
|
149
|
+
emojiDelete,
|
|
150
|
+
} = this.options.emoji;
|
|
151
|
+
|
|
152
|
+
const next = new ButtonBuilder().setCustomId(CUSTOM_IDS.NEXT).setEmoji(emojiNext!).setStyle(nextAndBack!);
|
|
153
|
+
const back = new ButtonBuilder().setCustomId(CUSTOM_IDS.BACK).setEmoji(emojiBack!).setStyle(nextAndBack!);
|
|
154
|
+
const first = new ButtonBuilder().setCustomId(CUSTOM_IDS.FIRST).setEmoji(emojiFirst!).setStyle(firstAndLast!);
|
|
155
|
+
const last = new ButtonBuilder().setCustomId(CUSTOM_IDS.LAST).setEmoji(emojiLast!).setStyle(firstAndLast!);
|
|
156
|
+
const home = new ButtonBuilder().setCustomId(CUSTOM_IDS.HOME).setEmoji(emojiHome!).setStyle(homeStyle!);
|
|
157
|
+
const deleteBtn = new ButtonBuilder().setCustomId(CUSTOM_IDS.DELETE).setEmoji(emojiDelete!).setStyle(deleteStyle!);
|
|
158
|
+
|
|
159
|
+
const {
|
|
160
|
+
labelNext,
|
|
161
|
+
labelBack,
|
|
162
|
+
labelFirst,
|
|
163
|
+
labelLast,
|
|
164
|
+
labelHome,
|
|
165
|
+
labelDelete,
|
|
166
|
+
} = this.options.label;
|
|
167
|
+
|
|
168
|
+
if (labelNext) next.setLabel(labelNext);
|
|
169
|
+
if (labelBack) back.setLabel(labelBack);
|
|
170
|
+
if (labelFirst) first.setLabel(labelFirst);
|
|
171
|
+
if (labelLast) last.setLabel(labelLast);
|
|
172
|
+
if (labelHome) home.setLabel(labelHome);
|
|
173
|
+
if (labelDelete) deleteBtn.setLabel(labelDelete);
|
|
174
|
+
|
|
175
|
+
const buttons: ButtonBuilder[] = [];
|
|
176
|
+
|
|
177
|
+
if (this.options.firstLast) buttons.push(first);
|
|
178
|
+
buttons.push(back);
|
|
179
|
+
if (this.options.home?.home_Option) buttons.push(home);
|
|
180
|
+
else if (this.options.deleteOption) buttons.push(deleteBtn);
|
|
181
|
+
buttons.push(next);
|
|
182
|
+
if (this.options.firstLast) buttons.push(last);
|
|
183
|
+
|
|
184
|
+
return buttons;
|
|
183
185
|
}
|
|
184
|
-
|
|
185
|
-
private
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
186
|
+
|
|
187
|
+
private createComponents(): ActionRowBuilder<MessageActionRowComponentBuilder>[] {
|
|
188
|
+
const buttonRow = new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(this.buttons);
|
|
189
|
+
|
|
190
|
+
const otherRows = this.options.otherComponents || [];
|
|
191
|
+
const selectMenus = this.options.navigationMenu?.enabled ? this.createSelectMenus() : [];
|
|
192
|
+
|
|
193
|
+
return [buttonRow, ...selectMenus, ...otherRows];
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private createSelectMenus(): ActionRowBuilder<StringSelectMenuBuilder>[] {
|
|
197
|
+
const { embeds = [], content = [], attachment = [] } = this.options.pages || {};
|
|
198
|
+
const longest_length = Math.max(embeds.length, content.length, attachment.length);
|
|
199
|
+
const selectMenus: ActionRowBuilder<StringSelectMenuBuilder>[] = [];
|
|
200
|
+
const select_status = this.options.navigationMenu?.enabled;
|
|
201
|
+
const select_placeholder = this.options.navigationMenu?.placeHolder;
|
|
202
|
+
const selects = this.options.navigationMenu?.selects || [];
|
|
203
|
+
|
|
204
|
+
if (select_status) {
|
|
205
|
+
for (let i = 0; i < longest_length; i += 25) {
|
|
206
|
+
const menuOptions = Array.from({ length: Math.min(25, longest_length - i) }, (_, j) => ({
|
|
207
|
+
label: selects[i + j] ? selects[i + j] : `Page ${i + j + 1}`,
|
|
208
|
+
value: `${i + j}`
|
|
209
|
+
}));
|
|
210
|
+
|
|
211
|
+
const selectMenu = new StringSelectMenuBuilder()
|
|
212
|
+
.setCustomId(`select_${i}`)
|
|
213
|
+
.setPlaceholder(select_placeholder || "Choose a page")
|
|
214
|
+
.addOptions(menuOptions);
|
|
215
|
+
|
|
216
|
+
selectMenus.push(new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(selectMenu));
|
|
217
|
+
}
|
|
189
218
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (settings?.emoji) {
|
|
200
|
-
button.setEmoji(settings.emoji);
|
|
219
|
+
|
|
220
|
+
return selectMenus;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
public async send() {
|
|
224
|
+
const { embeds = [], content = [], attachment = [] } = this.options.pages || {};
|
|
225
|
+
|
|
226
|
+
if (embeds.length === 0) {
|
|
227
|
+
throw new Error("No embeds provided.");
|
|
201
228
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
229
|
+
|
|
230
|
+
try {
|
|
231
|
+
const msg = await this.message.reply({
|
|
232
|
+
embeds: [embeds[0]],
|
|
233
|
+
content: content[0] || "",
|
|
234
|
+
files: attachment[0] ? [attachment[0]] : [],
|
|
235
|
+
components: this.components,
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
const collector = this.createCollector(msg);
|
|
239
|
+
collector.on("collect", async (i: MessageComponentInteraction) => this.handleCollect(i));
|
|
240
|
+
collector.on("end", async () => this.handleEnd(msg));
|
|
241
|
+
} catch (error) {
|
|
242
|
+
console.error("Error sending message:", error);
|
|
216
243
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
private createCollector(msg: Message) {
|
|
247
|
+
const filter = this.options.user_only?.user_status
|
|
248
|
+
? async (i: MessageComponentInteraction) => {
|
|
249
|
+
if (i.user.id !== this.message.author.id) {
|
|
250
|
+
await i.reply({ content: this.options.user_only.reply!, ephemeral: true });
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
: undefined;
|
|
256
|
+
|
|
257
|
+
return msg.createMessageComponentCollector({
|
|
258
|
+
filter,
|
|
259
|
+
time: this.options.timeOption?.timeOut || 86400000,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
private async handleCollect(i: MessageComponentInteraction) {
|
|
264
|
+
const { embeds = [], content = [], attachment = [] } = this.options.pages || {};
|
|
265
|
+
const num = embeds.length;
|
|
266
|
+
|
|
267
|
+
try {
|
|
268
|
+
if (i.isButton()) {
|
|
269
|
+
switch (i.customId) {
|
|
270
|
+
case CUSTOM_IDS.NEXT:
|
|
271
|
+
this.naw_page = (this.naw_page + 1) % num;
|
|
238
272
|
break;
|
|
239
|
-
|
|
240
|
-
this.
|
|
273
|
+
case CUSTOM_IDS.BACK:
|
|
274
|
+
this.naw_page = (this.naw_page - 1 + num) % num;
|
|
241
275
|
break;
|
|
242
|
-
|
|
243
|
-
this.
|
|
276
|
+
case CUSTOM_IDS.FIRST:
|
|
277
|
+
this.naw_page = 0;
|
|
244
278
|
break;
|
|
245
|
-
|
|
246
|
-
this.
|
|
279
|
+
case CUSTOM_IDS.LAST:
|
|
280
|
+
this.naw_page = num - 1;
|
|
247
281
|
break;
|
|
248
|
-
|
|
282
|
+
case CUSTOM_IDS.DELETE:
|
|
283
|
+
await i.message.delete();
|
|
284
|
+
return;
|
|
285
|
+
case CUSTOM_IDS.HOME:
|
|
286
|
+
this.naw_page = this.options.home?.home_page || 0;
|
|
249
287
|
break;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (this.message) {
|
|
253
|
-
await interaction.deferUpdate();
|
|
254
|
-
await this.message.edit({
|
|
255
|
-
embeds: [this.getEmbed()],
|
|
256
|
-
components: this.components,
|
|
257
|
-
content: this.content ?? undefined,
|
|
258
|
-
files: this.attachments.length ? this.attachments : undefined,
|
|
259
|
-
});
|
|
260
|
-
} else if (this.channel) {
|
|
261
|
-
this.message = await this.channel.send({
|
|
262
|
-
embeds: [this.getEmbed()],
|
|
263
|
-
components: this.components,
|
|
264
|
-
content: this.content ?? undefined,
|
|
265
|
-
files: this.attachments.length ? this.attachments : undefined,
|
|
266
|
-
});
|
|
267
|
-
this.createCollector(this.message);
|
|
268
|
-
} else if (this.context) {
|
|
269
|
-
// @ts-ignore
|
|
270
|
-
this.message = await this.context.reply({
|
|
271
|
-
embeds: [this.getEmbed()],
|
|
272
|
-
components: this.components,
|
|
273
|
-
content: this.content ?? undefined,
|
|
274
|
-
files: this.attachments.length ? this.attachments : undefined,
|
|
275
|
-
}) as Message;
|
|
276
|
-
// @ts-ignore
|
|
277
|
-
this.message = await this.context.fetchReply() as Message;
|
|
278
|
-
this.createCollector(this.message);
|
|
279
|
-
} else {
|
|
280
|
-
throw new Error('You must specify either a context or a channel.');
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
public async send(): Promise<void> {
|
|
285
|
-
if (this.context || this.channel) {
|
|
286
|
-
// @ts-ignore
|
|
287
|
-
await this.handleInteraction({ customId: '', values: [] } as ButtonInteraction);
|
|
288
|
-
} else {
|
|
289
|
-
throw new Error('You must specify either a context or a channel.');
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
private createCollector(message: Message): void {
|
|
294
|
-
const collector = message.createMessageComponentCollector({
|
|
295
|
-
filter: (i) => i.isButton() || i.isStringSelectMenu(),
|
|
296
|
-
time: this.timeoutOptions.duration,
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
collector.on('collect', async (interaction) => {
|
|
300
|
-
if (interaction.isButton() || interaction.isStringSelectMenu()) {
|
|
301
|
-
await this.handleInteraction(interaction);
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
collector.on('end', async () => {
|
|
306
|
-
if (this.timeoutOptions.onTimeout) {
|
|
307
|
-
this.timeoutOptions.onTimeout();
|
|
308
288
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
await message.edit({
|
|
313
|
-
// @ts-ignore
|
|
314
|
-
components: this.components.map((row) =>
|
|
315
|
-
row.components.map((component) => component.setDisabled(true))
|
|
316
|
-
),
|
|
317
|
-
});
|
|
289
|
+
} else if (i.isStringSelectMenu()) {
|
|
290
|
+
if (i.customId === "select-djs-builder") {
|
|
291
|
+
this.naw_page = parseInt(i.values[0], 10);
|
|
318
292
|
}
|
|
319
|
-
|
|
293
|
+
}
|
|
294
|
+
await i.update({
|
|
295
|
+
embeds: [embeds[this.naw_page]],
|
|
296
|
+
content: content[this.naw_page] || "",
|
|
297
|
+
files: attachment[this.naw_page] ? [attachment[this.naw_page]] : [],
|
|
298
|
+
components: this.createComponents(),
|
|
299
|
+
});
|
|
300
|
+
} catch (error) {
|
|
301
|
+
console.error("Error handling interaction:", error);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
private async handleEnd(msg: Message) {
|
|
306
|
+
try {
|
|
307
|
+
if (this.options.timeOption?.disable) {
|
|
308
|
+
this.components[0].components.forEach((button) => button.setDisabled(true));
|
|
309
|
+
await msg.edit({ components: this.components });
|
|
310
|
+
}
|
|
311
|
+
if (this.options.timeOption?.deletes) {
|
|
312
|
+
await msg.edit({ components: [] });
|
|
313
|
+
}
|
|
314
|
+
if (typeof this.options.timeOption?.custom === "function") {
|
|
315
|
+
this.options.timeOption.custom();
|
|
316
|
+
}
|
|
317
|
+
} catch (error) {
|
|
318
|
+
console.error("Error handling end of collector:", error);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
320
321
|
}
|
|
321
|
-
|
|
322
|
+
|
|
@@ -123,6 +123,7 @@ export async function loadEvents(client: any, eventsOptions: EventsOptions) {
|
|
|
123
123
|
|
|
124
124
|
const eventCount = await countEventFiles(eventsOptions.path, eventsOptions);
|
|
125
125
|
client.eventSize = eventCount;
|
|
126
|
+
|
|
126
127
|
} catch (error: any) {
|
|
127
128
|
logError(`Error while loading events from path: ${eventsOptions.path}`);
|
|
128
129
|
logError(error.message, error);
|