xernerx 4.17.4 → 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 -46
  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
@@ -1,167 +1,168 @@
1
1
  /** @format */
2
- import { ActionRowBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, } from 'discord.js';
2
+ import { ActionRowBuilder, ButtonBuilder, ButtonStyle, 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 MessageUtil extends Util {
7
- constructor(client, message) {
8
- super(client);
9
- this.message = message?.message || message;
10
- this.parsed = {
11
- alias: null,
12
- prefix: null,
13
- args: null,
14
- };
15
- }
16
- async send(content) {
17
- if (this.client.cache.messages.has(this.message.id) && this.client.modules.options.message?.handleEdits) {
18
- const id = this.client.cache.messages.get(this.message.id);
19
- if (!id)
20
- return null;
21
- const msg = await this.message.channel.messages.fetch(id);
22
- msg.edit(content);
23
- return msg;
24
- }
25
- const msg = await this.message.channel.send(content);
26
- this.client.cache.messages.set(this.message.id, msg.id);
27
- return msg;
28
- }
29
- async reply(content) {
30
- if (this.client.cache.messages.has(this.message.id) && this.client.modules.options.message?.handleEdits) {
31
- const id = this.client.cache.messages.get(this.message.id);
32
- if (!id)
33
- return null;
34
- const msg = await this.message.channel.messages.fetch(id);
35
- msg.edit(content);
36
- return msg;
37
- }
38
- const msg = await this.message.reply(content);
39
- this.client.cache.messages.set(this.message.id, msg.id);
40
- return msg;
41
- }
42
- async mimic(user, message, options) {
43
- user = (typeof user == 'string' ? (await this.client.users.fetch(user)) : user);
44
- const webhooks = await this.message.channel.fetchWebhooks();
45
- const webhook = webhooks.find((wh) => wh.token) ||
46
- (await this.message.channel.createWebhook({
47
- name: `${this.client.user?.username}'s mimic webhook.`,
48
- avatar: user.displayAvatarURL() || this.client.user?.displayAvatarURL(),
49
- }));
50
- await webhook.send({
51
- content: message.content,
52
- username: user.username,
53
- avatarURL: user.displayAvatarURL(),
54
- });
55
- setTimeout(() => {
56
- webhook.delete().catch(() => true);
57
- }, options.timeout);
58
- }
59
- async paginator(embeds, options = {}) {
60
- let buttonRow, menuRow;
61
- if (embeds.length <= 0)
62
- throw new XernerxError(`Can't make a paginator without embeds`);
63
- options = {
64
- type: options.type ?? 'combined',
65
- buttons: options.buttons ?? ['⏪', '◀️', '⏹️', '▶️', '⏩'],
66
- description: options.description ?? false,
67
- placeholder: options.placeholder ?? 'Change page',
68
- index: options.index ?? 0,
69
- send: options.send ?? false,
70
- filter: options.filter ?? (() => true),
71
- time: options.time ?? 300000,
72
- };
73
- if (options.type == 'button' || options.type == 'combined') {
74
- if (!options.buttons)
75
- throw new XernerxError(`¯\\_(ツ)_/¯ Somehow there are no buttons? ¯\\_(ツ)_/¯`);
76
- buttonRow = new ActionRowBuilder().addComponents(...options.buttons.map((button, i) => new ButtonBuilder().setCustomId(`${this.message.id}-${i}`).setEmoji(button).setStyle(ButtonStyle.Primary)));
77
- }
78
- if (options.type == 'select-menu' || options.type == 'combined') {
79
- menuRow = new ActionRowBuilder().addComponents(new StringSelectMenuBuilder()
80
- .setCustomId(`${this.message.id}-select-menu`)
81
- .setPlaceholder(options.placeholder)
82
- .addOptions(...embeds.map((embed, i) => ({ label: embed.data.title || 'No Title', description: (options.description ? embed.data.description : undefined) || undefined, value: `${i}` }))));
83
- }
84
- let index = options.index || 0;
85
- return options.send
86
- ? await this.message.util.send({
87
- embeds: [embeds[index]],
88
- components: [options.type == 'combined' || options.type == 'button' ? buttonRow : null, options.type == 'combined' || options.type == 'select-menu' ? menuRow : null].filter((x) => x),
89
- })
90
- : await this.message.util
91
- .reply({
92
- embeds: [embeds[index]],
93
- components: [options.type == 'combined' || options.type == 'button' ? buttonRow : null, options.type == 'combined' || options.type == 'select-menu' ? menuRow : null].filter((x) => x),
94
- })
95
- .then(async (msg) => {
96
- const collector = this.message.channel
97
- ?.createMessageComponentCollector({ time: options.time })
98
- .on('collect', (collect) => {
99
- if (!collect.customId.startsWith(this.message.id))
100
- return;
101
- if (collect.customId.endsWith('select-menu')) {
102
- index = Number(collect.values[0]);
103
- collect.update({ embeds: [embeds[index]] });
104
- }
105
- else {
106
- const option = Number(collect.customId.split(/-/)[1]);
107
- let embed = embeds[index];
108
- if (option == 0) {
109
- index = 0;
110
- embed = embeds[index];
111
- collect.update({ embeds: [embed] });
112
- }
113
- if (option == 1) {
114
- index = embeds.indexOf(embed) >= 1 ? embeds.indexOf(embed) - 1 : 0;
115
- embed = embeds[index];
116
- collect.update({ embeds: [embed] });
117
- }
118
- if (option == 2) {
119
- collect.update({ components: [] });
120
- collector?.stop();
121
- }
122
- if (option == 3) {
123
- index = embeds.indexOf(embed) < embeds.length - 1 ? embeds.indexOf(embed) + 1 : embeds.length - 1;
124
- embed = embeds[index];
125
- collect.update({ embeds: [embed] });
126
- }
127
- if (option == 4) {
128
- index = embeds.length - 1;
129
- embed = embeds[index];
130
- collect.update({ embeds: [embed] });
131
- }
132
- }
133
- })
134
- .on('end', async () => {
135
- await msg?.edit({ components: [] });
136
- });
137
- });
138
- }
139
- commands() {
140
- return this.client.commands.message;
141
- }
142
- permissionCheck(type, permissions, emit = true) {
143
- const missing = [];
144
- for (const permission of permissions) {
145
- if (type == 'user') {
146
- this.message.member?.permissionsIn(this.message.channel.id).has(Style.pascalCase(permission, true)) ? null : missing.push(permission);
147
- }
148
- if (type == 'client') {
149
- this.message.guild?.members.me?.permissionsIn(this.message.channel.id).has(Style.pascalCase(permission, true)) ? null : missing.push(permission);
150
- }
151
- }
152
- const command = this.commands().find((cmd) => cmd.name == this.parsed.alias || cmd.aliases?.includes(this.parsed.alias));
153
- if (missing.length && emit) {
154
- this.client.emit(`commandBlock`, this.message, {
155
- reason: `missing${Style.pascalCase(type)}Permissions`,
156
- message: `${type == 'user' ? 'You are' : 'I am'} missing the following permissions to run \`${command?.name}\`:\n${missing.map((permission) => `> - ${permission}`).join('\n')}`,
157
- required: permissions,
158
- missing,
159
- }, command || null);
160
- return false;
161
- }
162
- else if (missing.length && !emit)
163
- return missing;
164
- else
165
- return true;
166
- }
7
+ constructor(client, message) {
8
+ super(client);
9
+ this.message = message?.message || message;
10
+ this.parsed = {
11
+ alias: null,
12
+ prefix: null,
13
+ args: null,
14
+ };
15
+ }
16
+ async send(content) {
17
+ if (this.client.cache.messages.has(this.message.id) && this.client.modules.options.message?.handleEdits) {
18
+ const id = this.client.cache.messages.get(this.message.id);
19
+ if (!id) return null;
20
+ const msg = await this.message.channel.messages.fetch(id);
21
+ msg.edit(content);
22
+ return msg;
23
+ }
24
+ const msg = await this.message.channel.send(content);
25
+ this.client.cache.messages.set(this.message.id, msg.id);
26
+ return msg;
27
+ }
28
+ async reply(content) {
29
+ if (this.client.cache.messages.has(this.message.id) && this.client.modules.options.message?.handleEdits) {
30
+ const id = this.client.cache.messages.get(this.message.id);
31
+ if (!id) return null;
32
+ const msg = await this.message.channel.messages.fetch(id);
33
+ msg.edit(content);
34
+ return msg;
35
+ }
36
+ const msg = await this.message.reply(content);
37
+ this.client.cache.messages.set(this.message.id, msg.id);
38
+ return msg;
39
+ }
40
+ async mimic(user, message, options) {
41
+ user = typeof user == 'string' ? await this.client.users.fetch(user) : user;
42
+ const webhooks = await this.message.channel.fetchWebhooks();
43
+ const webhook =
44
+ webhooks.find((wh) => wh.token) ||
45
+ (await this.message.channel.createWebhook({
46
+ name: `${this.client.user?.username}'s mimic webhook.`,
47
+ avatar: user.displayAvatarURL() || this.client.user?.displayAvatarURL(),
48
+ }));
49
+ await webhook.send({
50
+ content: message.content,
51
+ username: user.username,
52
+ avatarURL: user.displayAvatarURL(),
53
+ });
54
+ setTimeout(() => {
55
+ webhook.delete().catch(() => true);
56
+ }, options.timeout);
57
+ }
58
+ async paginator(embeds, options = {}) {
59
+ let buttonRow, menuRow;
60
+ if (embeds.length <= 0) throw new XernerxError(`Can't make a paginator without embeds`);
61
+ options = {
62
+ type: options.type ?? 'combined',
63
+ buttons: options.buttons ?? ['⏪', '◀️', '⏹️', '▶️', '⏩'],
64
+ description: options.description ?? false,
65
+ placeholder: options.placeholder ?? 'Change page',
66
+ index: options.index ?? 0,
67
+ send: options.send ?? false,
68
+ filter: options.filter ?? (() => true),
69
+ time: options.time ?? 300000,
70
+ };
71
+ if (options.type == 'button' || options.type == 'combined') {
72
+ if (!options.buttons) throw new XernerxError(`¯\\_(ツ)_/¯ Somehow there are no buttons? ¯\\_(ツ)_/¯`);
73
+ buttonRow = new ActionRowBuilder().addComponents(
74
+ ...options.buttons.map((button, i) => new ButtonBuilder().setCustomId(`${this.message.id}-${i}`).setEmoji(button).setStyle(ButtonStyle.Primary))
75
+ );
76
+ }
77
+ if (options.type == 'select-menu' || options.type == 'combined') {
78
+ menuRow = new ActionRowBuilder().addComponents(
79
+ new StringSelectMenuBuilder()
80
+ .setCustomId(`${this.message.id}-select-menu`)
81
+ .setPlaceholder(options.placeholder)
82
+ .addOptions(...embeds.map((embed, i) => ({ label: embed.data.title || 'No Title', description: (options.description ? embed.data.description : undefined) || undefined, value: `${i}` })))
83
+ );
84
+ }
85
+ let index = options.index || 0;
86
+ return options.send
87
+ ? await this.message.util.send({
88
+ embeds: [embeds[index]],
89
+ components: [options.type == 'combined' || options.type == 'button' ? buttonRow : null, options.type == 'combined' || options.type == 'select-menu' ? menuRow : null].filter((x) => x),
90
+ })
91
+ : await this.message.util
92
+ .reply({
93
+ embeds: [embeds[index]],
94
+ components: [options.type == 'combined' || options.type == 'button' ? buttonRow : null, options.type == 'combined' || options.type == 'select-menu' ? menuRow : null].filter((x) => x),
95
+ })
96
+ .then(async (msg) => {
97
+ const collector = this.message.channel
98
+ ?.createMessageComponentCollector({ time: options.time })
99
+ .on('collect', (collect) => {
100
+ if (!collect.customId.startsWith(this.message.id)) return;
101
+ if (collect.customId.endsWith('select-menu')) {
102
+ index = Number(collect.values[0]);
103
+ collect.update({ embeds: [embeds[index]] });
104
+ } else {
105
+ const option = Number(collect.customId.split(/-/)[1]);
106
+ let embed = embeds[index];
107
+ if (option == 0) {
108
+ index = 0;
109
+ embed = embeds[index];
110
+ collect.update({ embeds: [embed] });
111
+ }
112
+ if (option == 1) {
113
+ index = embeds.indexOf(embed) >= 1 ? embeds.indexOf(embed) - 1 : 0;
114
+ embed = embeds[index];
115
+ collect.update({ embeds: [embed] });
116
+ }
117
+ if (option == 2) {
118
+ collect.update({ components: [] });
119
+ collector?.stop();
120
+ }
121
+ if (option == 3) {
122
+ index = embeds.indexOf(embed) < embeds.length - 1 ? embeds.indexOf(embed) + 1 : embeds.length - 1;
123
+ embed = embeds[index];
124
+ collect.update({ embeds: [embed] });
125
+ }
126
+ if (option == 4) {
127
+ index = embeds.length - 1;
128
+ embed = embeds[index];
129
+ collect.update({ embeds: [embed] });
130
+ }
131
+ }
132
+ })
133
+ .on('end', async () => {
134
+ await msg?.edit({ components: [] });
135
+ });
136
+ });
137
+ }
138
+ commands() {
139
+ return this.client.commands.message;
140
+ }
141
+ permissionCheck(type, permissions, emit = true) {
142
+ const missing = [];
143
+ for (const permission of permissions) {
144
+ if (type == 'user') {
145
+ this.message.member?.permissionsIn(this.message.channel.id).has(Style.pascalCase(permission, true)) ? null : missing.push(permission);
146
+ }
147
+ if (type == 'client') {
148
+ this.message.guild?.members.me?.permissionsIn(this.message.channel.id).has(Style.pascalCase(permission, true)) ? null : missing.push(permission);
149
+ }
150
+ }
151
+ const command = this.commands().find((cmd) => cmd.name == this.parsed.alias || cmd.aliases?.includes(this.parsed.alias));
152
+ if (missing.length && emit) {
153
+ this.client.emit(
154
+ `commandBlock`,
155
+ this.message,
156
+ {
157
+ reason: `missing${Style.pascalCase(type)}Permissions`,
158
+ message: `${type == 'user' ? 'You are' : 'I am'} missing the following permissions to run \`${command?.name}\`:\n${missing.map((permission) => `> - ${permission}`).join('\n')}`,
159
+ required: permissions,
160
+ missing,
161
+ },
162
+ command || null
163
+ );
164
+ return false;
165
+ } else if (missing.length && !emit) return missing;
166
+ else return true;
167
+ }
167
168
  }
@@ -2,8 +2,8 @@
2
2
  import XernerxClient from '../client/XernerxClient.js';
3
3
  import XernerxText from '../tools/XernerxText.js';
4
4
  export default class Util {
5
- readonly client: XernerxClient<unknown>;
6
- readonly text: XernerxText;
7
- constructor(client: XernerxClient);
8
- delay(time: number): Promise<unknown>;
5
+ readonly client: XernerxClient<unknown>;
6
+ readonly text: XernerxText;
7
+ constructor(client: XernerxClient);
8
+ delay(time: number): Promise<unknown>;
9
9
  }
@@ -1,11 +1,11 @@
1
1
  /** @format */
2
2
  import XernerxText from '../tools/XernerxText.js';
3
3
  export default class Util {
4
- constructor(client) {
5
- this.client = client;
6
- this.text = new XernerxText();
7
- }
8
- async delay(time) {
9
- return await new Promise((resolve) => setTimeout(resolve, time));
10
- }
4
+ constructor(client) {
5
+ this.client = client;
6
+ this.text = new XernerxText();
7
+ }
8
+ async delay(time) {
9
+ return await new Promise((resolve) => setTimeout(resolve, time));
10
+ }
11
11
  }
@@ -4,4 +4,7 @@ import MessageCommandBuilder from '../build/XernerxMessageCommand.js';
4
4
  import XernerxSlashCommand from '../build/XernerxSlashCommand.js';
5
5
  import { XernerxMessage, XernerxSlashInteraction, XernerxUserContextInteraction } from '../types/extenders.js';
6
6
  import { XernerxInteraction } from '../types/types.js';
7
- export default function commandValidation(event: XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxUserContextInteraction> | XernerxMessage, command: MessageCommandBuilder | XernerxSlashCommand | XernerxContextCommand): Promise<boolean>;
7
+ export default function commandValidation(
8
+ event: XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxUserContextInteraction> | XernerxMessage,
9
+ command: MessageCommandBuilder | XernerxSlashCommand | XernerxContextCommand
10
+ ): Promise<boolean>;