xernerx 4.17.3 → 4.17.5

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 (62) hide show
  1. package/dist/build/XernerxContextCommand.d.ts +75 -47
  2. package/dist/build/XernerxContextCommand.js +119 -115
  3. package/dist/build/XernerxEvent.d.ts +10 -10
  4. package/dist/build/XernerxEvent.js +17 -17
  5. package/dist/build/XernerxInhibitor.d.ts +39 -15
  6. package/dist/build/XernerxInhibitor.js +18 -18
  7. package/dist/build/XernerxMessageCommand.d.ts +78 -52
  8. package/dist/build/XernerxMessageCommand.js +118 -114
  9. package/dist/build/XernerxSlashCommand.d.ts +96 -62
  10. package/dist/build/XernerxSlashCommand.js +176 -172
  11. package/dist/client/XernerxClient.d.ts +55 -45
  12. package/dist/client/XernerxClient.js +83 -88
  13. package/dist/client/XernerxShardClient.d.ts +14 -14
  14. package/dist/client/XernerxShardClient.js +61 -47
  15. package/dist/functions/deploy.js +45 -52
  16. package/dist/functions/load.js +28 -29
  17. package/dist/functions/reload.js +23 -24
  18. package/dist/functions/setPresence.d.ts +1 -1
  19. package/dist/functions/setPresence.js +17 -16
  20. package/dist/functions/xernerxUser.js +5 -6
  21. package/dist/handlers/CommandHandler.d.ts +10 -10
  22. package/dist/handlers/CommandHandler.js +311 -336
  23. package/dist/handlers/EventHandler.d.ts +3 -3
  24. package/dist/handlers/EventHandler.js +48 -21
  25. package/dist/handlers/ExtensionHandler.d.ts +3 -3
  26. package/dist/handlers/ExtensionHandler.js +23 -23
  27. package/dist/handlers/Handler.d.ts +19 -14
  28. package/dist/handlers/Handler.js +46 -50
  29. package/dist/handlers/InhibitorHandler.d.ts +3 -3
  30. package/dist/handlers/InhibitorHandler.js +25 -23
  31. package/dist/handlers/IntegrationHandler.d.ts +6 -6
  32. package/dist/handlers/IntegrationHandler.js +20 -20
  33. package/dist/main.d.ts +28 -21
  34. package/dist/main.js +28 -21
  35. package/dist/models/Arguments.d.ts +4 -1
  36. package/dist/models/Arguments.js +134 -149
  37. package/dist/models/Cooldowns.d.ts +6 -6
  38. package/dist/models/Cooldowns.js +25 -29
  39. package/dist/tools/XernerxError.d.ts +4 -4
  40. package/dist/tools/XernerxError.js +8 -8
  41. package/dist/tools/XernerxIntents.d.ts +2 -2
  42. package/dist/tools/XernerxIntents.js +21 -21
  43. package/dist/tools/XernerxLog.d.ts +23 -23
  44. package/dist/tools/XernerxLog.js +125 -110
  45. package/dist/tools/XernerxText.d.ts +23 -23
  46. package/dist/tools/XernerxText.js +79 -89
  47. package/dist/types/extenders.d.ts +55 -47
  48. package/dist/types/interfaces.d.ts +192 -189
  49. package/dist/types/types.d.ts +104 -5
  50. package/dist/utils/ClientUtil.d.ts +12 -9
  51. package/dist/utils/ClientUtil.js +96 -79
  52. package/dist/utils/InteractionUtil.d.ts +13 -13
  53. package/dist/utils/InteractionUtil.js +148 -147
  54. package/dist/utils/MessageUtil.d.ts +14 -14
  55. package/dist/utils/MessageUtil.js +162 -161
  56. package/dist/utils/Util.d.ts +4 -4
  57. package/dist/utils/Util.js +7 -7
  58. package/dist/validators/commandValidation.d.ts +4 -1
  59. package/dist/validators/commandValidation.js +157 -114
  60. package/dist/validators/inhibitorValidations.d.ts +21 -2
  61. package/dist/validators/inhibitorValidations.js +39 -39
  62. package/package.json +3 -3
