xernerx 3.4.3 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +10 -10
  2. package/dist/build/ContextCommandBuilder.js +93 -86
  3. package/dist/build/EventBuilder.js +34 -35
  4. package/dist/build/InhibitorBuilder.js +27 -27
  5. package/dist/build/MessageCommandBuilder.js +90 -78
  6. package/dist/build/SlashCommandBuilder.js +125 -118
  7. package/dist/client/XernerxClient.js +101 -83
  8. package/dist/handlers/CommandHandler.js +42 -42
  9. package/dist/handlers/EventHandler.js +16 -16
  10. package/dist/handlers/Handler.js +250 -250
  11. package/dist/handlers/InhibitorHandler.js +21 -21
  12. package/dist/main.cjs +2012 -0
  13. package/dist/main.js +42 -42
  14. package/dist/models/CommandArguments.js +121 -123
  15. package/dist/models/Events.js +294 -304
  16. package/dist/models/Extensions.js +23 -23
  17. package/dist/tools/XernerxError.js +8 -8
  18. package/dist/tools/package.js +37 -41
  19. package/dist/types/enums.js +35 -35
  20. package/dist/types/interfaces.js +1 -1
  21. package/dist/types/options.js +1 -1
  22. package/dist/types/types.js +1 -1
  23. package/dist/utils/ClientUtil.js +222 -218
  24. package/dist/utils/CommandUtil.js +248 -260
  25. package/dist/validators/CommandValidations.js +183 -185
  26. package/dist/validators/InhibitorValidations.js +42 -42
  27. package/dist/validators/Shapes.js +1 -0
  28. package/package.json +54 -39
  29. package/types/build/ContextCommandBuilder.d.ts +68 -0
  30. package/{dist → types}/build/EventBuilder.d.ts +21 -17
  31. package/{dist → types}/build/InhibitorBuilder.d.ts +19 -20
  32. package/types/build/MessageCommandBuilder.d.ts +59 -0
  33. package/types/build/SlashCommandBuilder.d.ts +64 -0
  34. package/{dist → types}/client/XernerxClient.d.ts +28 -28
  35. package/{dist → types}/handlers/CommandHandler.d.ts +27 -27
  36. package/{dist → types}/handlers/EventHandler.d.ts +13 -13
  37. package/{dist → types}/handlers/Handler.d.ts +57 -57
  38. package/{dist → types}/handlers/InhibitorHandler.d.ts +18 -18
  39. package/{dist → types}/main.d.ts +44 -30
  40. package/{dist → types}/models/CommandArguments.d.ts +17 -17
  41. package/{dist → types}/models/Events.d.ts +24 -24
  42. package/{dist → types}/models/Extensions.d.ts +7 -7
  43. package/{dist → types}/tools/XernerxError.d.ts +5 -5
  44. package/{dist → types}/tools/package.d.ts +38 -38
  45. package/types/types/enums.d.ts +44 -0
  46. package/{dist → types}/types/interfaces.d.ts +25 -25
  47. package/{dist → types}/types/options.d.ts +241 -206
  48. package/{dist → types}/types/types.d.ts +61 -32
  49. package/{dist → types}/utils/ClientUtil.d.ts +25 -25
  50. package/{dist → types}/utils/CommandUtil.d.ts +58 -56
  51. package/{dist → types}/validators/CommandValidations.d.ts +12 -7
  52. package/{dist → types}/validators/InhibitorValidations.d.ts +11 -11
  53. package/types/validators/Shapes.d.ts +1 -0
  54. package/dist/build/ContextCommandBuilder.d.ts +0 -42
  55. package/dist/build/MessageCommandBuilder.d.ts +0 -42
  56. package/dist/build/SlashCommandBuilder.d.ts +0 -40
  57. package/dist/build/XContextCommandBuilder.d.ts +0 -40
  58. package/dist/build/XContextCommandBuilder.js +0 -84
  59. package/dist/build/XEventBuilder.d.ts +0 -17
  60. package/dist/build/XEventBuilder.js +0 -35
  61. package/dist/build/XInhibitorBuilder.d.ts +0 -20
  62. package/dist/build/XInhibitorBuilder.js +0 -28
  63. package/dist/build/XMessageCommandBuilder.d.ts +0 -42
  64. package/dist/build/XMessageCommandBuilder.js +0 -80
  65. package/dist/build/XSlashCommandBuilder.d.ts +0 -36
  66. package/dist/build/XSlashCommandBuilder.js +0 -114
  67. package/dist/models/CommandValidations.d.ts +0 -4
  68. package/dist/models/CommandValidations.js +0 -183
  69. package/dist/models/InhibitorValidations.d.ts +0 -12
  70. package/dist/models/InhibitorValidations.js +0 -42
  71. package/dist/types/enums.d.ts +0 -35
