xernerx 4.17.6 → 4.17.9

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 (68) hide show
  1. package/dist/build/XernerxContextCommand.d.ts +47 -75
  2. package/dist/build/XernerxContextCommand.js +115 -119
  3. package/dist/build/XernerxEvent.d.ts +10 -10
  4. package/dist/build/XernerxEvent.js +17 -17
  5. package/dist/build/XernerxInhibitor.d.ts +15 -39
  6. package/dist/build/XernerxInhibitor.js +18 -18
  7. package/dist/build/XernerxMessageCommand.d.ts +52 -78
  8. package/dist/build/XernerxMessageCommand.js +114 -118
  9. package/dist/build/XernerxSlashCommand.d.ts +63 -97
  10. package/dist/build/XernerxSlashCommand.js +173 -177
  11. package/dist/client/XernerxClient.d.ts +55 -61
  12. package/dist/client/XernerxClient.js +94 -91
  13. package/dist/client/XernerxShardClient.d.ts +14 -14
  14. package/dist/client/XernerxShardClient.js +48 -61
  15. package/dist/functions/deploy.js +52 -45
  16. package/dist/functions/load.js +29 -28
  17. package/dist/functions/reload.js +24 -23
  18. package/dist/functions/setPresence.d.ts +1 -1
  19. package/dist/functions/setPresence.js +16 -17
  20. package/dist/handlers/CommandHandler.d.ts +10 -10
  21. package/dist/handlers/CommandHandler.js +337 -312
  22. package/dist/handlers/EventHandler.d.ts +5 -3
  23. package/dist/handlers/EventHandler.js +76 -48
  24. package/dist/handlers/ExtensionHandler.d.ts +3 -3
  25. package/dist/handlers/ExtensionHandler.js +23 -23
  26. package/dist/handlers/Handler.d.ts +17 -22
  27. package/dist/handlers/Handler.js +57 -45
  28. package/dist/handlers/InhibitorHandler.d.ts +3 -3
  29. package/dist/handlers/InhibitorHandler.js +23 -25
  30. package/dist/handlers/IntegrationHandler.d.ts +6 -6
  31. package/dist/handlers/IntegrationHandler.js +20 -20
  32. package/dist/main.d.ts +22 -29
  33. package/dist/main.js +22 -29
  34. package/dist/models/Arguments.d.ts +1 -4
  35. package/dist/models/Arguments.js +149 -134
  36. package/dist/models/Cooldowns.d.ts +6 -6
  37. package/dist/models/Cooldowns.js +29 -25
  38. package/dist/models/XernerxEntitlement.d.ts +45 -0
  39. package/dist/models/XernerxEntitlement.js +57 -0
  40. package/dist/models/XernerxUser.d.ts +14 -0
  41. package/dist/models/XernerxUser.js +13 -0
  42. package/dist/tools/XernerxError.d.ts +4 -4
  43. package/dist/tools/XernerxError.js +8 -8
  44. package/dist/tools/XernerxIntents.d.ts +2 -2
  45. package/dist/tools/XernerxIntents.js +21 -21
  46. package/dist/tools/XernerxLog.d.ts +25 -25
  47. package/dist/tools/XernerxLog.js +131 -140
  48. package/dist/tools/XernerxText.d.ts +23 -23
  49. package/dist/tools/XernerxText.js +89 -79
  50. package/dist/types/extenders.d.ts +47 -55
  51. package/dist/types/interfaces.d.ts +190 -195
  52. package/dist/types/types.d.ts +5 -104
  53. package/dist/utils/ClientUtil.d.ts +10 -12
  54. package/dist/utils/ClientUtil.js +117 -96
  55. package/dist/utils/InteractionUtil.d.ts +13 -13
  56. package/dist/utils/InteractionUtil.js +147 -148
  57. package/dist/utils/MessageUtil.d.ts +14 -14
  58. package/dist/utils/MessageUtil.js +161 -162
  59. package/dist/utils/Util.d.ts +7 -7
  60. package/dist/utils/Util.js +7 -7
  61. package/dist/validators/commandValidation.d.ts +1 -4
  62. package/dist/validators/commandValidation.js +114 -157
  63. package/dist/validators/inhibitorValidations.d.ts +2 -21
  64. package/dist/validators/inhibitorValidations.js +39 -39
  65. package/package.json +6 -5
  66. package/tsup.config.ts +19 -0
  67. package/dist/functions/xernerxUser.d.ts +0 -4
  68. package/dist/functions/xernerxUser.js +0 -10
@@ -1,154 +1,153 @@
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) 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
- }
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
+ }
154
153
  }
@@ -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('discord.js').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<any>;
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<any>;
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 {};