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