xernerx 3.5.1 → 3.6.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 (121) hide show
  1. package/dist/{build → cjs/build}/ContextCommandBuilder.d.ts +31 -28
  2. package/dist/cjs/build/ContextCommandBuilder.js +97 -0
  3. package/dist/cjs/build/EventBuilder.js +44 -0
  4. package/dist/{build → cjs/build}/InhibitorBuilder.d.ts +1 -1
  5. package/dist/cjs/build/InhibitorBuilder.js +37 -0
  6. package/dist/{build → cjs/build}/MessageCommandBuilder.d.ts +23 -17
  7. package/dist/cjs/build/MessageCommandBuilder.js +100 -0
  8. package/dist/{build → cjs/build}/SlashCommandBuilder.d.ts +25 -18
  9. package/dist/cjs/build/SlashCommandBuilder.js +169 -0
  10. package/dist/{client → cjs/client}/XernerxClient.d.ts +1 -0
  11. package/dist/cjs/client/XernerxClient.js +120 -0
  12. package/dist/{handlers → cjs/handlers}/CommandHandler.js +11 -8
  13. package/dist/{handlers → cjs/handlers}/EventHandler.js +6 -3
  14. package/dist/cjs/handlers/Handler.js +308 -0
  15. package/dist/{handlers → cjs/handlers}/InhibitorHandler.js +6 -3
  16. package/dist/cjs/handlers/WebhookHandler.d.ts +7 -0
  17. package/dist/cjs/handlers/WebhookHandler.js +23 -0
  18. package/dist/{main.d.ts → cjs/main.d.ts} +15 -1
  19. package/dist/cjs/main.js +112 -0
  20. package/dist/{models → cjs/models}/CommandArguments.d.ts +1 -1
  21. package/dist/{models → cjs/models}/CommandArguments.js +37 -52
  22. package/dist/cjs/models/Events.js +309 -0
  23. package/dist/cjs/models/Extensions.js +26 -0
  24. package/dist/cjs/models/XernerxUser.d.ts +2 -0
  25. package/dist/cjs/models/XernerxUser.js +12 -0
  26. package/dist/{tools → cjs/tools}/XernerxError.js +4 -1
  27. package/dist/{tools → cjs/tools}/package.d.ts +4 -9
  28. package/dist/{tools → cjs/tools}/package.js +14 -17
  29. package/dist/cjs/types/enums.d.ts +44 -0
  30. package/dist/cjs/types/enums.js +38 -0
  31. package/dist/{types → cjs/types}/interfaces.d.ts +2 -0
  32. package/dist/cjs/types/interfaces.js +2 -0
  33. package/dist/{types → cjs/types}/options.d.ts +13 -0
  34. package/dist/cjs/types/options.js +2 -0
  35. package/dist/{types → cjs/types}/types.d.ts +38 -10
  36. package/dist/cjs/types/types.js +2 -0
  37. package/dist/{utils → cjs/utils}/ClientUtil.d.ts +1 -0
  38. package/dist/{utils → cjs/utils}/ClientUtil.js +73 -84
  39. package/dist/{utils → cjs/utils}/CommandUtil.d.ts +4 -2
  40. package/dist/{utils → cjs/utils}/CommandUtil.js +102 -103
  41. package/dist/{validators → cjs/validators}/CommandValidations.d.ts +6 -1
  42. package/dist/{validators → cjs/validators}/CommandValidations.js +36 -50
  43. package/dist/{validators → cjs/validators}/InhibitorValidations.js +12 -14
  44. package/dist/mjs/build/ContextCommandBuilder.d.ts +63 -0
  45. package/dist/mjs/build/ContextCommandBuilder.js +97 -0
  46. package/dist/mjs/build/EventBuilder.d.ts +21 -0
  47. package/dist/mjs/build/EventBuilder.js +44 -0
  48. package/dist/mjs/build/InhibitorBuilder.d.ts +19 -0
  49. package/dist/mjs/build/InhibitorBuilder.js +37 -0
  50. package/dist/mjs/build/MessageCommandBuilder.d.ts +59 -0
  51. package/dist/mjs/build/MessageCommandBuilder.js +100 -0
  52. package/dist/mjs/build/SlashCommandBuilder.d.ts +65 -0
  53. package/dist/mjs/build/SlashCommandBuilder.js +169 -0
  54. package/dist/mjs/client/XernerxClient.d.ts +29 -0
  55. package/dist/mjs/client/XernerxClient.js +120 -0
  56. package/dist/mjs/handlers/CommandHandler.d.ts +27 -0
  57. package/dist/mjs/handlers/CommandHandler.js +45 -0
  58. package/dist/mjs/handlers/EventHandler.d.ts +13 -0
  59. package/dist/mjs/handlers/EventHandler.js +19 -0
  60. package/dist/mjs/handlers/Handler.d.ts +57 -0
  61. package/dist/mjs/handlers/Handler.js +308 -0
  62. package/dist/mjs/handlers/InhibitorHandler.d.ts +18 -0
  63. package/dist/mjs/handlers/InhibitorHandler.js +24 -0
  64. package/dist/mjs/handlers/WebhookHandler.d.ts +7 -0
  65. package/dist/mjs/handlers/WebhookHandler.js +23 -0
  66. package/dist/{main.js → mjs/main.d.ts} +20 -18
  67. package/dist/mjs/main.js +112 -0
  68. package/dist/mjs/models/CommandArguments.d.ts +17 -0
  69. package/dist/mjs/models/CommandArguments.js +106 -0
  70. package/dist/mjs/models/Events.d.ts +24 -0
  71. package/dist/mjs/models/Events.js +309 -0
  72. package/dist/mjs/models/Extensions.d.ts +7 -0
  73. package/dist/mjs/models/Extensions.js +26 -0
  74. package/dist/mjs/models/XernerxUser.d.ts +2 -0
  75. package/dist/mjs/models/XernerxUser.js +12 -0
  76. package/dist/mjs/tools/XernerxError.d.ts +5 -0
  77. package/dist/mjs/tools/XernerxError.js +11 -0
  78. package/dist/mjs/tools/package.d.ts +44 -0
  79. package/dist/mjs/tools/package.js +45 -0
  80. package/dist/mjs/types/enums.d.ts +44 -0
  81. package/dist/mjs/types/enums.js +38 -0
  82. package/dist/mjs/types/interfaces.d.ts +27 -0
  83. package/dist/mjs/types/interfaces.js +2 -0
  84. package/dist/mjs/types/options.d.ts +254 -0
  85. package/dist/mjs/types/options.js +2 -0
  86. package/dist/mjs/types/types.d.ts +62 -0
  87. package/dist/mjs/types/types.js +2 -0
  88. package/dist/mjs/utils/ClientUtil.d.ts +26 -0
  89. package/dist/mjs/utils/ClientUtil.js +211 -0
  90. package/dist/mjs/utils/CommandUtil.d.ts +58 -0
  91. package/dist/mjs/utils/CommandUtil.js +247 -0
  92. package/dist/mjs/validators/CommandValidations.d.ts +12 -0
  93. package/dist/mjs/validators/CommandValidations.js +169 -0
  94. package/dist/mjs/validators/InhibitorValidations.d.ts +11 -0
  95. package/dist/mjs/validators/InhibitorValidations.js +40 -0
  96. package/package.json +11 -15
  97. package/dist/build/ContextCommandBuilder.js +0 -93
  98. package/dist/build/EventBuilder.js +0 -34
  99. package/dist/build/InhibitorBuilder.js +0 -27
  100. package/dist/build/MessageCommandBuilder.js +0 -90
  101. package/dist/build/SlashCommandBuilder.js +0 -125
  102. package/dist/client/XernerxClient.js +0 -101
  103. package/dist/handlers/Handler.js +0 -250
  104. package/dist/main.cjs +0 -2023
  105. package/dist/models/Events.js +0 -294
  106. package/dist/models/Extensions.js +0 -23
  107. package/dist/types/enums.d.ts +0 -35
  108. package/dist/types/enums.js +0 -35
  109. package/dist/types/interfaces.js +0 -1
  110. package/dist/types/options.js +0 -1
  111. package/dist/types/types.js +0 -1
  112. package/dist/validators/Shapes.js +0 -1
  113. /package/dist/{build → cjs/build}/EventBuilder.d.ts +0 -0
  114. /package/dist/{handlers → cjs/handlers}/CommandHandler.d.ts +0 -0
  115. /package/dist/{handlers → cjs/handlers}/EventHandler.d.ts +0 -0
  116. /package/dist/{handlers → cjs/handlers}/Handler.d.ts +0 -0
  117. /package/dist/{handlers → cjs/handlers}/InhibitorHandler.d.ts +0 -0
  118. /package/dist/{models → cjs/models}/Events.d.ts +0 -0
  119. /package/dist/{models → cjs/models}/Extensions.d.ts +0 -0
  120. /package/dist/{tools → cjs/tools}/XernerxError.d.ts +0 -0
  121. /package/dist/{validators → cjs/validators}/InhibitorValidations.d.ts +0 -0
