xernerx 3.5.1 → 3.6.0

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.
Files changed (121) hide show
  1. package/dist/{build → cjs/build}/ContextCommandBuilder.d.ts +31 -28
  2. package/dist/cjs/build/ContextCommandBuilder.js +97 -0
  3. package/dist/cjs/build/EventBuilder.js +44 -0
  4. package/dist/{build → cjs/build}/InhibitorBuilder.d.ts +1 -1
  5. package/dist/cjs/build/InhibitorBuilder.js +37 -0
  6. package/dist/{build → cjs/build}/MessageCommandBuilder.d.ts +23 -17
  7. package/dist/cjs/build/MessageCommandBuilder.js +100 -0
  8. package/dist/{build → cjs/build}/SlashCommandBuilder.d.ts +25 -18
  9. package/dist/cjs/build/SlashCommandBuilder.js +169 -0
  10. package/dist/{client → cjs/client}/XernerxClient.d.ts +1 -0
  11. package/dist/cjs/client/XernerxClient.js +120 -0
  12. package/dist/{handlers → cjs/handlers}/CommandHandler.js +11 -8
  13. package/dist/{handlers → cjs/handlers}/EventHandler.js +6 -3
  14. package/dist/cjs/handlers/Handler.js +308 -0
  15. package/dist/{handlers → cjs/handlers}/InhibitorHandler.js +6 -3
  16. package/dist/cjs/handlers/WebhookHandler.d.ts +7 -0
  17. package/dist/cjs/handlers/WebhookHandler.js +23 -0
  18. package/dist/{main.d.ts → cjs/main.d.ts} +15 -1
  19. package/dist/cjs/main.js +112 -0
  20. package/dist/{models → cjs/models}/CommandArguments.d.ts +1 -1
  21. package/dist/{models → cjs/models}/CommandArguments.js +37 -52
  22. package/dist/cjs/models/Events.js +309 -0
  23. package/dist/cjs/models/Extensions.js +26 -0
  24. package/dist/cjs/models/XernerxUser.d.ts +2 -0
  25. package/dist/cjs/models/XernerxUser.js +12 -0
  26. package/dist/{tools → cjs/tools}/XernerxError.js +4 -1
  27. package/dist/{tools → cjs/tools}/package.d.ts +4 -9
  28. package/dist/{tools → cjs/tools}/package.js +14 -17
  29. package/dist/cjs/types/enums.d.ts +44 -0
  30. package/dist/cjs/types/enums.js +38 -0
  31. package/dist/{types → cjs/types}/interfaces.d.ts +2 -0
  32. package/dist/cjs/types/interfaces.js +2 -0
  33. package/dist/{types → cjs/types}/options.d.ts +13 -0
  34. package/dist/cjs/types/options.js +2 -0
  35. package/dist/{types → cjs/types}/types.d.ts +38 -10
  36. package/dist/cjs/types/types.js +2 -0
  37. package/dist/{utils → cjs/utils}/ClientUtil.d.ts +1 -0
  38. package/dist/{utils → cjs/utils}/ClientUtil.js +73 -84
  39. package/dist/{utils → cjs/utils}/CommandUtil.d.ts +4 -2
  40. package/dist/{utils → cjs/utils}/CommandUtil.js +102 -103
  41. package/dist/{validators → cjs/validators}/CommandValidations.d.ts +6 -1
  42. package/dist/{validators → cjs/validators}/CommandValidations.js +36 -50
  43. package/dist/{validators → cjs/validators}/InhibitorValidations.js +12 -14
  44. package/dist/mjs/build/ContextCommandBuilder.d.ts +63 -0
  45. package/dist/mjs/build/ContextCommandBuilder.js +97 -0
  46. package/dist/mjs/build/EventBuilder.d.ts +21 -0
  47. package/dist/mjs/build/EventBuilder.js +44 -0
  48. package/dist/mjs/build/InhibitorBuilder.d.ts +19 -0
  49. package/dist/mjs/build/InhibitorBuilder.js +37 -0
  50. package/dist/mjs/build/MessageCommandBuilder.d.ts +59 -0
  51. package/dist/mjs/build/MessageCommandBuilder.js +100 -0
  52. package/dist/mjs/build/SlashCommandBuilder.d.ts +65 -0
  53. package/dist/mjs/build/SlashCommandBuilder.js +169 -0
  54. package/dist/mjs/client/XernerxClient.d.ts +29 -0
  55. package/dist/mjs/client/XernerxClient.js +120 -0
  56. package/dist/mjs/handlers/CommandHandler.d.ts +27 -0
  57. package/dist/mjs/handlers/CommandHandler.js +45 -0
  58. package/dist/mjs/handlers/EventHandler.d.ts +13 -0
  59. package/dist/mjs/handlers/EventHandler.js +19 -0
  60. package/dist/mjs/handlers/Handler.d.ts +57 -0
  61. package/dist/mjs/handlers/Handler.js +308 -0
  62. package/dist/mjs/handlers/InhibitorHandler.d.ts +18 -0
  63. package/dist/mjs/handlers/InhibitorHandler.js +24 -0
  64. package/dist/mjs/handlers/WebhookHandler.d.ts +7 -0
  65. package/dist/mjs/handlers/WebhookHandler.js +23 -0
  66. package/dist/{main.js → mjs/main.d.ts} +20 -18
  67. package/dist/mjs/main.js +112 -0
  68. package/dist/mjs/models/CommandArguments.d.ts +17 -0
  69. package/dist/mjs/models/CommandArguments.js +106 -0
  70. package/dist/mjs/models/Events.d.ts +24 -0
  71. package/dist/mjs/models/Events.js +309 -0
  72. package/dist/mjs/models/Extensions.d.ts +7 -0
  73. package/dist/mjs/models/Extensions.js +26 -0
  74. package/dist/mjs/models/XernerxUser.d.ts +2 -0
  75. package/dist/mjs/models/XernerxUser.js +12 -0
  76. package/dist/mjs/tools/XernerxError.d.ts +5 -0
  77. package/dist/mjs/tools/XernerxError.js +11 -0
  78. package/dist/mjs/tools/package.d.ts +44 -0
  79. package/dist/mjs/tools/package.js +45 -0
  80. package/dist/mjs/types/enums.d.ts +44 -0
  81. package/dist/mjs/types/enums.js +38 -0
  82. package/dist/mjs/types/interfaces.d.ts +27 -0
  83. package/dist/mjs/types/interfaces.js +2 -0
  84. package/dist/mjs/types/options.d.ts +254 -0
  85. package/dist/mjs/types/options.js +2 -0
  86. package/dist/mjs/types/types.d.ts +62 -0
  87. package/dist/mjs/types/types.js +2 -0
  88. package/dist/mjs/utils/ClientUtil.d.ts +26 -0
  89. package/dist/mjs/utils/ClientUtil.js +211 -0
  90. package/dist/mjs/utils/CommandUtil.d.ts +58 -0
  91. package/dist/mjs/utils/CommandUtil.js +247 -0
  92. package/dist/mjs/validators/CommandValidations.d.ts +12 -0
  93. package/dist/mjs/validators/CommandValidations.js +169 -0
  94. package/dist/mjs/validators/InhibitorValidations.d.ts +11 -0
  95. package/dist/mjs/validators/InhibitorValidations.js +40 -0
  96. package/package.json +11 -15
  97. package/dist/build/ContextCommandBuilder.js +0 -93
  98. package/dist/build/EventBuilder.js +0 -34
  99. package/dist/build/InhibitorBuilder.js +0 -27
  100. package/dist/build/MessageCommandBuilder.js +0 -90
  101. package/dist/build/SlashCommandBuilder.js +0 -125
  102. package/dist/client/XernerxClient.js +0 -101
  103. package/dist/handlers/Handler.js +0 -250
  104. package/dist/main.cjs +0 -2023
  105. package/dist/models/Events.js +0 -294
  106. package/dist/models/Extensions.js +0 -23
  107. package/dist/types/enums.d.ts +0 -35
  108. package/dist/types/enums.js +0 -35
  109. package/dist/types/interfaces.js +0 -1
  110. package/dist/types/options.js +0 -1
  111. package/dist/types/types.js +0 -1
  112. package/dist/validators/Shapes.js +0 -1
  113. /package/dist/{build → cjs/build}/EventBuilder.d.ts +0 -0
  114. /package/dist/{handlers → cjs/handlers}/CommandHandler.d.ts +0 -0
  115. /package/dist/{handlers → cjs/handlers}/EventHandler.d.ts +0 -0
  116. /package/dist/{handlers → cjs/handlers}/Handler.d.ts +0 -0
  117. /package/dist/{handlers → cjs/handlers}/InhibitorHandler.d.ts +0 -0
  118. /package/dist/{models → cjs/models}/Events.d.ts +0 -0
  119. /package/dist/{models → cjs/models}/Extensions.d.ts +0 -0
  120. /package/dist/{tools → cjs/tools}/XernerxError.d.ts +0 -0
  121. /package/dist/{validators → cjs/validators}/InhibitorValidations.d.ts +0 -0
