xernerx 4.14.1 → 4.15.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 (140) hide show
  1. package/dist/cjs/build/XernerxContextCommand.js +124 -0
  2. package/dist/cjs/build/XernerxEvent.js +34 -0
  3. package/dist/cjs/build/XernerxInhibitor.js +30 -0
  4. package/dist/cjs/build/XernerxMessageCommand.js +122 -0
  5. package/dist/cjs/build/XernerxSlashCommand.js +180 -0
  6. package/dist/cjs/client/XernerxClient.js +105 -0
  7. package/dist/cjs/client/XernerxShardClient.js +56 -0
  8. package/dist/cjs/functions/deploy.js +66 -0
  9. package/dist/cjs/functions/load.js +38 -0
  10. package/dist/cjs/functions/reload.js +33 -0
  11. package/dist/cjs/functions/setPresence.js +24 -0
  12. package/dist/cjs/functions/xernerxUser.js +15 -0
  13. package/dist/cjs/handlers/CommandHandler.js +342 -0
  14. package/dist/cjs/handlers/EventHandler.js +32 -0
  15. package/dist/cjs/handlers/ExtensionHandler.js +32 -0
  16. package/dist/cjs/handlers/Handler.js +48 -0
  17. package/dist/cjs/handlers/InhibitorHandler.js +34 -0
  18. package/dist/cjs/handlers/IntegrationHandler.js +29 -0
  19. package/dist/cjs/main.js +36 -0
  20. package/dist/cjs/models/Arguments.js +159 -0
  21. package/dist/cjs/models/Cooldowns.js +36 -0
  22. package/dist/cjs/tools/XernerxError.js +14 -0
  23. package/dist/cjs/tools/XernerxIntents.js +27 -0
  24. package/dist/cjs/tools/XernerxLog.js +98 -0
  25. package/dist/cjs/tools/XernerxText.js +92 -0
  26. package/dist/cjs/types/extenders.js +3 -0
  27. package/dist/cjs/types/interfaces.js +3 -0
  28. package/dist/cjs/types/types.js +3 -0
  29. package/dist/{utils → cjs/utils}/ClientUtil.d.ts +1 -1
  30. package/dist/cjs/utils/ClientUtil.js +84 -0
  31. package/dist/{utils → cjs/utils}/InteractionUtil.d.ts +2 -1
  32. package/dist/cjs/utils/InteractionUtil.js +156 -0
  33. package/dist/{utils → cjs/utils}/MessageUtil.d.ts +2 -0
  34. package/dist/cjs/utils/MessageUtil.js +170 -0
  35. package/dist/cjs/utils/Util.js +14 -0
  36. package/dist/cjs/validators/commandValidation.js +127 -0
  37. package/dist/cjs/validators/inhibitorValidations.js +49 -0
  38. package/dist/mjs/build/XernerxContextCommand.d.ts +53 -0
  39. package/dist/mjs/build/XernerxEvent.d.ts +25 -0
  40. package/dist/mjs/build/XernerxInhibitor.d.ts +29 -0
  41. package/dist/mjs/build/XernerxMessageCommand.d.ts +57 -0
  42. package/dist/mjs/build/XernerxSlashCommand.d.ts +69 -0
  43. package/dist/mjs/client/XernerxClient.d.ts +53 -0
  44. package/dist/mjs/client/XernerxShardClient.d.ts +21 -0
  45. package/dist/mjs/functions/deploy.d.ts +3 -0
  46. package/dist/mjs/functions/load.d.ts +4 -0
  47. package/dist/mjs/functions/reload.d.ts +3 -0
  48. package/dist/mjs/functions/setPresence.d.ts +4 -0
  49. package/dist/mjs/functions/xernerxUser.d.ts +4 -0
  50. package/dist/mjs/handlers/CommandHandler.d.ts +16 -0
  51. package/dist/mjs/handlers/EventHandler.d.ts +9 -0
  52. package/dist/mjs/handlers/ExtensionHandler.d.ts +9 -0
  53. package/dist/mjs/handlers/Handler.d.ts +14 -0
  54. package/dist/mjs/handlers/InhibitorHandler.d.ts +9 -0
  55. package/dist/{handlers/WebhookHandler.d.ts → mjs/handlers/IntegrationHandler.d.ts} +8 -1
  56. package/dist/mjs/main.d.ts +40 -0
  57. package/dist/mjs/models/Arguments.d.ts +9 -0
  58. package/dist/mjs/models/Cooldowns.d.ts +11 -0
  59. package/dist/mjs/tools/XernerxError.d.ts +7 -0
  60. package/dist/mjs/tools/XernerxIntents.d.ts +5 -0
  61. package/dist/mjs/tools/XernerxLog.d.ts +28 -0
  62. package/dist/mjs/tools/XernerxText.d.ts +30 -0
  63. package/dist/mjs/types/extenders.d.ts +61 -0
  64. package/dist/mjs/types/interfaces.d.ts +256 -0
  65. package/dist/mjs/types/types.d.ts +14 -0
  66. package/dist/mjs/utils/ClientUtil.d.ts +19 -0
  67. package/dist/{utils → mjs/utils}/ClientUtil.js +1 -1
  68. package/dist/mjs/utils/InteractionUtil.d.ts +25 -0
  69. package/dist/{utils → mjs/utils}/InteractionUtil.js +26 -0
  70. package/dist/mjs/utils/MessageUtil.d.ts +26 -0
  71. package/dist/{utils → mjs/utils}/MessageUtil.js +26 -0
  72. package/dist/mjs/utils/Util.d.ts +9 -0
  73. package/dist/mjs/validators/commandValidation.d.ts +7 -0
  74. package/dist/{validators → mjs/validators}/commandValidation.js +10 -22
  75. package/dist/mjs/validators/inhibitorValidations.d.ts +9 -0
  76. package/package.json +7 -4
  77. package/dist/functions/sendWebhook.d.ts +0 -4
  78. package/dist/functions/sendWebhook.js +0 -14
  79. package/dist/handlers/WebhookHandler.js +0 -10
  80. package/dist/{build → cjs/build}/XernerxContextCommand.d.ts +0 -0
  81. package/dist/{build → cjs/build}/XernerxEvent.d.ts +0 -0
  82. package/dist/{build → cjs/build}/XernerxInhibitor.d.ts +0 -0
  83. package/dist/{build → cjs/build}/XernerxMessageCommand.d.ts +0 -0
  84. package/dist/{build → cjs/build}/XernerxSlashCommand.d.ts +0 -0
  85. package/dist/{client → cjs/client}/XernerxClient.d.ts +3 -3
  86. /package/dist/{client → cjs/client}/XernerxShardClient.d.ts +0 -0
  87. /package/dist/{functions → cjs/functions}/deploy.d.ts +0 -0
  88. /package/dist/{functions → cjs/functions}/load.d.ts +0 -0
  89. /package/dist/{functions → cjs/functions}/reload.d.ts +0 -0
  90. /package/dist/{functions → cjs/functions}/setPresence.d.ts +0 -0
  91. /package/dist/{functions → cjs/functions}/xernerxUser.d.ts +0 -0
  92. /package/dist/{handlers → cjs/handlers}/CommandHandler.d.ts +0 -0
  93. /package/dist/{handlers → cjs/handlers}/EventHandler.d.ts +0 -0
  94. /package/dist/{handlers → cjs/handlers}/ExtensionHandler.d.ts +0 -0
  95. /package/dist/{handlers → cjs/handlers}/Handler.d.ts +0 -0
  96. /package/dist/{handlers → cjs/handlers}/InhibitorHandler.d.ts +0 -0
  97. /package/dist/{handlers → cjs/handlers}/IntegrationHandler.d.ts +0 -0
  98. /package/dist/{main.d.ts → cjs/main.d.ts} +0 -0
  99. /package/dist/{models → cjs/models}/Arguments.d.ts +0 -0
  100. /package/dist/{models → cjs/models}/Cooldowns.d.ts +0 -0
  101. /package/dist/{tools → cjs/tools}/XernerxError.d.ts +0 -0
  102. /package/dist/{tools → cjs/tools}/XernerxIntents.d.ts +0 -0
  103. /package/dist/{tools → cjs/tools}/XernerxLog.d.ts +0 -0
  104. /package/dist/{tools → cjs/tools}/XernerxText.d.ts +0 -0
  105. /package/dist/{types → cjs/types}/extenders.d.ts +0 -0
  106. /package/dist/{types → cjs/types}/interfaces.d.ts +0 -0
  107. /package/dist/{types → cjs/types}/types.d.ts +0 -0
  108. /package/dist/{utils → cjs/utils}/Util.d.ts +0 -0
  109. /package/dist/{validators → cjs/validators}/commandValidation.d.ts +0 -0
  110. /package/dist/{validators → cjs/validators}/inhibitorValidations.d.ts +0 -0
  111. /package/dist/{build → mjs/build}/XernerxContextCommand.js +0 -0
  112. /package/dist/{build → mjs/build}/XernerxEvent.js +0 -0
  113. /package/dist/{build → mjs/build}/XernerxInhibitor.js +0 -0
  114. /package/dist/{build → mjs/build}/XernerxMessageCommand.js +0 -0
  115. /package/dist/{build → mjs/build}/XernerxSlashCommand.js +0 -0
  116. /package/dist/{client → mjs/client}/XernerxClient.js +0 -0
  117. /package/dist/{client → mjs/client}/XernerxShardClient.js +0 -0
  118. /package/dist/{functions → mjs/functions}/deploy.js +0 -0
  119. /package/dist/{functions → mjs/functions}/load.js +0 -0
  120. /package/dist/{functions → mjs/functions}/reload.js +0 -0
  121. /package/dist/{functions → mjs/functions}/setPresence.js +0 -0
  122. /package/dist/{functions → mjs/functions}/xernerxUser.js +0 -0
  123. /package/dist/{handlers → mjs/handlers}/CommandHandler.js +0 -0
  124. /package/dist/{handlers → mjs/handlers}/EventHandler.js +0 -0
  125. /package/dist/{handlers → mjs/handlers}/ExtensionHandler.js +0 -0
  126. /package/dist/{handlers → mjs/handlers}/Handler.js +0 -0
  127. /package/dist/{handlers → mjs/handlers}/InhibitorHandler.js +0 -0
  128. /package/dist/{handlers → mjs/handlers}/IntegrationHandler.js +0 -0
  129. /package/dist/{main.js → mjs/main.js} +0 -0
  130. /package/dist/{models → mjs/models}/Arguments.js +0 -0
  131. /package/dist/{models → mjs/models}/Cooldowns.js +0 -0
  132. /package/dist/{tools → mjs/tools}/XernerxError.js +0 -0
  133. /package/dist/{tools → mjs/tools}/XernerxIntents.js +0 -0
  134. /package/dist/{tools → mjs/tools}/XernerxLog.js +0 -0
  135. /package/dist/{tools → mjs/tools}/XernerxText.js +0 -0
  136. /package/dist/{types → mjs/types}/extenders.js +0 -0
  137. /package/dist/{types → mjs/types}/interfaces.js +0 -0
  138. /package/dist/{types → mjs/types}/types.js +0 -0
  139. /package/dist/{utils → mjs/utils}/Util.js +0 -0
  140. /package/dist/{validators → mjs/validators}/inhibitorValidations.js +0 -0
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ /** @format */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const discord_js_1 = require("discord.js");
5
+ const dumfunctions_1 = require("dumfunctions");
6
+ const XernerxLog_js_1 = __importDefault(require("../tools/XernerxLog.js"));
7
+ const XernerxError_js_1 = __importDefault(require("../tools/XernerxError.js"));
8
+ const globalCommands = [];
9
+ const localCommands = [];
10
+ function deploy(client) {
11
+ const commands = [];
12
+ function stats() {
13
+ client.stats.guildCount = client.guilds.cache.size;
14
+ client.stats.userCount = client.guilds.cache.map((g) => g.memberCount || g.approximateMemberCount || 0).reduce((a, b) => (a += b), 0);
15
+ }
16
+ process.on('message', (message) => {
17
+ if (message.type == 'xernerx')
18
+ client.stats.shardId = message?.data?.shardId;
19
+ if (message.type == 'client')
20
+ client.data = message.data;
21
+ });
22
+ client.on('messageCreate', stats);
23
+ client.on('interactionCreate', stats);
24
+ client.prependOnceListener('ready', (client) => {
25
+ stats();
26
+ client.commands.slash.map((command) => commands.push(command));
27
+ client.commands.context.map((command) => commands.push(command));
28
+ client.commands.slash.map((command) => commands.push(command));
29
+ if (client.commands.slash.size)
30
+ client.commands.slash.map((command) => (command.global ? globalCommands.push(command.data.toJSON()) : localCommands.push(command.data.toJSON())));
31
+ if (client.commands.context.size)
32
+ client.commands.context.map((command) => (command.global ? globalCommands.push(command.data.toJSON()) : localCommands.push(command.data.toJSON())));
33
+ if (globalCommands.length <= 0 && localCommands.length <= 0)
34
+ return;
35
+ try {
36
+ if (client.settings.global) {
37
+ put(client, client.settings.global, globalCommands);
38
+ put(client, !client.settings.global, localCommands);
39
+ }
40
+ else {
41
+ put(client, !client.settings.global, [...globalCommands, ...localCommands]);
42
+ put(client, client.settings.global, []);
43
+ }
44
+ }
45
+ catch (error) {
46
+ new XernerxLog_js_1.default(client).error(`An error occurred while deploying the commands!`, error);
47
+ }
48
+ finally {
49
+ new XernerxLog_js_1.default(client).info(`Deployed ${dumfunctions_1.Style.log(String(commands.filter((command) => command.global).length), {
50
+ color: dumfunctions_1.Style.TextColor.Cyan,
51
+ })} Commands ${client.settings.global
52
+ ? dumfunctions_1.Style.log('globally', { color: dumfunctions_1.Style.TextColor.Green })
53
+ : `${dumfunctions_1.Style.log('locally', { color: dumfunctions_1.Style.TextColor.Red })} in ${dumfunctions_1.Style.log(client.guilds.cache.get(client.settings.local)?.name, { color: dumfunctions_1.Style.TextColor.Blue })}`}.`);
54
+ }
55
+ });
56
+ }
57
+ exports.default = deploy;
58
+ function put(client, global, body) {
59
+ const rest = new discord_js_1.REST({ version: discord_js_1.GatewayVersion }).setToken(client.token);
60
+ if (!global && !client.settings?.local)
61
+ throw new XernerxError_js_1.default(`No guild ID provided as local guild!`);
62
+ if (!global && client.settings?.local)
63
+ return rest.put(discord_js_1.Routes.applicationGuildCommands(client.user?.id, client.settings.local), { body });
64
+ else
65
+ return rest.put(discord_js_1.Routes.applicationCommands(client.user?.id), { body });
66
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ /** @format */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const XernerxLog_js_1 = __importDefault(require("../tools/XernerxLog.js"));
5
+ async function load(client, path, type) {
6
+ try {
7
+ let file = new (await import(`file://${path}`)).default();
8
+ file.filetype = type;
9
+ file.filepath = path;
10
+ file.client = client;
11
+ file.util = {};
12
+ fileSave(client, file, type);
13
+ return file;
14
+ }
15
+ catch (error) {
16
+ new XernerxLog_js_1.default(client).error(`Couldn't load ${type} ${path.match(/\w*\.js$/gim)?.at(0) || path}`, error);
17
+ }
18
+ }
19
+ exports.default = load;
20
+ function fileSave(client, file, type) {
21
+ switch (type) {
22
+ case 'MessageCommand':
23
+ client.commands.message.set(file.name, file);
24
+ break;
25
+ case 'SlashCommand':
26
+ client.commands.slash.set(file.name, file);
27
+ break;
28
+ case 'ContextCommand':
29
+ client.commands.context.set(file.name, file);
30
+ break;
31
+ case 'Inhibitor':
32
+ client.inhibitors.set(file.name, file);
33
+ break;
34
+ case 'Event':
35
+ client.events.set(file.name, file);
36
+ break;
37
+ }
38
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ /** @format */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const path = __importStar(require("path"));
5
+ const fs = __importStar(require("fs"));
6
+ const load_js_1 = __importDefault(require("./load.js"));
7
+ async function reload(client, type) {
8
+ switch (type) {
9
+ case 'message': {
10
+ client.commands.message.clear();
11
+ if (!client.modules.options.message)
12
+ return null;
13
+ const directory = path.resolve(client.modules.options.message?.directory);
14
+ for (const file of fs.readdirSync(directory)) {
15
+ (0, load_js_1.default)(client, `${directory}\\${file}`, 'MessageCommand');
16
+ }
17
+ return true;
18
+ }
19
+ case 'slash': {
20
+ return client.commands.slash.clear();
21
+ }
22
+ case 'context': {
23
+ return client.commands.context.clear();
24
+ }
25
+ case 'events': {
26
+ return client.events.clear();
27
+ }
28
+ case 'inhibitors': {
29
+ return client.inhibitors.clear();
30
+ }
31
+ }
32
+ }
33
+ exports.default = reload;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /** @format */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const discord_js_1 = require("discord.js");
5
+ const dumfunctions_1 = require("dumfunctions");
6
+ function setPresence(client, options) {
7
+ const presence = () => client.user?.setPresence({
8
+ activities: [
9
+ {
10
+ name: options.text,
11
+ type: discord_js_1.ActivityType[dumfunctions_1.Style.titleCase(options.type || 'Custom')],
12
+ url: options.url,
13
+ },
14
+ ],
15
+ status: options.status,
16
+ });
17
+ let response = presence();
18
+ if (options.interval)
19
+ setInterval(() => {
20
+ response = presence();
21
+ }, options.interval);
22
+ return response;
23
+ }
24
+ exports.default = setPresence;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ /** @format */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.xernerxUser = void 0;
5
+ async function xernerxUser(event, client) {
6
+ const author = event.author || event.user;
7
+ author.owner = isOwner(client, author);
8
+ if (client.dbl.validate)
9
+ author.voted = await client?.dbl?.validate(author);
10
+ return author;
11
+ }
12
+ exports.xernerxUser = xernerxUser;
13
+ function isOwner(client, user) {
14
+ return client.settings.ownerId.includes(user.id);
15
+ }
@@ -0,0 +1,342 @@
1
+ "use strict";
2
+ /** @format */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const zod_1 = require("zod");
5
+ const path = __importStar(require("path"));
6
+ const discord_js_1 = require("discord.js");
7
+ const Handler_js_1 = __importDefault(require("./Handler.js"));
8
+ const MessageUtil_js_1 = __importDefault(require("../utils/MessageUtil.js"));
9
+ const xernerxUser_js_1 = require("../functions/xernerxUser.js");
10
+ const InteractionUtil_js_1 = __importDefault(require("../utils/InteractionUtil.js"));
11
+ const commandValidation_js_1 = __importDefault(require("../validators/commandValidation.js"));
12
+ const XernerxLog_js_1 = __importDefault(require("../tools/XernerxLog.js"));
13
+ const Arguments_js_1 = require("../models/Arguments.js");
14
+ const inhibitorValidations_js_1 = require("../validators/inhibitorValidations.js");
15
+ const dumfunctions_1 = require("dumfunctions");
16
+ class CommandHandler extends Handler_js_1.default {
17
+ constructor(client) {
18
+ super(client);
19
+ this.readyTimestamp = Number(Date.now());
20
+ }
21
+ async loadMessageCommands(options) {
22
+ const commands = [];
23
+ if (!this.client.options.intents.has(discord_js_1.GatewayIntentBits.MessageContent))
24
+ new XernerxLog_js_1.default(this.client).warn(`Message commands might not work as you're missing the intent MessageContent!`);
25
+ if (!this.client.options.intents.has(discord_js_1.GatewayIntentBits.GuildMessages))
26
+ new XernerxLog_js_1.default(this.client).warn(`Message commands might not work as you're missing the intent GuildMessages!`);
27
+ options = zod_1.z
28
+ .object({
29
+ directory: zod_1.z.string(),
30
+ prefix: zod_1.z.string().or(zod_1.z.array(zod_1.z.string())),
31
+ allowMention: zod_1.z.boolean().default(false),
32
+ cooldown: zod_1.z.number().default(0),
33
+ permissions: zod_1.z
34
+ .object({
35
+ user: zod_1.z.array(zod_1.z.string()).or(zod_1.z.null()).default(null),
36
+ client: zod_1.z.array(zod_1.z.string()).or(zod_1.z.null()).default(null),
37
+ dm: zod_1.z.boolean().default(true),
38
+ })
39
+ .default({}),
40
+ handleEdits: zod_1.z.boolean().default(false),
41
+ handleDeletes: zod_1.z.boolean().default(false),
42
+ handleTyping: zod_1.z.boolean().default(false),
43
+ logging: zod_1.z.boolean().default(false),
44
+ })
45
+ .parse(options);
46
+ this.client.modules.options.message = options;
47
+ const files = this.readdir(options.directory);
48
+ for (const file of files) {
49
+ const filepath = `${path.resolve(options.directory)}\\${file}`;
50
+ const command = await this.load(filepath, 'MessageCommand');
51
+ this._checks(command);
52
+ commands.push(command.id);
53
+ }
54
+ new XernerxLog_js_1.default(this.client).info(`Loaded ${dumfunctions_1.Style.log(String(files.length), { color: dumfunctions_1.Style.TextColor.Cyan })} Message Commands: ${commands.map((command) => dumfunctions_1.Style.log(command, { color: dumfunctions_1.Style.TextColor.LightYellow })).join(', ')}`);
55
+ this.emit({
56
+ name: 'messageCreate',
57
+ filetype: 'MessageCommand',
58
+ run: (message) => this.messageCommandRun(message),
59
+ });
60
+ this.emit({
61
+ name: 'messageUpdate',
62
+ filetype: 'MessageCommand',
63
+ run: (message, message2) => this.messageCommandRun(message, message2),
64
+ });
65
+ this.emit({
66
+ name: 'messageDelete',
67
+ filetype: 'MessageCommand',
68
+ run: (message) => this.messageCommandRun(message, 'delete'),
69
+ });
70
+ }
71
+ // public reloadMessageCommands() {
72
+ // return reload(this.client, 'message');
73
+ // }
74
+ async loadSlashCommands(options) {
75
+ const commands = [];
76
+ if (!this.client.settings.local)
77
+ new XernerxLog_js_1.default(this.client).warn(`Slash commands might not work as you haven't specified a local guild ID.`);
78
+ options = zod_1.z
79
+ .object({
80
+ directory: zod_1.z.string(),
81
+ cooldown: zod_1.z.number().default(0),
82
+ permissions: zod_1.z
83
+ .object({
84
+ user: zod_1.z.array(zod_1.z.string()).or(zod_1.z.null()).default(null),
85
+ client: zod_1.z.array(zod_1.z.string()).or(zod_1.z.null()).default(null),
86
+ dm: zod_1.z.boolean().default(true),
87
+ })
88
+ .default({}),
89
+ logging: zod_1.z.boolean().default(false),
90
+ defer: zod_1.z
91
+ .object({
92
+ reply: zod_1.z.boolean().default(false),
93
+ ephemeral: zod_1.z.boolean().default(false),
94
+ fetchReply: zod_1.z.boolean().default(false),
95
+ })
96
+ .default({}),
97
+ })
98
+ .parse(options);
99
+ this.client.modules.options.slash = options;
100
+ const files = this.readdir(options.directory);
101
+ for (const file of files) {
102
+ const filepath = `${path.resolve(options.directory)}\\${file}`;
103
+ const command = await this.load(filepath, 'SlashCommand');
104
+ commands.push(command.id);
105
+ }
106
+ new XernerxLog_js_1.default(this.client).info(`Loaded ${dumfunctions_1.Style.log(String(files.length), { color: dumfunctions_1.Style.TextColor.Cyan })} Slash Commands: ${commands.map((command) => dumfunctions_1.Style.log(command, { color: dumfunctions_1.Style.TextColor.LightYellow })).join(', ')}`);
107
+ this.emit({
108
+ name: 'interactionCreate',
109
+ filetype: 'SlashCommand',
110
+ run: (interaction) => this.slashCommandRun(interaction),
111
+ });
112
+ }
113
+ async loadContextCommands(options) {
114
+ const commands = [];
115
+ if (!this.client.settings.local)
116
+ new XernerxLog_js_1.default(this.client).warn(`Context commands might not work as you haven't specified a local guild ID.`);
117
+ options = zod_1.z
118
+ .object({
119
+ directory: zod_1.z.string(),
120
+ cooldown: zod_1.z.number().default(0),
121
+ permissions: zod_1.z
122
+ .object({
123
+ user: zod_1.z.array(zod_1.z.string()).or(zod_1.z.null()).default(null),
124
+ client: zod_1.z.array(zod_1.z.string()).or(zod_1.z.null()).default(null),
125
+ dm: zod_1.z.boolean().default(true),
126
+ })
127
+ .default({}),
128
+ logging: zod_1.z.boolean().default(false),
129
+ defer: zod_1.z
130
+ .object({
131
+ reply: zod_1.z.boolean().default(false),
132
+ ephemeral: zod_1.z.boolean().default(false),
133
+ fetchReply: zod_1.z.boolean().default(false),
134
+ })
135
+ .default({}),
136
+ })
137
+ .parse(options);
138
+ this.client.modules.options.context = options;
139
+ const files = this.readdir(options.directory);
140
+ for (const file of files) {
141
+ const filepath = `${path.resolve(options.directory)}\\${file}`;
142
+ const command = await this.load(filepath, 'ContextCommand');
143
+ commands.push(command.id);
144
+ }
145
+ new XernerxLog_js_1.default(this.client).info(`Loaded ${dumfunctions_1.Style.log(String(files.length), { color: dumfunctions_1.Style.TextColor.Cyan })} Context Commands: ${commands.map((command) => dumfunctions_1.Style.log(command, { color: dumfunctions_1.Style.TextColor.LightYellow })).join(', ')}`);
146
+ this.emit({
147
+ name: 'interactionCreate',
148
+ filetype: 'ContextCommand',
149
+ run: (interaction) => this.contextCommandRun(interaction),
150
+ });
151
+ }
152
+ async messageCommandRun(message, message2) {
153
+ const filetype = 'MessageCommand';
154
+ if (message.author.id === this.client.user?.id && this.client.settings.ignore?.self)
155
+ return;
156
+ else if (message.author.bot && this.client.settings.ignore?.bots)
157
+ return;
158
+ if (message.system && this.client.settings.ignore?.system)
159
+ return;
160
+ message.util = new MessageUtil_js_1.default(this.client, message);
161
+ message.user = await (0, xernerxUser_js_1.xernerxUser)(message, this.client);
162
+ if (await (0, inhibitorValidations_js_1.inhibitorValidation)(message, undefined, undefined, 'pre'))
163
+ return;
164
+ if (typeof message2 === 'object')
165
+ message = message2;
166
+ if (message2 === 'delete' && this.client.modules.options.message?.handleDeletes) {
167
+ if (!this.client.cache.messages.has(message.id))
168
+ return;
169
+ const id = this.client.cache.messages.get(message.id);
170
+ if (!id)
171
+ return;
172
+ (async () => {
173
+ const msg = await message.channel.messages.fetch(id);
174
+ await msg.delete();
175
+ this.client.cache.messages.delete(message.id);
176
+ })();
177
+ return;
178
+ }
179
+ if (message.content && this.client.modules.options.message) {
180
+ const commands = this.client.commands.message;
181
+ const prefixes = Array.isArray(this.client.modules.options.message.prefix) ? this.client.modules.options.message.prefix : [this.client.modules.options.message.prefix];
182
+ let commandName = null, cmd, commandAlias = null, commandPrefix = null;
183
+ commands.map((command) => {
184
+ let prefix = null;
185
+ if (command.regex && message.content.match(command.regex)) {
186
+ const [match] = message.content.match(command.regex) || [null];
187
+ if (match)
188
+ commandName = command.name;
189
+ }
190
+ const cp = Array.isArray(command.prefix) ? command.prefix : [command.prefix];
191
+ prefixes.map((p) => {
192
+ if (message.content.startsWith(p))
193
+ prefix = p;
194
+ });
195
+ cp.map((p) => {
196
+ if (message.content.startsWith(p))
197
+ prefix = p;
198
+ });
199
+ if (!prefix)
200
+ return;
201
+ if (!commandName)
202
+ commandName =
203
+ message.content
204
+ .replace(prefix, '')
205
+ .split(command.separator || / +/)
206
+ .shift()
207
+ ?.trim()
208
+ ?.toLowerCase() || '';
209
+ if (!this.client.commands.message.has(commandName) && command.aliases?.includes(commandName)) {
210
+ commandAlias = commandName;
211
+ commandName = command.name;
212
+ }
213
+ commandAlias = commandAlias ? commandAlias : commandName;
214
+ commandPrefix = prefix;
215
+ });
216
+ if (!cmd && this.client.modules.options.message.allowMention) {
217
+ if (message.mentions.users.has(this.client.user?.id) || message.mentions.repliedUser?.id === this.client.user?.id) {
218
+ commandName =
219
+ message.content
220
+ .replace(`<@${this.client.user?.id}>`, '')
221
+ .trim()
222
+ .split(/ +/)
223
+ .shift()
224
+ ?.toLowerCase() || null;
225
+ commands.map((command) => {
226
+ if (command.aliases?.includes(commandName)) {
227
+ commandName = command.name;
228
+ return (commandAlias = commandName);
229
+ }
230
+ });
231
+ commandPrefix = `<@${this.client.user?.id}>`;
232
+ }
233
+ }
234
+ if (this.client.commands.message.has(commandName)) {
235
+ if (this.client.modules.options.message?.handleTyping)
236
+ message.channel.sendTyping();
237
+ cmd = this.client.commands.message.get(commandName);
238
+ }
239
+ if (!commandPrefix || !commandName)
240
+ return;
241
+ if (!cmd)
242
+ return await this.client.emit('commandNotFound', message, commandName, filetype);
243
+ await this.client.emit('commandStart', message, cmd);
244
+ const args = await (0, Arguments_js_1.messageArguments)(message, cmd, commandPrefix);
245
+ message.util.parsed = {
246
+ alias: commandAlias,
247
+ prefix: commandPrefix,
248
+ args: args.args,
249
+ };
250
+ cmd.util = message.util;
251
+ return await this.exec(cmd, message, args, filetype);
252
+ }
253
+ }
254
+ async slashCommandRun(interaction) {
255
+ const filetype = 'SlashCommand';
256
+ interaction.util = new InteractionUtil_js_1.default(this.client, interaction);
257
+ interaction.user = await (0, xernerxUser_js_1.xernerxUser)(interaction, this.client);
258
+ if (await (0, inhibitorValidations_js_1.inhibitorValidation)(interaction, undefined, undefined, 'pre'))
259
+ return;
260
+ let cmd = null;
261
+ if (this.client.commands.slash.has(interaction.commandName))
262
+ cmd = this.client.commands.slash.get(interaction.commandName);
263
+ if (!cmd)
264
+ return this.client.emit('commandNotFound', interaction, interaction.commandName, filetype);
265
+ new Promise(async (resolve) => {
266
+ if (interaction.isAutocomplete()) {
267
+ const focused = interaction.options.getFocused(true);
268
+ const options = interaction.options;
269
+ await cmd.autocomplete(interaction, focused, options);
270
+ }
271
+ else
272
+ resolve(true);
273
+ })
274
+ .then(async () => {
275
+ await this.client.emit('commandStart', interaction);
276
+ const args = await (0, Arguments_js_1.interactionArguments)(interaction, cmd);
277
+ interaction.util.parsed = {
278
+ alias: [interaction.commandName, args.group || null, args.subcommand || null].filter((x) => x).join(' '),
279
+ args: args.args,
280
+ };
281
+ cmd.util = interaction.util;
282
+ return await this.exec(cmd, interaction, args, filetype);
283
+ })
284
+ .catch((error) => this.client.emit('commandError', interaction, error, cmd, filetype));
285
+ }
286
+ async contextCommandRun(interaction) {
287
+ const filetype = 'ContextCommand';
288
+ interaction.util = new InteractionUtil_js_1.default(this.client, interaction);
289
+ interaction.user = await (0, xernerxUser_js_1.xernerxUser)(interaction, this.client);
290
+ if (await (0, inhibitorValidations_js_1.inhibitorValidation)(interaction, undefined, undefined, 'pre'))
291
+ return;
292
+ let cmd;
293
+ if (this.client.commands.context.has(interaction.commandName))
294
+ cmd = this.client.commands.context.get(interaction.commandName);
295
+ if (!cmd)
296
+ return this.client.emit('commandNotFound', interaction, interaction.commandName, filetype);
297
+ await this.client.emit('commandStart', interaction);
298
+ const args = await (0, Arguments_js_1.interactionArguments)(interaction, cmd);
299
+ interaction.util.parsed = {
300
+ alias: interaction.commandName,
301
+ args: args,
302
+ };
303
+ cmd.util = interaction.util;
304
+ return await this.exec(cmd, interaction, args, filetype);
305
+ }
306
+ async exec(cmd, event, args, type) {
307
+ try {
308
+ if (cmd.filetype == 'SlashCommand' && (cmd?.defer?.reply ?? this.client.modules.options.slash?.defer?.reply)) {
309
+ await event.deferReply({
310
+ ephemeral: cmd.defer?.ephemeral || this.client.modules.options.slash?.defer?.ephemeral || false,
311
+ });
312
+ }
313
+ if (cmd.filetype == 'ContextCommand' && (cmd?.defer?.reply ?? this.client.modules.options.context?.defer?.reply)) {
314
+ await event.deferReply({
315
+ ephemeral: cmd.defer?.ephemeral || this.client.modules.options.context?.defer?.ephemeral || false,
316
+ });
317
+ }
318
+ if (await (0, commandValidation_js_1.default)(event, cmd))
319
+ return;
320
+ if (await (0, inhibitorValidations_js_1.inhibitorValidation)(event, args, cmd, 'check'))
321
+ return;
322
+ if (cmd.conditions && (await cmd.conditions(event, args)))
323
+ return;
324
+ await cmd.exec(event, args);
325
+ await (0, inhibitorValidations_js_1.inhibitorValidation)(event, args, cmd, 'post');
326
+ return await this.client.emit('commandFinish', event, cmd);
327
+ }
328
+ catch (error) {
329
+ new XernerxLog_js_1.default(this.client).error(`An error occurred executing ${dumfunctions_1.Style.log(cmd.name, { color: dumfunctions_1.Style.TextColor.Blue })}`, error);
330
+ return await this.client.emit('commandError', event, error, cmd, type);
331
+ }
332
+ }
333
+ _checks(command) {
334
+ if ((command.strict?.voice || command.ignore?.voice) && !this.client.options.intents.has('GuildVoiceStates'))
335
+ new XernerxLog_js_1.default(this.client).warn(`${dumfunctions_1.Style.log(command.id, { color: dumfunctions_1.Style.TextColor.Blue })} options ${dumfunctions_1.Style.log(`Xernerx${command.filetype}#strict#voice`, {
336
+ color: dumfunctions_1.Style.BackgroundColor.Grey,
337
+ })} or ${dumfunctions_1.Style.log(`Xernerx${command.filetype}#ignore#voice`, {
338
+ color: dumfunctions_1.Style.BackgroundColor.Grey,
339
+ })} will misbehave due to missing the ${dumfunctions_1.Style.log('GuildVoiceStates', { color: dumfunctions_1.Style.TextColor.Yellow })} intent.`);
340
+ }
341
+ }
342
+ exports.default = CommandHandler;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /** @format */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const zod_1 = require("zod");
5
+ const dumfunctions_1 = require("dumfunctions");
6
+ const path = __importStar(require("path"));
7
+ const Handler_js_1 = __importDefault(require("./Handler.js"));
8
+ const XernerxLog_js_1 = __importDefault(require("../tools/XernerxLog.js"));
9
+ class EventHandler extends Handler_js_1.default {
10
+ constructor(client) {
11
+ super(client);
12
+ this.readyTimestamp = Number(Date.now());
13
+ }
14
+ async loadEvents(options) {
15
+ const events = [];
16
+ options = zod_1.z
17
+ .object({
18
+ directory: zod_1.z.string(),
19
+ })
20
+ .parse(options);
21
+ this.client.modules.options.events = options;
22
+ const files = this.readdir(options.directory);
23
+ for (const file of files) {
24
+ const filepath = `${path.resolve(options.directory)}\\${file}`;
25
+ const event = await this.load(filepath, 'Event');
26
+ this.emit(event);
27
+ events.push(event.id);
28
+ }
29
+ new XernerxLog_js_1.default(this.client).info(`Loaded ${dumfunctions_1.Style.log(String(this.client.events.size), { color: dumfunctions_1.Style.TextColor.Cyan })} Events: ${events.map((event) => dumfunctions_1.Style.log(event, { color: dumfunctions_1.Style.TextColor.LightYellow })).join(', ')}`);
30
+ }
31
+ }
32
+ exports.default = EventHandler;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /** @format */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const dumfunctions_1 = require("dumfunctions");
5
+ const Handler_js_1 = __importDefault(require("./Handler.js"));
6
+ const XernerxLog_js_1 = __importDefault(require("../tools/XernerxLog.js"));
7
+ class ExtensionHandler extends Handler_js_1.default {
8
+ constructor(client) {
9
+ super(client);
10
+ this.readyTimestamp = Number(Date.now());
11
+ }
12
+ loadExtensions(...extensions) {
13
+ const active = extensions.map((extension) => {
14
+ try {
15
+ if (extension.main)
16
+ extension.main(this.client);
17
+ if (extension.defer) {
18
+ this.client.on('ready', (client) => extension.defer(client));
19
+ }
20
+ return extension.name;
21
+ }
22
+ catch (error) {
23
+ return new XernerxLog_js_1.default(this.client).error(`An error occurred while loading ${dumfunctions_1.Style.log(extension.name, { color: dumfunctions_1.Style.TextColor.Red })}`, error);
24
+ }
25
+ });
26
+ new XernerxLog_js_1.default(this.client).info(`Loaded ${dumfunctions_1.Style.log(String(extensions.length), { color: dumfunctions_1.Style.TextColor.Cyan })} Extensions: ${active
27
+ .filter((e) => e)
28
+ .map((event) => dumfunctions_1.Style.log(event, { color: dumfunctions_1.Style.TextColor.LightYellow }))
29
+ .join(', ')}`);
30
+ }
31
+ }
32
+ exports.default = ExtensionHandler;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /** @format */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const fs = __importStar(require("fs"));
5
+ const path = __importStar(require("path"));
6
+ const load_js_1 = __importDefault(require("../functions/load.js"));
7
+ class Handler {
8
+ client;
9
+ files;
10
+ constructor(client) {
11
+ this.client = client;
12
+ this.files = [];
13
+ }
14
+ readdir(dir) {
15
+ try {
16
+ return fs.readdirSync(path.resolve(dir)).filter((file) => file.endsWith('.js'));
17
+ }
18
+ catch (error) {
19
+ console.error(error);
20
+ }
21
+ return [];
22
+ }
23
+ async load(filepath, type) {
24
+ const file = await (0, load_js_1.default)(this.client, filepath, type);
25
+ this.files.push(file);
26
+ return file;
27
+ }
28
+ async emit(event) {
29
+ if (!event?.filetype)
30
+ return;
31
+ if (event.filetype === 'Event') {
32
+ if (event.emitter === 'client')
33
+ event.once
34
+ ? this.client.once(event.name, (...args) => event.run(...args))
35
+ : this.client.on(event.name, (...args) => event.run(...args));
36
+ else if (event.emitter === 'process')
37
+ event.once
38
+ ? process.once(event.name, (...args) => event.run(...args))
39
+ : process.on(event.name, (...args) => event.run(...args));
40
+ }
41
+ if (['MessageCommand', 'SlashCommand', 'ContextCommand'].includes(event.filetype)) {
42
+ event.once
43
+ ? this.client.once(event.name, (...args) => event.run(...args))
44
+ : this.client.on(event.name, (...args) => event.run(...args));
45
+ }
46
+ }
47
+ }
48
+ exports.default = Handler;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ /** @format */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const zod_1 = require("zod");
5
+ const path = __importStar(require("path"));
6
+ const dumfunctions_1 = require("dumfunctions");
7
+ const Handler_js_1 = __importDefault(require("./Handler.js"));
8
+ const XernerxLog_js_1 = __importDefault(require("../tools/XernerxLog.js"));
9
+ class InhibitorHandler extends Handler_js_1.default {
10
+ constructor(client) {
11
+ super(client);
12
+ this.readyTimestamp = Number(Date.now());
13
+ }
14
+ async loadInhibitors(options) {
15
+ const inhibitors = [];
16
+ options = zod_1.z
17
+ .object({
18
+ directory: zod_1.z.string(),
19
+ })
20
+ .parse(options);
21
+ this.client.modules.options.inhibitors = options;
22
+ const files = this.readdir(options.directory);
23
+ for (const file of files) {
24
+ const filepath = `${path.resolve(options.directory)}\\${file}`;
25
+ const inhibitor = await this.load(filepath, 'Inhibitor');
26
+ this.emit(inhibitor);
27
+ inhibitors.push(inhibitor.id);
28
+ }
29
+ new XernerxLog_js_1.default(this.client).info(`Loaded ${dumfunctions_1.Style.log(String(this.client.inhibitors.size), { color: dumfunctions_1.Style.TextColor.Cyan })} Inhibitors: ${inhibitors
30
+ .map((inhibitor) => dumfunctions_1.Style.log(inhibitor, { color: dumfunctions_1.Style.TextColor.LightYellow }))
31
+ .join(', ')}`);
32
+ }
33
+ }
34
+ exports.default = InhibitorHandler;