@@ -1,218 +1,222 @@
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)
9
- timestamp = this.client.uptime || 0;
10
- let totalSeconds = timestamp / 1000;
11
- let years = Math.floor(totalSeconds / 31536000);
12
- totalSeconds %= 31536000;
13
- let days = Math.floor(totalSeconds / 86400);
14
- totalSeconds %= 86400;
15
- let hours = Math.floor(totalSeconds / 3600);
16
- totalSeconds %= 3600;
17
- let minutes = Math.floor(totalSeconds / 60);
18
- let seconds = Math.floor(totalSeconds % 60);
19
- if (years >= 1)
20
- return `${years}y ${days}d ${hours}h ${minutes}m`;
21
- else if (days >= 1)
22
- return `${days}d ${hours}h ${minutes}m`;
23
- else if (hours >= 1)
24
- return `${hours}h ${minutes}m`;
25
- else if (minutes >= 1)
26
- return `${minutes}m ${seconds}s`;
27
- else
28
- return `${seconds}s`;
29
- }
30
- getSubcommands(name) {
31
- if (!name || typeof name !== 'string')
32
- throw new XernerxError(`Expected name to be of type string, received ${typeof name} instead!`);
33
- const commands = [];
34
- this.getAllCommands()
35
- .filter((c) => (c.data?.name?.toLowerCase() || c.name?.toLowerCase()) == name?.toLowerCase())
36
- .map((c) => {
37
- if (c?.data?.options?.length > 0) {
38
- c?.data?.options?.map((option) => {
39
- if (!option?.type) {
40
- if (option?.options?.length > 0) {
41
- option?.options?.map((opt) => {
42
- if (!opt.type) {
43
- commands.push({
44
- name: c.data.name,
45
- formattedName: `${c.data.name} ${option.name} ${opt.name}`,
46
- description: opt.description,
47
- category: c.category || null,
48
- commandType: c.commandType,
49
- });
50
- }
51
- else {
52
- commands.push({
53
- name: c.data.name,
54
- formattedName: `${c.data.name} ${option.name}`,
55
- description: option.description,
56
- category: c.category || null,
57
- commandType: c.commandType,
58
- });
59
- }
60
- });
61
- }
62
- else {
63
- commands.push({
64
- name: c.data.name,
65
- formattedName: `${c.data.name} ${option.name}`,
66
- description: option.description,
67
- category: c.category || null,
68
- commandType: c.commandType,
69
- });
70
- }
71
- }
72
- else {
73
- commands.push({
74
- name: c.data.name,
75
- formattedName: `${c.data.name}`,
76
- description: c.data.description,
77
- category: c.category || null,
78
- commandType: c.commandType,
79
- });
80
- }
81
- });
82
- }
83
- else {
84
- commands.push({
85
- name: c.data?.name || c.name,
86
- formattedName: `${c.data?.name || c.name}`,
87
- description: c.data?.description || c.description,
88
- category: c.category || null,
89
- commandType: c.commandType,
90
- });
91
- }
92
- });
93
- return commands;
94
- }
95
- isOwner(userId) {
96
- if (!userId)
97
- throw new XernerxError('No ID specified');
98
- let owners = this.client.settings.ownerId;
99
- if (!owners)
100
- return false;
101
- if (typeof owners === 'string')
102
- owners = [owners];
103
- return owners.includes(userId);
104
- }
105
- getAllCommands() {
106
- const cmds = [];
107
- for (const commands of Object.values(this.client.commands)) {
108
- commands.map((cmd) => cmds.push(cmd));
109
- }
110
- return cmds;
111
- }
112
- getAllMessageCommands() {
113
- const cmds = [];
114
- this.client.commands.message.map((cmd) => cmds.push(cmd));
115
- return cmds;
116
- }
117
- getAllSlashCommands() {
118
- const cmds = [];
119
- this.client.commands.slash.map((cmd) => cmds.push(cmd));
120
- return cmds;
121
- }
122
- getAllContextCommands() {
123
- const cmds = [];
124
- this.client.commands.context.map((cmd) => cmds.push(cmd));
125
- return cmds;
126
- }
127
- setPresence(options) {
128
- const client = this.client;
129
- function pres() {
130
- client.user?.setPresence({
131
- activities: [
132
- {
133
- name: options.text || undefined,
134
- type: options.type || undefined,
135
- url: options.link || undefined,
136
- },
137
- ],
138
- status: options.status || undefined,
139
- });
140
- }
141
- pres();
142
- if (options.interval) {
143
- setInterval(() => {
144
- pres();
145
- }, options.interval);
146
- }
147
- }
148
- getCooldowns(id, command) {
149
- let cooldowns = [];
150
- for (const [key, value] of Object.entries(this.client.cache)) {
151
- if (!['cooldowns', 'messageCommands', 'slashCommands', 'contextCommands', 'commands'].includes(key))
152
- continue;
153
- if (key === 'commands') {
154
- if (command) {
155
- value.map((x) => {
156
- const name = x.name.split(/-/);
157
- name.pop();
158
- if (name.join('-') === id + '-' + command) {
159
- cooldowns.push(x);
160
- }
161
- });
162
- }
163
- else {
164
- value.map((x) => {
165
- if (x.name.split(/-/).shift() === id) {
166
- cooldowns.push(x);
167
- }
168
- });
169
- }
170
- }
171
- else {
172
- if (value.has(id)) {
173
- const x = value.get(id);
174
- cooldowns.push(x);
175
- }
176
- }
177
- }
178
- return cooldowns;
179
- }
180
- getCooldownTimers(id, command) {
181
- let cooldowns = [];
182
- for (const [key, value] of Object.entries(this.client.cache)) {
183
- if (!['cooldowns', 'messageCommands', 'slashCommands', 'contextCommands', 'commands'].includes(key))
184
- continue;
185
- if (key === 'commands') {
186
- if (command) {
187
- value.map((x) => {
188
- const name = x.name.split(/-/);
189
- name.pop();
190
- if (name.join('-') === id + '-' + command) {
191
- cooldowns.push({ [x.commandName]: x.endsAt - Date.now() });
192
- }
193
- });
194
- }
195
- else {
196
- value.map((x) => {
197
- if (x.name.split(/-/).shift() === id) {
198
- cooldowns.push({ [x.commandName]: x.endsAt - Date.now() });
199
- }
200
- });
201
- }
202
- }
203
- else {
204
- if (value.has(id)) {
205
- const x = value.get(id);
206
- cooldowns.push({ [key]: x.endsAt - Date.now() });
207
- }
208
- }
209
- }
210
- const sort = cooldowns.map((x) => Object.entries(x).shift()).sort((a, b) => b[1] - a[1]);
211
- cooldowns = [];
212
- sort.map(([key, value]) => cooldowns.push({ [key]: value }));
213
- return cooldowns;
214
- }
215
- async defer(time) {
216
- return new Promise((resolve) => setTimeout(resolve, time || 0));
217
- }
218
- }
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)
9
+ timestamp = this.client.uptime || 0;
10
+ let totalSeconds = timestamp / 1000;
11
+ let years = Math.floor(totalSeconds / 31536000);
12
+ totalSeconds %= 31536000;
13
+ let days = Math.floor(totalSeconds / 86400);
14
+ totalSeconds %= 86400;
15
+ let hours = Math.floor(totalSeconds / 3600);
16
+ totalSeconds %= 3600;
17
+ let minutes = Math.floor(totalSeconds / 60);
18
+ let seconds = Math.floor(totalSeconds % 60);
19
+ if (years >= 1)
20
+ return `${years}y ${days}d ${hours}h ${minutes}m`;
21
+ else if (days >= 1)
22
+ return `${days}d ${hours}h ${minutes}m`;
23
+ else if (hours >= 1)
24
+ return `${hours}h ${minutes}m`;
25
+ else if (minutes >= 1)
26
+ return `${minutes}m ${seconds}s`;
27
+ else
28
+ return `${seconds}s`;
29
+ }
30
+ getSubcommands(name) {
31
+ if (!name || typeof name !== 'string')
32
+ throw new XernerxError(`Expected name to be of type string, received ${typeof name} instead!`);
33
+ const commands = [];
34
+ this.getAllCommands()
35
+ .filter((c) => (c.data?.name?.toLowerCase() || c.name?.toLowerCase()) == name?.toLowerCase())
36
+ .map((c) => {
37
+ if (c?.data?.options?.length > 0) {
38
+ c?.data?.options?.map((option) => {
39
+ if (!option?.type) {
40
+ if (option?.options?.length > 0) {
41
+ option?.options?.map((opt) => {
42
+ if (!opt.type) {
43
+ commands.push({
44
+ name: c.data.name,
45
+ formattedName: `${c.data.name} ${option.name} ${opt.name}`,
46
+ description: opt.description,
47
+ category: c.category || null,
48
+ commandType: c.commandType,
49
+ });
50
+ }
51
+ else {
52
+ commands.push({
53
+ name: c.data.name,
54
+ formattedName: `${c.data.name} ${option.name}`,
55
+ description: option.description,
56
+ category: c.category || null,
57
+ commandType: c.commandType,
58
+ });
59
+ }
60
+ });
61
+ }
62
+ else {
63
+ commands.push({
64
+ name: c.data.name,
65
+ formattedName: `${c.data.name} ${option.name}`,
66
+ description: option.description,
67
+ category: c.category || null,
68
+ commandType: c.commandType,
69
+ });
70
+ }
71
+ }
72
+ else {
73
+ commands.push({
74
+ name: c.data.name,
75
+ formattedName: `${c.data.name}`,
76
+ description: c.data.description,
77
+ category: c.category || null,
78
+ commandType: c.commandType,
79
+ });
80
+ }
81
+ });
82
+ }
83
+ else {
84
+ commands.push({
85
+ name: c.data?.name || c.name,
86
+ formattedName: `${c.data?.name || c.name}`,
87
+ description: c.data?.description || c.description,
88
+ category: c.category || null,
89
+ commandType: c.commandType,
90
+ });
91
+ }
92
+ });
93
+ return commands;
94
+ }
95
+ isOwner(userId) {
96
+ if (!userId)
97
+ throw new XernerxError('No ID specified');
98
+ let owners = this.client.settings.ownerId;
99
+ if (!owners)
100
+ return false;
101
+ if (typeof owners === 'string')
102
+ owners = [owners];
103
+ return owners.includes(userId);
104
+ }
105
+ getAllCommands() {
106
+ const cmds = [];
107
+ for (const commands of Object.values(this.client.commands)) {
108
+ commands.map((cmd) => cmds.push(cmd));
109
+ }
110
+ return cmds;
111
+ }
112
+ getAllMessageCommands() {
113
+ const cmds = [];
114
+ this.client.commands.message.map((cmd) => cmds.push(cmd));
115
+ return cmds;
116
+ }
117
+ getAllSlashCommands() {
118
+ const cmds = [];
119
+ this.client.commands.slash.map((cmd) => cmds.push(cmd));
120
+ return cmds;
121
+ }
122
+ getAllContextCommands() {
123
+ const cmds = [];
124
+ this.client.commands.context.map((cmd) => cmds.push(cmd));
125
+ return cmds;
126
+ }
127
+ setPresence(options) {
128
+ const client = this.client;
129
+ function pres() {
130
+ client.user?.setPresence({
131
+ activities: [
132
+ {
133
+ name: options.text || undefined,
134
+ type: options.type || undefined,
135
+ url: options.link || undefined,
136
+ },
137
+ ],
138
+ status: options.status || undefined,
139
+ });
140
+ }
141
+ pres();
142
+ if (options.interval) {
143
+ setInterval(() => {
144
+ pres();
145
+ }, options.interval);
146
+ }
147
+ }
148
+ getCooldowns(id, command) {
149
+ let cooldowns = [];
150
+ for (const [key, value] of Object.entries(this.client.cache)) {
151
+ if (!['cooldowns', 'messageCommands', 'slashCommands', 'contextCommands', 'commands'].includes(key))
152
+ continue;
153
+ if (key === 'commands') {
154
+ if (command) {
155
+ value.map((x) => {
156
+ const name = x.name.split(/-/);
157
+ name.pop();
158
+ if (name.join('-') === id + '-' + command) {
159
+ cooldowns.push(x);
160
+ }
161
+ });
162
+ }
163
+ else {
164
+ value.map((x) => {
165
+ if (x.name.split(/-/).shift() === id) {
166
+ cooldowns.push(x);
167
+ }
168
+ });
169
+ }
170
+ }
171
+ else {
172
+ if (value.has(id)) {
173
+ const x = value.get(id);
174
+ cooldowns.push(x);
175
+ }
176
+ }
177
+ }
178
+ return cooldowns;
179
+ }
180
+ getCooldownTimers(id, command) {
181
+ let cooldowns = [];
182
+ for (const [key, value] of Object.entries(this.client.cache)) {
183
+ if (!['cooldowns', 'messageCommands', 'slashCommands', 'contextCommands', 'commands'].includes(key))
184
+ continue;
185
+ if (key === 'commands') {
186
+ if (command) {
187
+ value.map((x) => {
188
+ const name = x.name.split(/-/);
189
+ name.pop();
190
+ if (name.join('-') === id + '-' + command) {
191
+ cooldowns.push({
192
+ [x.commandName]: x.endsAt - Date.now(),
193
+ });
194
+ }
195
+ });
196
+ }
197
+ else {
198
+ value.map((x) => {
199
+ if (x.name.split(/-/).shift() === id) {
200
+ cooldowns.push({
201
+ [x.commandName]: x.endsAt - Date.now(),
202
+ });
203
+ }
204
+ });
205
+ }
206
+ }
207
+ else {
208
+ if (value.has(id)) {
209
+ const x = value.get(id);
210
+ cooldowns.push({ [key]: x.endsAt - Date.now() });
211
+ }
212
+ }
213
+ }
214
+ const sort = cooldowns.map((x) => Object.entries(x).shift()).sort((a, b) => b[1] - a[1]);
215
+ cooldowns = [];
216
+ sort.map(([key, value]) => cooldowns.push({ [key]: value }));
217
+ return cooldowns;
218
+ }
219
+ async defer(time) {
220
+ return new Promise((resolve) => setTimeout(resolve, time || 0));
221
+ }
222
+ }