@@ -3,83 +3,100 @@ import { Collection } from 'discord.js';
3
3
  import setPresence from '../functions/setPresence.js';
4
4
  import Util from './Util.js';
5
5
  export default class ClientUtil extends Util {
6
- constructor(client) {
7
- super(client);
8
- }
9
- setPresence(options) {
10
- return setPresence(this.client, options);
11
- }
12
- // @ts-ignore
13
- resolveCooldown() { }
14
- async resolveCommand(options) {
15
- const interCommands = await this.client.application?.commands.fetch();
16
- const commands = [], collection = new Collection();
17
- if (options?.type == 'MessageCommand' || !options?.type)
18
- commands.push(...this.client.commands.message);
19
- if (options?.type == 'Interaction' || options?.type == 'SlashCommand' || !options?.type)
20
- commands.push(...this.client.commands.slash);
21
- if (options?.type == 'Interaction' || options?.type == 'ContextCommand' || !options?.type)
22
- commands.push(...this.client.commands.context);
23
- commands.map(([name, command]) => {
24
- command.snowflake = interCommands?.find((cmd) => command.name === cmd.name)?.id || null;
25
- collection.set(name, command);
26
- });
27
- if (options?.name) {
28
- return collection.get(options.name) || null;
29
- }
30
- else
31
- return collection;
32
- }
33
- async resolveChannel(query) {
34
- if (typeof query == 'object')
35
- query = query.id;
36
- try {
37
- let channel = this.client.channels.cache.find((channel) => channel.name == query.toLowerCase() || channel.id == query.toLowerCase() ? channel : null) || null;
38
- if (!channel)
39
- channel = (await this.client.channels.fetch(query)) || null;
40
- return channel;
41
- }
42
- catch {
43
- return null;
44
- }
45
- }
46
- async resolveGuild(query) {
47
- if (typeof query == 'object')
48
- query = query.id;
49
- try {
50
- let guild = this.client.guilds.cache.find((guild) => guild.name.toLowerCase() == query.toLowerCase()) || null;
51
- if (!guild)
52
- guild = (await this.client.guilds.fetch(query)) || null;
53
- return guild;
54
- }
55
- catch {
56
- return null;
57
- }
58
- }
59
- uptime(timestamp) {
60
- if (!timestamp)
61
- timestamp = this.client.uptime || 0;
62
- let totalSeconds = timestamp / 1000;
63
- let years = Math.floor(totalSeconds / 31536000);
64
- totalSeconds %= 31536000;
65
- let days = Math.floor(totalSeconds / 86400);
66
- totalSeconds %= 86400;
67
- let hours = Math.floor(totalSeconds / 3600);
68
- totalSeconds %= 3600;
69
- let minutes = Math.floor(totalSeconds / 60);
70
- let seconds = Math.floor(totalSeconds % 60);
71
- if (years >= 1)
72
- return `${years}y ${days}d ${hours}h ${minutes}m`;
73
- else if (days >= 1)
74
- return `${days}d ${hours}h ${minutes}m`;
75
- else if (hours >= 1)
76
- return `${hours}h ${minutes}m`;
77
- else if (minutes >= 1)
78
- return `${minutes}m ${seconds}s`;
79
- else
80
- return `${seconds}s`;
81
- }
82
- commands() {
83
- return [...this.client.commands.context.toJSON(), ...this.client.commands.slash.toJSON(), ...this.client.commands.message.toJSON()];
84
- }
6
+ constructor(client) {
7
+ super(client);
8
+ this.setPresence = this.setPresence;
9
+ this.resolveCooldown = this.resolveCooldown;
10
+ this.resolveChannel = this.resolveChannel;
11
+ this.commands = this.commands;
12
+ this.resolveGuild = this.resolveGuild;
13
+ this.uptime = this.uptime;
14
+ }
15
+ setPresence(options) {
16
+ return setPresence(this.client, options);
17
+ }
18
+ // @ts-ignore
19
+ resolveCooldown() {}
20
+ async resolveCommand(options) {
21
+ const interCommands = await this.client.application?.commands.fetch();
22
+ const commands = [],
23
+ collection = new Collection();
24
+ if (options?.type == 'MessageCommand' || !options?.type) commands.push(...this.client.commands.message);
25
+ if (options?.type == 'Interaction' || options?.type == 'SlashCommand' || !options?.type) commands.push(...this.client.commands.slash);
26
+ if (options?.type == 'Interaction' || options?.type == 'ContextCommand' || !options?.type) commands.push(...this.client.commands.context);
27
+ commands.map(([name, command]) => {
28
+ command.snowflake = interCommands?.find((cmd) => command.name === cmd.name)?.id || null;
29
+ collection.set(name, command);
30
+ });
31
+ if (options?.name) {
32
+ return collection.get(options.name) || null;
33
+ } else return collection;
34
+ }
35
+ async resolveChannel(query) {
36
+ if (typeof query == 'object') query = query.id;
37
+ try {
38
+ let channel = this.client.channels.cache.find((channel) => (channel.name == query.toLowerCase() || channel.id == query.toLowerCase() ? channel : null)) || null;
39
+ if (!channel) channel = (await this.client.channels.fetch(query)) || null;
40
+ return channel;
41
+ } catch {
42
+ return null;
43
+ }
44
+ }
45
+ async resolveGuild(query) {
46
+ if (typeof query == 'object') query = query.id;
47
+ try {
48
+ let guild = this.client.guilds.cache.find((guild) => guild.name.toLowerCase() == query.toLowerCase()) || null;
49
+ if (!guild) guild = (await this.client.guilds.fetch(query)) || null;
50
+ return guild;
51
+ } catch {
52
+ return null;
53
+ }
54
+ }
55
+ uptime(timestamp) {
56
+ if (!timestamp) timestamp = this.client.uptime || 0;
57
+ let totalSeconds = timestamp / 1000;
58
+ let years = Math.floor(totalSeconds / 31536000);
59
+ totalSeconds %= 31536000;
60
+ let days = Math.floor(totalSeconds / 86400);
61
+ totalSeconds %= 86400;
62
+ let hours = Math.floor(totalSeconds / 3600);
63
+ totalSeconds %= 3600;
64
+ let minutes = Math.floor(totalSeconds / 60);
65
+ let seconds = Math.floor(totalSeconds % 60);
66
+ if (years >= 1) return `${years}y ${days}d ${hours}h ${minutes}m`;
67
+ else if (days >= 1) return `${days}d ${hours}h ${minutes}m`;
68
+ else if (hours >= 1) return `${hours}h ${minutes}m`;
69
+ else if (minutes >= 1) return `${minutes}m ${seconds}s`;
70
+ else return `${seconds}s`;
71
+ }
72
+ commands() {
73
+ return [...this.client.commands.context.toJSON(), ...this.client.commands.slash.toJSON(), ...this.client.commands.message.toJSON()];
74
+ }
75
+ commandsList() {
76
+ function set(name, type, description, usage) {
77
+ return collection.set(name, { name, type, description, usage });
78
+ }
79
+ const commands = this.commands();
80
+ const collection = new Collection();
81
+ commands.map((command) => {
82
+ if (command.filetype == 'MessageCommand' || command.filetype == 'ContextCommand') return set(command.name, command.filetype, command.description, command.usage);
83
+ else if (command.data.options.length) {
84
+ command.data.options.map((option) => {
85
+ if (!option.type) {
86
+ if (option.options.length) {
87
+ option.options.map((o) => {
88
+ if (!o.type) set(`${command.name} ${option.name} ${o.name}`, command.filetype, o.description, command.usage);
89
+ else set(`${command.name} ${option.name}`, command.filetype, option.description, command.usage);
90
+ });
91
+ } else {
92
+ set(`${command.name} ${option.name}`, command.filetype, option.description, command.usage);
93
+ }
94
+ }
95
+ });
96
+ } else {
97
+ set(command.name, command.filetype, command.description, command.usage);
98
+ }
99
+ });
100
+ return collection;
101
+ }
85
102
  }