@@ -0,0 +1,211 @@
1
+ 'use strict';
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
7
+ Object.defineProperty(exports, '__esModule', { value: true });
8
+ exports.ClientUtil = void 0;
9
+ const XernerxError_js_1 = __importDefault(require('../tools/XernerxError.js'));
10
+ class ClientUtil {
11
+ client;
12
+ constructor(client) {
13
+ this.client = client;
14
+ }
15
+ uptime(timestamp) {
16
+ if (!timestamp) timestamp = this.client.uptime || 0;
17
+ let totalSeconds = timestamp / 1000;
18
+ let years = Math.floor(totalSeconds / 31536000);
19
+ totalSeconds %= 31536000;
20
+ let days = Math.floor(totalSeconds / 86400);
21
+ totalSeconds %= 86400;
22
+ let hours = Math.floor(totalSeconds / 3600);
23
+ totalSeconds %= 3600;
24
+ let minutes = Math.floor(totalSeconds / 60);
25
+ let seconds = Math.floor(totalSeconds % 60);
26
+ if (years >= 1) return `${years}y ${days}d ${hours}h ${minutes}m`;
27
+ else if (days >= 1) return `${days}d ${hours}h ${minutes}m`;
28
+ else if (hours >= 1) return `${hours}h ${minutes}m`;
29
+ else if (minutes >= 1) return `${minutes}m ${seconds}s`;
30
+ else return `${seconds}s`;
31
+ }
32
+ getSubcommands(name) {
33
+ if (!name || typeof name !== 'string') throw new XernerxError_js_1.default(`Expected name to be of type string, received ${typeof name} instead!`);
34
+ const commands = [];
35
+ this.getAllCommands()
36
+ .filter((c) => (c.data?.name?.toLowerCase() || c.name?.toLowerCase()) == name?.toLowerCase())
37
+ .map((c) => {
38
+ if (c?.data?.options?.length > 0) {
39
+ c?.data?.options?.map((option) => {
40
+ if (!option?.type) {
41
+ if (option?.options?.length > 0) {
42
+ option?.options?.map((opt) => {
43
+ if (!opt.type) {
44
+ commands.push({
45
+ name: c.data.name,
46
+ formattedName: `${c.data.name} ${option.name} ${opt.name}`,
47
+ description: opt.description,
48
+ category: c.category || null,
49
+ commandType: c.commandType,
50
+ });
51
+ } else {
52
+ commands.push({
53
+ name: c.data.name,
54
+ formattedName: `${c.data.name} ${option.name}`,
55
+ description: option.description,
56
+ category: c.category || null,
57
+ commandType: c.commandType,
58
+ });
59
+ }
60
+ });
61
+ } else {
62
+ commands.push({
63
+ name: c.data.name,
64
+ formattedName: `${c.data.name} ${option.name}`,
65
+ description: option.description,
66
+ category: c.category || null,
67
+ commandType: c.commandType,
68
+ });
69
+ }
70
+ } else {
71
+ commands.push({
72
+ name: c.data.name,
73
+ formattedName: `${c.data.name}`,
74
+ description: c.data.description,
75
+ category: c.category || null,
76
+ commandType: c.commandType,
77
+ });
78
+ }
79
+ });
80
+ } else {
81
+ commands.push({
82
+ name: c.data?.name || c.name,
83
+ formattedName: `${c.data?.name || c.name}`,
84
+ description: c.data?.description || c.description,
85
+ category: c.category || null,
86
+ commandType: c.commandType,
87
+ });
88
+ }
89
+ });
90
+ return commands;
91
+ }
92
+ isOwner(userId) {
93
+ if (!userId) throw new XernerxError_js_1.default('No ID specified');
94
+ let owners = this.client.settings.ownerId;
95
+ if (!owners) return false;
96
+ if (typeof owners === 'string') owners = [owners];
97
+ return owners.includes(userId);
98
+ }
99
+ getAllCommands() {
100
+ const cmds = [];
101
+ for (const commands of Object.values(this.client.commands)) {
102
+ commands.map((cmd) => cmds.push(cmd));
103
+ }
104
+ return cmds;
105
+ }
106
+ getAllMessageCommands() {
107
+ const cmds = [];
108
+ this.client.commands.message.map((cmd) => cmds.push(cmd));
109
+ return cmds;
110
+ }
111
+ getAllSlashCommands() {
112
+ const cmds = [];
113
+ this.client.commands.slash.map((cmd) => cmds.push(cmd));
114
+ return cmds;
115
+ }
116
+ getAllContextCommands() {
117
+ const cmds = [];
118
+ this.client.commands.context.map((cmd) => cmds.push(cmd));
119
+ return cmds;
120
+ }
121
+ setPresence(options) {
122
+ const client = this.client;
123
+ function pres() {
124
+ client.user?.setPresence({
125
+ activities: [
126
+ {
127
+ name: options.text || undefined,
128
+ type: options.type || undefined,
129
+ url: options.link || undefined,
130
+ },
131
+ ],
132
+ status: options.status || undefined,
133
+ });
134
+ }
135
+ pres();
136
+ if (options.interval) {
137
+ setInterval(() => {
138
+ pres();
139
+ }, options.interval);
140
+ }
141
+ }
142
+ getCooldowns(id, command) {
143
+ let cooldowns = [];
144
+ for (const [key, value] of Object.entries(this.client.cache)) {
145
+ if (!['cooldowns', 'messageCommands', 'slashCommands', 'contextCommands', 'commands'].includes(key)) continue;
146
+ if (key === 'commands') {
147
+ if (command) {
148
+ value.map((x) => {
149
+ const name = x.name.split(/-/);
150
+ name.pop();
151
+ if (name.join('-') === id + '-' + command) {
152
+ cooldowns.push(x);
153
+ }
154
+ });
155
+ } else {
156
+ value.map((x) => {
157
+ if (x.name.split(/-/).shift() === id) {
158
+ cooldowns.push(x);
159
+ }
160
+ });
161
+ }
162
+ } else {
163
+ if (value.has(id)) {
164
+ const x = value.get(id);
165
+ cooldowns.push(x);
166
+ }
167
+ }
168
+ }
169
+ return cooldowns;
170
+ }
171
+ getCooldownTimers(id, command) {
172
+ let cooldowns = [];
173
+ for (const [key, value] of Object.entries(this.client.cache)) {
174
+ if (!['cooldowns', 'messageCommands', 'slashCommands', 'contextCommands', 'commands'].includes(key)) continue;
175
+ if (key === 'commands') {
176
+ if (command) {
177
+ value.map((x) => {
178
+ const name = x.name.split(/-/);
179
+ name.pop();
180
+ if (name.join('-') === id + '-' + command) {
181
+ cooldowns.push({
182
+ [x.commandName]: x.endsAt - Date.now(),
183
+ });
184
+ }
185
+ });
186
+ } else {
187
+ value.map((x) => {
188
+ if (x.name.split(/-/).shift() === id) {
189
+ cooldowns.push({
190
+ [x.commandName]: x.endsAt - Date.now(),
191
+ });
192
+ }
193
+ });
194
+ }
195
+ } else {
196
+ if (value.has(id)) {
197
+ const x = value.get(id);
198
+ cooldowns.push({ [key]: x.endsAt - Date.now() });
199
+ }
200
+ }
201
+ }
202
+ const sort = cooldowns.map((x) => Object.entries(x).shift()).sort((a, b) => b[1] - a[1]);
203
+ cooldowns = [];
204
+ sort.map(([key, value]) => cooldowns.push({ [key]: value }));
205
+ return cooldowns;
206
+ }
207
+ async defer(time) {
208
+ return new Promise((resolve) => setTimeout(resolve, time || 0));
209
+ }
210
+ }
211
+ exports.ClientUtil = ClientUtil;
@@ -0,0 +1,58 @@
1
+ import { ActionRowBuilder, ButtonBuilder, EmbedBuilder, Interaction, Message, MessagePayload, StringSelectMenuBuilder } from 'discord.js';
2
+ import XernerxClient from '../client/XernerxClient.js';
3
+ import { XernerxMessage } from '../types/types.js';
4
+ interface SelectMenuOptions {
5
+ index?: EmbedBuilder;
6
+ row?: ActionRowBuilder;
7
+ component?: StringSelectMenuBuilder;
8
+ components?: object[];
9
+ reply?: boolean;
10
+ id?: string;
11
+ filter?: Function;
12
+ time?: number;
13
+ ephemeral?: boolean;
14
+ }
15
+ interface ButtonOptions {
16
+ index?: number;
17
+ buttons?: Array<string>;
18
+ reply?: boolean;
19
+ row?: ActionRowBuilder;
20
+ component?: ButtonBuilder;
21
+ components?: object[];
22
+ id?: string;
23
+ filter?: any;
24
+ time?: number;
25
+ ephemeral?: boolean;
26
+ }
27
+ export declare class MessageCommandUtil {
28
+ client: XernerxClient;
29
+ message: XernerxMessage;
30
+ constructor(client: XernerxClient, message: Message & XernerxMessage);
31
+ reply(content: MessagePayload | string): Promise<Message<boolean> | undefined>;
32
+ send(content: MessagePayload | string): Promise<Message<true> | Message<false> | undefined>;
33
+ defer(time: number): Promise<unknown>;
34
+ getCommands(): import('@discordjs/collection').Collection<string, import('../main.js').MessageCommandBuilder>;
35
+ getCommandName(): void;
36
+ selectMenuPaginator(embeds: Array<EmbedBuilder>, options?: SelectMenuOptions): void;
37
+ buttonPaginator(embeds: Array<EmbedBuilder>, options: ButtonOptions): void;
38
+ buttonMenuPaginator(embeds: Array<EmbedBuilder>, options: ButtonOptions & SelectMenuOptions): void;
39
+ isOwner(): boolean;
40
+ createModal(): void;
41
+ }
42
+ export declare class InteractionCommandUtil {
43
+ client: XernerxClient;
44
+ interaction: any;
45
+ constructor(client: XernerxClient, interaction: Interaction);
46
+ reply(content: MessagePayload | string): any;
47
+ defer(time: number): Promise<unknown>;
48
+ getCommands():
49
+ | import('@discordjs/collection').Collection<string, import('../main.js').SlashCommandBuilder>
50
+ | import('@discordjs/collection').Collection<string, import('../main.js').ContextCommandBuilder>;
51
+ getCommandName(): void;
52
+ selectMenuPaginator(embeds: Array<EmbedBuilder>, options?: SelectMenuOptions): void;
53
+ buttonPaginator(embeds: Array<EmbedBuilder>, options: ButtonOptions): void;
54
+ buttonMenuPaginator(embeds: Array<EmbedBuilder>, options: ButtonOptions & SelectMenuOptions): void;
55
+ isOwner(): boolean;
56
+ createModal(): void;
57
+ }
58
+ export {};
@@ -0,0 +1,247 @@
1
+ 'use strict';
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
7
+ Object.defineProperty(exports, '__esModule', { value: true });
8
+ exports.InteractionCommandUtil = exports.MessageCommandUtil = void 0;
9
+ const discord_js_1 = require('discord.js');
10
+ const XernerxError_js_1 = __importDefault(require('../tools/XernerxError.js'));
11
+ class MessageCommandUtil {
12
+ client;
13
+ message;
14
+ constructor(client, message) {
15
+ this.client = client;
16
+ this.message = message;
17
+ }
18
+ async reply(content) {
19
+ if (this.client.cache.messages.has(this.message.id)) var existingMessage = this.client.cache.messages.get(this.message.id);
20
+ if (!existingMessage) {
21
+ const msg = await this.message.reply(content);
22
+ this.message.response = msg.id;
23
+ if (this.client.handlerOptions.message?.handleEdits || this.client.handlerOptions.message?.handleDeletes) {
24
+ this.client.cache.messages.set(this.message.id, this.message);
25
+ setInterval(() => {
26
+ this.client.cache.messages.delete(this.message.id);
27
+ }, this.client.settings.cooldown?.cache || 300000);
28
+ }
29
+ return msg;
30
+ }
31
+ if (existingMessage && this.client.handlerOptions.message?.handleEdits) {
32
+ try {
33
+ const msg = await this.message.channel.messages.fetch(existingMessage.response);
34
+ msg.edit(content);
35
+ return msg;
36
+ } catch {
37
+ const msg = await this.message.reply(content);
38
+ this.message.response = msg.id;
39
+ if (this.client.handlerOptions.message?.handleEdits || this.client.handlerOptions.message?.handleDeletes) {
40
+ this.client.cache.messages.set(this.message.id, this.message);
41
+ setInterval(() => {
42
+ this.client.cache.messages.delete(this.message.id);
43
+ }, this.client.settings.cooldown?.cache || 300000);
44
+ }
45
+ }
46
+ }
47
+ }
48
+ async send(content) {
49
+ if (this.client.cache.messages.has(this.message.id)) var existingMessage = this.client.cache.messages.get(this.message.id);
50
+ if (!existingMessage) {
51
+ const msg = await this.message.channel.send(content);
52
+ this.message.response = msg.id;
53
+ if (this.client.handlerOptions.message?.handleEdits || this.client.handlerOptions.message?.handleDeletes) {
54
+ this.client.cache.messages.set(this.message.id, this.message);
55
+ setInterval(() => {
56
+ this.client.cache.messages.delete(this.message.id);
57
+ }, this.client.settings.cooldown?.cache || 300000);
58
+ }
59
+ return msg;
60
+ }
61
+ if (existingMessage && this.client.handlerOptions.message?.handleEdits) {
62
+ try {
63
+ const msg = await this.message.channel.messages.fetch(existingMessage.response);
64
+ msg.edit(content);
65
+ return msg;
66
+ } catch {
67
+ const msg = await this.message.channel.send(content);
68
+ this.message.response = msg.id;
69
+ if (this.client.handlerOptions.message?.handleEdits || this.client.handlerOptions.message?.handleDeletes) {
70
+ this.client.cache.messages.set(this.message.id, this.message);
71
+ setInterval(() => {
72
+ this.client.cache.messages.delete(this.message.id);
73
+ }, this.client.settings.cooldown?.cache || 300000);
74
+ }
75
+ }
76
+ }
77
+ }
78
+ async defer(time) {
79
+ return new Promise((resolve) => setTimeout(resolve, time));
80
+ }
81
+ getCommands() {
82
+ return this.client.commands.message;
83
+ }
84
+ getCommandName() {}
85
+ selectMenuPaginator(embeds, options) {}
86
+ buttonPaginator(embeds, options) {}
87
+ buttonMenuPaginator(embeds, options) {}
88
+ isOwner() {
89
+ return this.client.util.isOwner(this.message.author.id);
90
+ }
91
+ createModal() {}
92
+ }
93
+ exports.MessageCommandUtil = MessageCommandUtil;
94
+ class InteractionCommandUtil {
95
+ client;
96
+ interaction;
97
+ constructor(client, interaction) {
98
+ this.client = client;
99
+ this.interaction = interaction;
100
+ }
101
+ reply(content) {
102
+ return this.interaction.replied || this.interaction.deferred ? this.interaction.editReply(content) : this.interaction.reply(content);
103
+ }
104
+ async defer(time) {
105
+ return new Promise((resolve) => setTimeout(resolve, time));
106
+ }
107
+ getCommands() {
108
+ if (this.interaction.commandType === 1) return this.client.commands.slash;
109
+ else return this.client.commands.context;
110
+ }
111
+ getCommandName() {}
112
+ selectMenuPaginator(embeds, options) {
113
+ if (!Array.isArray(embeds)) throw new XernerxError_js_1.default(`Expected embeds to be of type array, received ${typeof embeds} instead.`);
114
+ if (embeds.length > 25) throw new XernerxError_js_1.default(`Max select menu length is 25.`);
115
+ if (typeof options !== 'object') options = {};
116
+ if (!Array.isArray(options.components)) options.components = [];
117
+ if (!options.index) {
118
+ options.index = new discord_js_1.EmbedBuilder().setTitle('Index').setColor('Random');
119
+ for (const embed of embeds) {
120
+ options.index.addFields([
121
+ {
122
+ name: embed.data.title || 'No Name',
123
+ value: embed.data.description || 'Page',
124
+ inline: embeds.length > 25 / 2 ? true : false,
125
+ },
126
+ ]);
127
+ }
128
+ }
129
+ if (!options.row) {
130
+ options.row = new discord_js_1.ActionRowBuilder();
131
+ if (!options.id) options.id = `${this.interaction.id}-menu`;
132
+ options.component = new discord_js_1.StringSelectMenuBuilder()
133
+ .setCustomId(options.id)
134
+ .setMaxValues(1)
135
+ .setMinValues(1)
136
+ .setPlaceholder('Select a page.')
137
+ .addOptions({ label: 'index', value: '0' });
138
+ embeds.map((embed, i = 0) => {
139
+ options?.component?.addOptions({
140
+ label: embed.data.title || 'No Name',
141
+ description: embed.data.description || `Page ${i}`,
142
+ value: String(i + 1),
143
+ });
144
+ });
145
+ options.row.addComponents(options.component);
146
+ }
147
+ embeds.unshift(options.index);
148
+ const content = {
149
+ embeds: [options.index],
150
+ components: [options.row, ...options.components],
151
+ ephemeral: !!options.ephemeral,
152
+ };
153
+ (options.reply === undefined || options.reply === true ? this.interaction.util.reply(content) : this.interaction.channel.send(content)).then(() => {
154
+ const collector = this.interaction.channel
155
+ .createMessageComponentCollector({
156
+ filter: options?.filter,
157
+ time: options?.time || 60000,
158
+ })
159
+ .on('collect', (interaction) => {
160
+ if (!interaction.customId.startsWith(this.interaction.id)) return;
161
+ interaction.update({
162
+ embeds: [embeds[parseInt(interaction.values[0])]],
163
+ });
164
+ })
165
+ .on('end', () => {
166
+ this.interaction.editReply({ components: [] });
167
+ });
168
+ });
169
+ }
170
+ buttonPaginator(embeds, options) {
171
+ if (!Array.isArray(embeds)) throw new XernerxError_js_1.default(`Expected embeds to be of type array, received ${typeof embeds} instead.`);
172
+ if (embeds.length <= 0) throw new XernerxError_js_1.default(`The minimum embeds is 1.`);
173
+ if (typeof options !== 'object') options = {};
174
+ if (!Array.isArray(options.components)) options.components = [];
175
+ if (!options.row) {
176
+ options.row = new discord_js_1.ActionRowBuilder();
177
+ if (!options.id) options.id = `${this.interaction.id}-menu`;
178
+ }
179
+ if (!options.buttons) options.buttons = ['⏮️', '◀️', '⏹️', '▶️', '⏭️'];
180
+ for (const button of options.buttons) {
181
+ options.row.addComponents(
182
+ new discord_js_1.ButtonBuilder()
183
+ .setCustomId(`${this.interaction.id}-${options.buttons.indexOf(button)}`)
184
+ .setEmoji(button)
185
+ .setStyle(discord_js_1.ButtonStyle.Primary)
186
+ );
187
+ }
188
+ let embed = embeds[options.index || 0];
189
+ const content = {
190
+ embeds: [embed],
191
+ components: [options.row, ...options.components],
192
+ ephemeral: !!options.ephemeral,
193
+ };
194
+ (options.reply === undefined || options.reply === true ? this.interaction.util.reply(content) : this.interaction.channel.send(content)).then((message) => {
195
+ const collector = message.channel
196
+ .createMessageComponentCollector({
197
+ filter: options.filter,
198
+ time: options?.time || 60000,
199
+ })
200
+ .on('collect', (interaction) => {
201
+ let stop = false;
202
+ if (interaction.customId.startsWith(this.interaction.id)) {
203
+ switch (Number(interaction.customId.split(/-/).pop())) {
204
+ case 0: {
205
+ embed = embeds[0];
206
+ break;
207
+ }
208
+ case 1: {
209
+ embed = embeds[embeds.indexOf(embed) >= 1 ? embeds.indexOf(embed) - 1 : 0];
210
+ break;
211
+ }
212
+ case 2: {
213
+ collector.stop();
214
+ stop = true;
215
+ break;
216
+ }
217
+ case 3: {
218
+ embed = embeds[embeds.indexOf(embed) < embeds.length - 1 ? embeds.indexOf(embed) + 1 : embeds.length - 1];
219
+ break;
220
+ }
221
+ case 4: {
222
+ embed = embeds[embeds.length - 1];
223
+ break;
224
+ }
225
+ }
226
+ stop
227
+ ? interaction.update({
228
+ embeds: [embed],
229
+ components: [],
230
+ })
231
+ : interaction.update({
232
+ embeds: [embed],
233
+ });
234
+ }
235
+ })
236
+ .on('end', () => {
237
+ this.interaction.editReply({ components: [] });
238
+ });
239
+ });
240
+ }
241
+ buttonMenuPaginator(embeds, options) {}
242
+ isOwner() {
243
+ return this.client.util.isOwner(this.interaction.user.id);
244
+ }
245
+ createModal() {}
246
+ }
247
+ exports.InteractionCommandUtil = InteractionCommandUtil;
@@ -0,0 +1,12 @@
1
+ import { Interaction } from 'discord.js';
2
+ import ContextCommandBuilder from '../build/ContextCommandBuilder.js';
3
+ import MessageCommandBuilder from '../build/MessageCommandBuilder.js';
4
+ import SlashCommandBuilder from '../build/SlashCommandBuilder.js';
5
+ import XernerxClient from '../client/XernerxClient.js';
6
+ import { XernerxMessage } from '../types/types.js';
7
+ export default function commandValidation(
8
+ action: XernerxMessage | Interaction,
9
+ command: SlashCommandBuilder | MessageCommandBuilder | ContextCommandBuilder | any,
10
+ client: XernerxClient,
11
+ res?: boolean
12
+ ): boolean;