@@ -1,101 +0,0 @@
1
- import { Client, Collection } from 'discord.js';
2
- import { z } from 'zod';
3
- import { Style } from 'dumfunctions';
4
- import { ClientUtil } from '../utils/ClientUtil.js';
5
- import CommandHandler from '../handlers/CommandHandler.js';
6
- import EventHandler from '../handlers/EventHandler.js';
7
- import InhibitorHandler from '../handlers/InhibitorHandler.js';
8
- import Extensions from '../models/Extensions.js';
9
- // TODO - Add commandNotFound as an event to the client.
10
- /**
11
- * @description - The Client.
12
- * @param {DiscordOptions} discordOptions - The options for discord.js.
13
- * @param {ClientOptions} clientOptions - The options for the Xernerx Client.
14
- * @extends {Client}
15
- */
16
- export default class XernerxClient extends Client {
17
- settings;
18
- commands;
19
- cache;
20
- modules;
21
- util;
22
- handlerOptions;
23
- events;
24
- extensions;
25
- inhibitors;
26
- config;
27
- constructor(discordOptions, clientOptions, config) {
28
- super(discordOptions);
29
- this.settings = z
30
- .object({
31
- ownerId: z.string().or(z.array(z.string())).default([]),
32
- permissions: z
33
- .object({
34
- client: z.array(z.string()).default([]),
35
- user: z.array(z.string()).default([]),
36
- dm: z.boolean().default(false),
37
- })
38
- .optional(),
39
- ignore: z
40
- .object({
41
- owner: z.boolean().default(false),
42
- users: z.array(z.string()),
43
- channels: z.array(z.string()),
44
- guilds: z.array(z.string()),
45
- })
46
- .optional(),
47
- log: z
48
- .object({
49
- ready: z.boolean().default(false),
50
- error: z.boolean().default(false),
51
- })
52
- .optional(),
53
- cooldown: z
54
- .object({
55
- command: z.number().default(0),
56
- cache: z.number().default(0),
57
- })
58
- .optional(),
59
- })
60
- .parse(clientOptions);
61
- this.config = config || {};
62
- this.commands = {
63
- message: new Collection(),
64
- slash: new Collection(),
65
- context: new Collection(),
66
- };
67
- this.events = new Collection();
68
- this.inhibitors = new Collection();
69
- this.cache = {
70
- messages: new Collection(),
71
- cooldowns: new Collection(),
72
- messageCommands: new Collection(),
73
- slashCommands: new Collection(),
74
- contextCommands: new Collection(),
75
- commands: new Collection(),
76
- };
77
- this.modules = {
78
- commandHandler: new CommandHandler(this),
79
- eventHandler: new EventHandler(this),
80
- inhibitorHandler: new InhibitorHandler(this),
81
- };
82
- this.extensions = {};
83
- this.util = new ClientUtil(this);
84
- this.handlerOptions = {};
85
- if (this.settings?.log?.ready) {
86
- this.once('ready', async (client) => {
87
- const size = (await client.guilds.fetch()).size;
88
- console.info(Style.log(`Xernerx | ${client.user.tag} signed in watching ${size} server${size > 1 ? 's' : ''}. ${(this.handlerOptions.slash || this.handlerOptions.context)?.guildId
89
- ? `Using ${(await this.guilds.fetch((this.handlerOptions.slash || this.handlerOptions.context)?.guildId || '0')).name} as local guild.`
90
- : ''}`, { color: Style.TextColor.Purple }));
91
- });
92
- }
93
- }
94
- register(token) {
95
- this.login(token);
96
- }
97
- loadAllExtensions(options) {
98
- const extensions = new Extensions(this);
99
- return extensions.load(options.extensions, options.logging || false);
100
- }
101
- }
@@ -1,250 +0,0 @@
1
- import fs from 'fs';
2
- import * as path from 'path';
3
- import { CommandType } from '../types/enums.js';
4
- import { s } from '@sapphire/shapeshift';
5
- import { Style } from 'dumfunctions';
6
- /**
7
- * @description - The Handler class.
8
- * @param {XernerxClient} client - The XernerxClient.
9
- */
10
- export class Handler {
11
- client;
12
- commands;
13
- readyTimestamp;
14
- constructor(client) {
15
- this.client = client;
16
- this.commands = [];
17
- this.readyTimestamp = Number(Date.now());
18
- }
19
- /**
20
- * @description - The loader for the message commands.
21
- * @param {MessageCommandOptions} options - The options for the message command loader.
22
- */
23
- loadAllMessageCommands(options) {
24
- this.client.handlerOptions.message = s
25
- .object({
26
- directory: s.string,
27
- prefix: s.union(s.string, s.array(s.string)),
28
- allowMention: s.boolean.default(false),
29
- cooldown: s.number.default(0),
30
- userPermissions: s.array(s.bigint).default([]),
31
- clientPermissions: s.array(s.bigint).default([]),
32
- handleEdits: s.boolean.default(false),
33
- handleDeletes: s.boolean.default(false),
34
- handleTyping: s.boolean.default(false),
35
- logging: s.boolean.default(false),
36
- })
37
- .parse(options);
38
- const files = this.readdir(options.directory), loaded = [];
39
- for (const file of files) {
40
- this.load(options.directory, file, CommandType.MessageCommand);
41
- loaded.push(file.replace('.js', ''));
42
- }
43
- if (this.client.handlerOptions.message?.logging)
44
- console.info(Style.log(`Xernerx | Loaded ${loaded.length} message commands: ${loaded.join(', ')}.`, {
45
- color: Style.TextColor.Cyan,
46
- }));
47
- }
48
- /**
49
- * @description - The loader for the slash commands.
50
- * @param {SlashCommandOptions} options - The options for the slash command loader.
51
- */
52
- loadAllSlashCommands(options) {
53
- this.client.handlerOptions.slash = s
54
- .object({
55
- directory: s.string,
56
- guildId: s.string,
57
- global: s.boolean,
58
- cooldown: s.number.default(0),
59
- userPermissions: s.array(s.bigint).default([]),
60
- clientPermissions: s.array(s.bigint).default([]),
61
- logging: s.boolean.default(false),
62
- defer: s.object({
63
- reply: s.boolean.optional,
64
- ephemeral: s.boolean.optional,
65
- fetchReply: s.boolean.optional,
66
- }).optional,
67
- })
68
- .parse(options);
69
- const files = this.readdir(options.directory), loaded = [];
70
- for (const file of files) {
71
- this.load(options.directory, file, CommandType.SlashCommand);
72
- loaded.push(file.replace('.js', ''));
73
- }
74
- if (this.client.handlerOptions.slash?.logging)
75
- console.info(Style.log(`Xernerx | Loaded ${loaded.length} slash commands: ${loaded.join(', ')}.`, {
76
- color: Style.TextColor.Cyan,
77
- }));
78
- }
79
- /**
80
- * @description - The loader for the context commands.
81
- * @param {ContextCommandOptions} options - The options for the context command loader.
82
- */
83
- loadAllContextCommands(options) {
84
- this.client.handlerOptions.context = s
85
- .object({
86
- directory: s.string,
87
- guildId: s.string,
88
- global: s.boolean,
89
- cooldown: s.number.default(0),
90
- userPermissions: s.array(s.bigint).default([]),
91
- clientPermissions: s.array(s.bigint).default([]),
92
- logging: s.boolean.default(false),
93
- defer: s.object({
94
- reply: s.boolean.optional,
95
- ephemeral: s.boolean.optional,
96
- fetchReply: s.boolean.optional,
97
- }).optional,
98
- })
99
- .parse(options);
100
- const files = this.readdir(options.directory), loaded = [];
101
- for (const file of files) {
102
- this.load(options.directory, file, CommandType.ContextCommand);
103
- loaded.push(file.replace('.js', ''));
104
- }
105
- if (this.client.handlerOptions.context?.logging)
106
- console.info(Style.log(`Xernerx | Loaded ${loaded.length} context commands: ${loaded.join(', ')}.`, {
107
- color: Style.TextColor.Cyan,
108
- }));
109
- }
110
- /**
111
- * @description - The loader for the events.
112
- * @param {EventLoadOptions} options - The options for the event loader.
113
- */
114
- loadAllEvents(options) {
115
- this.client.handlerOptions.events = s
116
- .object({
117
- directory: s.string,
118
- logging: s.boolean.default(false),
119
- })
120
- .parse(options);
121
- const files = this.readdir(options.directory), loaded = [];
122
- (async () => {
123
- for (const file of files) {
124
- try {
125
- options.directory.split(/\//).shift();
126
- let event = (await import('file://' + `${path.resolve(options.directory)}/${file}`)).default;
127
- event = new event();
128
- event.client = this.client;
129
- event.commandType = CommandType.Event;
130
- this.client.events.set(event.name, event);
131
- this.emitter(event);
132
- }
133
- catch (error) {
134
- console.error(Style.log(`Xernerx | Couldn't load ${file} because <${error}>`, { color: Style.BackgroundColor.Red }));
135
- }
136
- loaded.push(file.replace('.js', ''));
137
- }
138
- if (this.client.handlerOptions.events?.logging)
139
- console.info(Style.log(`Xernerx | Loaded ${loaded.length} events: ${loaded.join(', ')}.`, { color: Style.TextColor.Cyan }));
140
- })();
141
- }
142
- /**
143
- * @description - The loader for the inhibitors.
144
- * @param {InhibitorLoadOptions} options - The options for the inhibitor loader.
145
- */
146
- loadAllInhibitors(options) {
147
- this.client.handlerOptions.inhibitors = s
148
- .object({
149
- directory: s.string,
150
- logging: s.boolean.default(false),
151
- })
152
- .parse(options);
153
- const files = this.readdir(options.directory), loaded = [];
154
- for (const file of files) {
155
- this.load(options.directory, file, CommandType.Inhibitor);
156
- loaded.push(file.replace('.js', ''));
157
- }
158
- if (this.client.handlerOptions.inhibitors?.logging)
159
- console.info(Style.log(`Xernerx | Loaded ${loaded.length} inhibitors: ${loaded.join(', ')}.`, {
160
- color: Style.TextColor.Cyan,
161
- }));
162
- }
163
- /**
164
- * @description - a reader for directories
165
- * @param {string} dir - the directory to look for.
166
- * @returns array of files.
167
- */
168
- readdir(dir) {
169
- try {
170
- return fs.readdirSync(path.resolve(dir)).filter((file) => file.endsWith('.js'));
171
- }
172
- catch (error) {
173
- console.error(Style.log(`Xernerx | Couldn't read ${dir} because <${error}>.`, { color: Style.BackgroundColor.Red }));
174
- }
175
- return [];
176
- }
177
- /**
178
- * @description file loader.
179
- * @param {string} dir - the directory.
180
- * @param {string} file - the file in the directory.
181
- * @param {string} type - the type of file.
182
- * @returns undefined
183
- */
184
- async load(dir, file, type) {
185
- try {
186
- dir.split(/\//).shift();
187
- let command = (await import('file://' + `${path.resolve(dir)}/${file}`)).default;
188
- command = new command();
189
- command.client = this.client;
190
- command.commandType = type;
191
- command.filepath = `${path.resolve(dir)}\\${file}`;
192
- command.file = file;
193
- if (type === CommandType.MessageCommand)
194
- this.client.commands.message.set(command?.name || command?.name, command);
195
- if (type === CommandType.SlashCommand) {
196
- this.client.commands.slash.set(command?.data?.name || command?.name, command);
197
- }
198
- if (type === CommandType.ContextCommand) {
199
- this.client.commands.context.set(command?.data?.name || command?.name, command);
200
- }
201
- if (type === CommandType.Event) {
202
- this.client.events.set(command.name, command);
203
- }
204
- if (type === CommandType.Inhibitor) {
205
- this.client.inhibitors.set(command.name, command);
206
- }
207
- }
208
- catch (error) {
209
- console.error(Style.log(`Xernerx | Couldn't load ${file} because <${error}>`, { color: Style.BackgroundColor.Red }));
210
- }
211
- }
212
- /**
213
- * @description the event emitter to emit all events.
214
- * @param {object} event - the event to be emitted.
215
- * @returns void
216
- */
217
- emitter(event) {
218
- const client = this.client;
219
- if (event.emitter === 'client') {
220
- if (event.once)
221
- client.once(event.name, (...args) => {
222
- event.run(...args);
223
- });
224
- else
225
- client.on(event.name, (...args) => {
226
- event.run(...args);
227
- });
228
- }
229
- else if (event.emitter === 'rest') {
230
- if (event.once)
231
- client.once(event.name, (...args) => {
232
- event.run(...args);
233
- });
234
- else
235
- client.on(event.name, (...args) => {
236
- event.run(...args);
237
- });
238
- }
239
- else if (event.emitter === 'process') {
240
- if (event.once)
241
- process.once(event.name, (...args) => {
242
- event.run(...args);
243
- });
244
- else
245
- process.on(event.name, (...args) => {
246
- event.run(...args);
247
- });
248
- }
249
- }
250
- }