@@ -6,20 +6,20 @@ import { PermissionNames, XernerxInteraction } from '../types/types.js';
6
6
  import Util from './Util.js';
7
7
  import { XernerxMessageContextInteraction, XernerxSlashInteraction, XernerxUser, XernerxUserContextInteraction } from '../types/extenders.js';
8
8
  type MimicOptions = {
9
- timeout: number;
9
+ timeout: number;
10
10
  };
11
11
  export default class InteractionUtil extends Util {
12
- private readonly interaction;
13
- parsed: {
14
- alias: string | null;
15
- args: (SlashCommandArguments | ContextCommandArguments<'message' | 'user'>) | null;
16
- };
17
- constructor(client: XernerxClient, interaction: XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction>);
18
- send(content: any): Promise<import("discord.js").Message<false> | import("discord.js").Message<true> | undefined>;
19
- reply(content: string | MessagePayload | InteractionReplyOptions | InteractionEditReplyOptions): Promise<import("discord.js").InteractionResponse<boolean> | import("discord.js").Message<boolean>>;
20
- mimic(user: XernerxUser | string, interaction: MessageCreateOptions, options: MimicOptions): Promise<void>;
21
- paginator(embeds: Array<EmbedBuilder>, options?: PaginatorOptions): Promise<void | import("discord.js").Message<false> | import("discord.js").Message<true>>;
22
- commands(): import("@discordjs/collection").Collection<string, import("../main.js").XernerxSlashCommand> | import("@discordjs/collection").Collection<string, import("../main.js").XernerxContextCommand>;
23
- permissionCheck(type: 'user' | 'client', permissions: Array<PermissionNames>, emit?: boolean): boolean | string[];
12
+ private readonly interaction;
13
+ parsed: {
14
+ alias: string | null;
15
+ args: (SlashCommandArguments | ContextCommandArguments<'message' | 'user'>) | null;
16
+ };
17
+ constructor(client: XernerxClient, interaction: XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction>);
18
+ send(content: any): Promise<import('discord.js').Message<false> | import('discord.js').Message<true> | undefined>;
19
+ reply(content: string | MessagePayload | InteractionReplyOptions | InteractionEditReplyOptions): Promise<import('discord.js').InteractionResponse<boolean> | import('discord.js').Message<boolean>>;
20
+ mimic(user: XernerxUser | string, interaction: MessageCreateOptions, options: MimicOptions): Promise<void>;
21
+ paginator(embeds: Array<EmbedBuilder>, options?: PaginatorOptions): Promise<void | import('discord.js').Message<false> | import('discord.js').Message<true>>;
22
+ commands(): import('discord.js').Collection<string, import('../main.js').XernerxSlashCommand> | import('discord.js').Collection<string, import('../main.js').XernerxContextCommand>;
23
+ permissionCheck(type: 'user' | 'client', permissions: Array<PermissionNames>, emit?: boolean): boolean | string[];
24
24
  }
25
25
  export {};
@@ -1,153 +1,154 @@
1
1
  /** @format */
2
- import { ActionRowBuilder, ButtonBuilder, ButtonStyle, InteractionType, StringSelectMenuBuilder, } from 'discord.js';
2
+ import { ActionRowBuilder, ButtonBuilder, ButtonStyle, InteractionType, StringSelectMenuBuilder } from 'discord.js';
3
3
  import Util from './Util.js';
4
4
  import XernerxError from '../tools/XernerxError.js';
5
5
  import { Style } from 'dumfunctions';
6
6
  export default class InteractionUtil extends Util {
7
- constructor(client, interaction) {
8
- super(client);
9
- this.interaction = interaction;
10
- this.parsed = {
11
- alias: null,
12
- args: null,
13
- };
14
- }
15
- async send(content) {
16
- if (!content)
17
- throw new XernerxError(`Can't send a message without content.`);
18
- return await this.interaction.channel?.send(content);
19
- }
20
- async reply(content) {
21
- if (!content)
22
- throw new XernerxError(`Can't send a message without content.`);
23
- return await (this.interaction.replied || this.interaction.deferred ? this.interaction.editReply(content) : this.interaction.reply(content));
24
- }
25
- async mimic(user, interaction, options) {
26
- user = (typeof user == 'string' ? (await this.client.users.fetch(user)) : user);
27
- const webhooks = await this.interaction.channel.fetchWebhooks();
28
- const webhook = webhooks.find((wh) => wh.token) ||
29
- (await this.interaction.channel.createWebhook({
30
- name: `${this.client.user?.username}'s mimic webhook.`,
31
- avatar: user.displayAvatarURL() || this.client.user?.displayAvatarURL(),
32
- }));
33
- await webhook.send({
34
- content: interaction.content,
35
- username: user.username,
36
- avatarURL: user.displayAvatarURL(),
37
- });
38
- setTimeout(() => {
39
- webhook.delete().catch(() => true);
40
- }, options.timeout);
41
- }
42
- async paginator(embeds, options = {}) {
43
- let buttonRow, menuRow;
44
- if (embeds.length <= 0)
45
- throw new XernerxError(`Can't make a paginator without embeds`);
46
- options = {
47
- type: options.type ?? 'combined',
48
- buttons: options.buttons ?? ['⏪', '◀️', '⏹️', '▶️', '⏩'],
49
- description: options.description ?? false,
50
- placeholder: options.placeholder ?? 'Change page',
51
- index: options.index ?? 0,
52
- send: options.send ?? false,
53
- filter: options.filter ?? (() => true),
54
- time: options.time ?? 300000,
55
- };
56
- if (options.type == 'button' || options.type == 'combined') {
57
- if (!options.buttons)
58
- throw new XernerxError(`¯\\_(ツ)_/¯ Somehow there are no buttons? ¯\\_(ツ)_/¯`);
59
- buttonRow = new ActionRowBuilder().addComponents(...options.buttons.map((button, i) => new ButtonBuilder().setCustomId(`${this.interaction.id}-${i}`).setEmoji(button).setStyle(ButtonStyle.Primary)));
60
- }
61
- if (options.type == 'select-menu' || options.type == 'combined') {
62
- menuRow = new ActionRowBuilder().addComponents(new StringSelectMenuBuilder()
63
- .setCustomId(`${this.interaction.id}-select-menu`)
64
- .setPlaceholder(options.placeholder)
65
- .addOptions(...embeds.map((embed, i) => ({ label: embed.data.title || 'No Title', description: (options.description ? embed.data.description : undefined) || undefined, value: `${i}` }))));
66
- }
67
- let index = options.index || 0;
68
- return options.send
69
- ? await this.interaction.util.send({
70
- embeds: [embeds[index]],
71
- components: [options.type == 'combined' || options.type == 'button' ? buttonRow : null, options.type == 'combined' || options.type == 'select-menu' ? menuRow : null].filter((x) => x),
72
- })
73
- : await this.interaction.util
74
- .reply({
75
- embeds: [embeds[index]],
76
- components: [options.type == 'combined' || options.type == 'button' ? buttonRow : null, options.type == 'combined' || options.type == 'select-menu' ? menuRow : null].filter((x) => x),
77
- })
78
- .then(async (msg) => {
79
- const collector = this.interaction.channel
80
- ?.createMessageComponentCollector({ time: options.time })
81
- .on('collect', (collect) => {
82
- if (!collect.customId.startsWith(this.interaction.id))
83
- return;
84
- if (collect.customId.endsWith('select-menu')) {
85
- index = Number(collect.values[0]);
86
- collect.update({ embeds: [embeds[index]] });
87
- }
88
- else {
89
- const option = Number(collect.customId.split(/-/)[1]);
90
- let embed = embeds[index];
91
- if (option == 0) {
92
- index = 0;
93
- embed = embeds[index];
94
- collect.update({ embeds: [embed] });
95
- }
96
- if (option == 1) {
97
- index = embeds.indexOf(embed) >= 1 ? embeds.indexOf(embed) - 1 : 0;
98
- embed = embeds[index];
99
- collect.update({ embeds: [embed] });
100
- }
101
- if (option == 2) {
102
- collect.update({ components: [] });
103
- collector?.stop();
104
- }
105
- if (option == 3) {
106
- index = embeds.indexOf(embed) < embeds.length - 1 ? embeds.indexOf(embed) + 1 : embeds.length - 1;
107
- embed = embeds[index];
108
- collect.update({ embeds: [embed] });
109
- }
110
- if (option == 4) {
111
- index = embeds.length - 1;
112
- embed = embeds[index];
113
- collect.update({ embeds: [embed] });
114
- }
115
- }
116
- })
117
- .on('end', async () => {
118
- this.interaction.editReply({ components: [] });
119
- });
120
- });
121
- }
122
- commands() {
123
- if (this.interaction.type == InteractionType.ApplicationCommand)
124
- return this.client.commands.slash;
125
- else
126
- return this.client.commands.context;
127
- }
128
- permissionCheck(type, permissions, emit = true) {
129
- const missing = [];
130
- for (const permission of permissions) {
131
- if (type == 'user') {
132
- this.interaction.memberPermissions?.has(Style.pascalCase(permission, true)) ? null : missing.push(permission);
133
- }
134
- if (type == 'client') {
135
- this.interaction.guild?.members.me?.permissionsIn(this.interaction.channel?.id).has(Style.pascalCase(permission, true)) ? null : missing.push(permission);
136
- }
137
- }
138
- const command = this.commands().toJSON().find((cmd) => cmd.name == this.parsed.alias?.split(/ +/)[0]);
139
- if (missing.length && emit) {
140
- this.client.emit(`commandBlock`, this.interaction, {
141
- reason: `missing${Style.pascalCase(type)}Permissions`,
142
- message: `${type == 'user' ? 'You are' : 'I am'} missing the following permissions to run \`${command?.name}\`:\n${missing.map((permission) => `> - ${permission}`).join('\n')}`,
143
- required: permissions,
144
- missing,
145
- }, command || null);
146
- return false;
147
- }
148
- else if (missing.length && !emit)
149
- return missing;
150
- else
151
- return true;
152
- }
7
+ constructor(client, interaction) {
8
+ super(client);
9
+ this.interaction = interaction;
10
+ this.parsed = {
11
+ alias: null,
12
+ args: null,
13
+ };
14
+ }
15
+ async send(content) {
16
+ if (!content) throw new XernerxError(`Can't send a message without content.`);
17
+ return await this.interaction.channel?.send(content);
18
+ }
19
+ async reply(content) {
20
+ if (!content) throw new XernerxError(`Can't send a message without content.`);
21
+ return await (this.interaction.replied || this.interaction.deferred ? this.interaction.editReply(content) : this.interaction.reply(content));
22
+ }
23
+ async mimic(user, interaction, options) {
24
+ user = typeof user == 'string' ? await this.client.users.fetch(user) : user;
25
+ const webhooks = await this.interaction.channel.fetchWebhooks();
26
+ const webhook =
27
+ webhooks.find((wh) => wh.token) ||
28
+ (await this.interaction.channel.createWebhook({
29
+ name: `${this.client.user?.username}'s mimic webhook.`,
30
+ avatar: user.displayAvatarURL() || this.client.user?.displayAvatarURL(),
31
+ }));
32
+ await webhook.send({
33
+ content: interaction.content,
34
+ username: user.username,
35
+ avatarURL: user.displayAvatarURL(),
36
+ });
37
+ setTimeout(() => {
38
+ webhook.delete().catch(() => true);
39
+ }, options.timeout);
40
+ }
41
+ async paginator(embeds, options = {}) {
42
+ let buttonRow, menuRow;
43
+ if (embeds.length <= 0) throw new XernerxError(`Can't make a paginator without embeds`);
44
+ options = {
45
+ type: options.type ?? 'combined',
46
+ buttons: options.buttons ?? ['⏪', '◀️', '⏹️', '▶️', '⏩'],
47
+ description: options.description ?? false,
48
+ placeholder: options.placeholder ?? 'Change page',
49
+ index: options.index ?? 0,
50
+ send: options.send ?? false,
51
+ filter: options.filter ?? (() => true),
52
+ time: options.time ?? 300000,
53
+ };
54
+ if (options.type == 'button' || options.type == 'combined') {
55
+ if (!options.buttons) throw new XernerxError(`¯\\_(ツ)_/¯ Somehow there are no buttons? ¯\\_(ツ)_/¯`);
56
+ buttonRow = new ActionRowBuilder().addComponents(
57
+ ...options.buttons.map((button, i) => new ButtonBuilder().setCustomId(`${this.interaction.id}-${i}`).setEmoji(button).setStyle(ButtonStyle.Primary))
58
+ );
59
+ }
60
+ if (options.type == 'select-menu' || options.type == 'combined') {
61
+ menuRow = new ActionRowBuilder().addComponents(
62
+ new StringSelectMenuBuilder()
63
+ .setCustomId(`${this.interaction.id}-select-menu`)
64
+ .setPlaceholder(options.placeholder)
65
+ .addOptions(...embeds.map((embed, i) => ({ label: embed.data.title || 'No Title', description: (options.description ? embed.data.description : undefined) || undefined, value: `${i}` })))
66
+ );
67
+ }
68
+ let index = options.index || 0;
69
+ return options.send
70
+ ? await this.interaction.util.send({
71
+ embeds: [embeds[index]],
72
+ components: [options.type == 'combined' || options.type == 'button' ? buttonRow : null, options.type == 'combined' || options.type == 'select-menu' ? menuRow : null].filter((x) => x),
73
+ })
74
+ : await this.interaction.util
75
+ .reply({
76
+ embeds: [embeds[index]],
77
+ components: [options.type == 'combined' || options.type == 'button' ? buttonRow : null, options.type == 'combined' || options.type == 'select-menu' ? menuRow : null].filter((x) => x),
78
+ })
79
+ .then(async (msg) => {
80
+ const collector = this.interaction.channel
81
+ ?.createMessageComponentCollector({ time: options.time })
82
+ .on('collect', (collect) => {
83
+ if (!collect.customId.startsWith(this.interaction.id)) return;
84
+ if (collect.customId.endsWith('select-menu')) {
85
+ index = Number(collect.values[0]);
86
+ collect.update({ embeds: [embeds[index]] });
87
+ } else {
88
+ const option = Number(collect.customId.split(/-/)[1]);
89
+ let embed = embeds[index];
90
+ if (option == 0) {
91
+ index = 0;
92
+ embed = embeds[index];
93
+ collect.update({ embeds: [embed] });
94
+ }
95
+ if (option == 1) {
96
+ index = embeds.indexOf(embed) >= 1 ? embeds.indexOf(embed) - 1 : 0;
97
+ embed = embeds[index];
98
+ collect.update({ embeds: [embed] });
99
+ }
100
+ if (option == 2) {
101
+ collect.update({ components: [] });
102
+ collector?.stop();
103
+ }
104
+ if (option == 3) {
105
+ index = embeds.indexOf(embed) < embeds.length - 1 ? embeds.indexOf(embed) + 1 : embeds.length - 1;
106
+ embed = embeds[index];
107
+ collect.update({ embeds: [embed] });
108
+ }
109
+ if (option == 4) {
110
+ index = embeds.length - 1;
111
+ embed = embeds[index];
112
+ collect.update({ embeds: [embed] });
113
+ }
114
+ }
115
+ })
116
+ .on('end', async () => {
117
+ this.interaction.editReply({ components: [] });
118
+ });
119
+ });
120
+ }
121
+ commands() {
122
+ if (this.interaction.type == InteractionType.ApplicationCommand) return this.client.commands.slash;
123
+ else return this.client.commands.context;
124
+ }
125
+ permissionCheck(type, permissions, emit = true) {
126
+ const missing = [];
127
+ for (const permission of permissions) {
128
+ if (type == 'user') {
129
+ this.interaction.memberPermissions?.has(Style.pascalCase(permission, true)) ? null : missing.push(permission);
130
+ }
131
+ if (type == 'client') {
132
+ this.interaction.guild?.members.me?.permissionsIn(this.interaction.channel?.id).has(Style.pascalCase(permission, true)) ? null : missing.push(permission);
133
+ }
134
+ }
135
+ const command = this.commands()
136
+ .toJSON()
137
+ .find((cmd) => cmd.name == this.parsed.alias?.split(/ +/)[0]);
138
+ if (missing.length && emit) {
139
+ this.client.emit(
140
+ `commandBlock`,
141
+ this.interaction,
142
+ {
143
+ reason: `missing${Style.pascalCase(type)}Permissions`,
144
+ message: `${type == 'user' ? 'You are' : 'I am'} missing the following permissions to run \`${command?.name}\`:\n${missing.map((permission) => `> - ${permission}`).join('\n')}`,
145
+ required: permissions,
146
+ missing,
147
+ },
148
+ command || null
149
+ );
150
+ return false;
151
+ } else if (missing.length && !emit) return missing;
152
+ else return true;
153
+ }
153
154
  }
@@ -6,21 +6,21 @@ import Util from './Util.js';
6
6
  import { PaginatorOptions } from '../types/interfaces.js';
7
7
  import { PermissionNames } from '../main.js';
8
8
  type MimicOptions = {
9
- timeout: number;
9
+ timeout: number;
10
10
  };
11
11
  export default class MessageUtil extends Util {
12
- private readonly message;
13
- parsed: {
14
- alias: string | null;
15
- prefix: string | null;
16
- args: Record<string, unknown> | null;
17
- };
18
- constructor(client: XernerxClient, message: XernerxMessage);
19
- send(content: any): Promise<import("discord.js").Message<boolean> | null>;
20
- reply(content: string | MessagePayload | MessageReplyOptions | MessageEditOptions): Promise<import("discord.js").Message<boolean> | null>;
21
- mimic(user: XernerxUser | string, message: MessageCreateOptions, options: MimicOptions): Promise<void>;
22
- paginator(embeds: Array<EmbedBuilder>, options?: PaginatorOptions): Promise<void | import("discord.js").Message<boolean> | null>;
23
- commands(): import("@discordjs/collection").Collection<string, import("../main.js").XernerxMessageCommand>;
24
- permissionCheck(type: 'user' | 'client', permissions: Array<PermissionNames>, emit?: boolean): boolean | string[];
12
+ private readonly message;
13
+ parsed: {
14
+ alias: string | null;
15
+ prefix: string | null;
16
+ args: Record<string, unknown> | null;
17
+ };
18
+ constructor(client: XernerxClient, message: XernerxMessage);
19
+ send(content: any): Promise<import('discord.js').Message<boolean> | null>;
20
+ reply(content: string | MessagePayload | MessageReplyOptions | MessageEditOptions): Promise<import('discord.js').Message<boolean> | null>;
21
+ mimic(user: XernerxUser | string, message: MessageCreateOptions, options: MimicOptions): Promise<void>;
22
+ paginator(embeds: Array<EmbedBuilder>, options?: PaginatorOptions): Promise<void | import('discord.js').Message<boolean> | null>;
23
+ commands(): import('discord.js').Collection<string, import('../main.js').XernerxMessageCommand>;
24
+ permissionCheck(type: 'user' | 'client', permissions: Array<PermissionNames>, emit?: boolean): boolean | string[];
25
25
  }
26
26
  export {};