xernerx 4.1.0 → 4.2.1

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 (112) hide show
  1. package/LICENSE +21 -21
  2. package/dist/cjs/build/ContextCommandBuilder.d.ts +68 -0
  3. package/dist/cjs/build/ContextCommandBuilder.js +97 -0
  4. package/dist/cjs/build/EventBuilder.d.ts +21 -0
  5. package/dist/cjs/build/EventBuilder.js +44 -0
  6. package/dist/cjs/build/InhibitorBuilder.d.ts +19 -0
  7. package/dist/cjs/build/InhibitorBuilder.js +37 -0
  8. package/dist/cjs/build/MessageCommandBuilder.d.ts +59 -0
  9. package/dist/cjs/build/MessageCommandBuilder.js +100 -0
  10. package/dist/cjs/build/SlashCommandBuilder.d.ts +64 -0
  11. package/dist/cjs/build/SlashCommandBuilder.js +168 -0
  12. package/dist/cjs/client/XernerxClient.d.ts +28 -0
  13. package/dist/cjs/client/XernerxClient.js +116 -0
  14. package/dist/cjs/handlers/CommandHandler.d.ts +27 -0
  15. package/dist/cjs/handlers/CommandHandler.js +45 -0
  16. package/dist/cjs/handlers/EventHandler.d.ts +13 -0
  17. package/dist/cjs/handlers/EventHandler.js +19 -0
  18. package/dist/cjs/handlers/Handler.d.ts +57 -0
  19. package/dist/cjs/handlers/Handler.js +308 -0
  20. package/dist/cjs/handlers/InhibitorHandler.d.ts +18 -0
  21. package/dist/cjs/handlers/InhibitorHandler.js +24 -0
  22. package/dist/cjs/main.d.ts +44 -0
  23. package/dist/cjs/main.js +112 -0
  24. package/dist/cjs/models/CommandArguments.d.ts +17 -0
  25. package/dist/cjs/models/CommandArguments.js +106 -0
  26. package/dist/cjs/models/Events.d.ts +24 -0
  27. package/dist/cjs/models/Events.js +307 -0
  28. package/dist/cjs/models/Extensions.d.ts +7 -0
  29. package/dist/cjs/models/Extensions.js +26 -0
  30. package/dist/cjs/tools/XernerxError.d.ts +5 -0
  31. package/dist/cjs/tools/XernerxError.js +11 -0
  32. package/dist/cjs/tools/package.d.ts +49 -0
  33. package/dist/cjs/tools/package.js +50 -0
  34. package/dist/cjs/types/enums.d.ts +44 -0
  35. package/dist/cjs/types/enums.js +38 -0
  36. package/dist/cjs/types/interfaces.d.ts +25 -0
  37. package/dist/cjs/types/interfaces.js +2 -0
  38. package/dist/cjs/types/options.d.ts +241 -0
  39. package/dist/cjs/types/options.js +2 -0
  40. package/dist/cjs/types/types.d.ts +61 -0
  41. package/dist/cjs/types/types.js +2 -0
  42. package/dist/cjs/utils/ClientUtil.d.ts +25 -0
  43. package/dist/cjs/utils/ClientUtil.js +211 -0
  44. package/dist/cjs/utils/CommandUtil.d.ts +58 -0
  45. package/dist/cjs/utils/CommandUtil.js +247 -0
  46. package/dist/cjs/validators/CommandValidations.d.ts +12 -0
  47. package/dist/cjs/validators/CommandValidations.js +169 -0
  48. package/dist/cjs/validators/InhibitorValidations.d.ts +11 -0
  49. package/dist/cjs/validators/InhibitorValidations.js +40 -0
  50. package/dist/client/XernerxClient.d.ts +5 -4
  51. package/dist/client/XernerxClient.js +2 -10
  52. package/dist/functions/deploy.js +20 -20
  53. package/dist/handlers/CommandHandler.js +28 -13
  54. package/dist/main.d.ts +1 -1
  55. package/dist/main.js +1 -1
  56. package/dist/mjs/build/ContextCommandBuilder.d.ts +68 -0
  57. package/dist/mjs/build/ContextCommandBuilder.js +88 -0
  58. package/dist/mjs/build/EventBuilder.d.ts +21 -0
  59. package/dist/mjs/build/EventBuilder.js +34 -0
  60. package/dist/mjs/build/InhibitorBuilder.d.ts +19 -0
  61. package/dist/mjs/build/InhibitorBuilder.js +27 -0
  62. package/dist/mjs/build/MessageCommandBuilder.d.ts +59 -0
  63. package/dist/mjs/build/MessageCommandBuilder.js +90 -0
  64. package/dist/mjs/build/SlashCommandBuilder.d.ts +64 -0
  65. package/dist/mjs/build/SlashCommandBuilder.js +121 -0
  66. package/dist/mjs/client/XernerxClient.d.ts +28 -0
  67. package/dist/mjs/client/XernerxClient.js +108 -0
  68. package/dist/mjs/handlers/CommandHandler.d.ts +27 -0
  69. package/dist/mjs/handlers/CommandHandler.js +42 -0
  70. package/dist/mjs/handlers/EventHandler.d.ts +13 -0
  71. package/dist/mjs/handlers/EventHandler.js +16 -0
  72. package/dist/mjs/handlers/Handler.d.ts +57 -0
  73. package/dist/mjs/handlers/Handler.js +260 -0
  74. package/dist/mjs/handlers/InhibitorHandler.d.ts +18 -0
  75. package/dist/mjs/handlers/InhibitorHandler.js +21 -0
  76. package/dist/mjs/main.d.ts +44 -0
  77. package/dist/mjs/main.js +52 -0
  78. package/dist/mjs/models/CommandArguments.d.ts +17 -0
  79. package/dist/mjs/models/CommandArguments.js +101 -0
  80. package/dist/mjs/models/Events.d.ts +24 -0
  81. package/dist/mjs/models/Events.js +295 -0
  82. package/dist/mjs/models/Extensions.d.ts +7 -0
  83. package/dist/mjs/models/Extensions.js +23 -0
  84. package/dist/mjs/tools/XernerxError.d.ts +5 -0
  85. package/dist/mjs/tools/XernerxError.js +8 -0
  86. package/dist/mjs/tools/package.d.ts +49 -0
  87. package/dist/mjs/tools/package.js +48 -0
  88. package/dist/mjs/types/enums.d.ts +44 -0
  89. package/dist/mjs/types/enums.js +35 -0
  90. package/dist/mjs/types/interfaces.d.ts +25 -0
  91. package/dist/mjs/types/interfaces.js +1 -0
  92. package/dist/mjs/types/options.d.ts +241 -0
  93. package/dist/mjs/types/options.js +1 -0
  94. package/dist/mjs/types/types.d.ts +61 -0
  95. package/dist/mjs/types/types.js +1 -0
  96. package/dist/mjs/utils/ClientUtil.d.ts +25 -0
  97. package/dist/mjs/utils/ClientUtil.js +202 -0
  98. package/dist/mjs/utils/CommandUtil.d.ts +58 -0
  99. package/dist/mjs/utils/CommandUtil.js +232 -0
  100. package/dist/mjs/validators/CommandValidations.d.ts +12 -0
  101. package/dist/mjs/validators/CommandValidations.js +166 -0
  102. package/dist/mjs/validators/InhibitorValidations.d.ts +11 -0
  103. package/dist/mjs/validators/InhibitorValidations.js +36 -0
  104. package/dist/tools/XernerxLog.d.ts +1 -0
  105. package/dist/tools/XernerxLog.js +26 -8
  106. package/dist/types/extenders.d.ts +11 -6
  107. package/dist/types/interfaces.d.ts +23 -19
  108. package/dist/utils/ClientUtil.d.ts +2 -1
  109. package/dist/utils/ClientUtil.js +10 -1
  110. package/dist/utils/MessageUtil.d.ts +4 -1
  111. package/dist/utils/MessageUtil.js +4 -2
  112. package/package.json +1 -1
@@ -0,0 +1,18 @@
1
+ import XernerxClient from '../client/XernerxClient.js';
2
+ import { InhibitorHandlerOptions } from '../types/options.js';
3
+ import { Handler } from './Handler.js';
4
+ /**
5
+ * @description - Inhibitor loader.
6
+ * @param {XernerxClient} client - The XernerxClient.
7
+ */
8
+ export default class InhibitorHandler {
9
+ client: XernerxClient;
10
+ handler: Handler;
11
+ constructor(client: XernerxClient);
12
+ /**
13
+ * @description - The loader for all inhibitors.
14
+ * @param {InhibitorLoadOptions} options - the inhibitor loader options.
15
+ * @returns undefined
16
+ */
17
+ loadAllInhibitors(options: InhibitorHandlerOptions): void;
18
+ }
@@ -0,0 +1,21 @@
1
+ import { Handler } from './Handler.js';
2
+ /**
3
+ * @description - Inhibitor loader.
4
+ * @param {XernerxClient} client - The XernerxClient.
5
+ */
6
+ export default class InhibitorHandler {
7
+ client;
8
+ handler;
9
+ constructor(client) {
10
+ this.client = client;
11
+ this.handler = new Handler(client);
12
+ }
13
+ /**
14
+ * @description - The loader for all inhibitors.
15
+ * @param {InhibitorLoadOptions} options - the inhibitor loader options.
16
+ * @returns undefined
17
+ */
18
+ loadAllInhibitors(options) {
19
+ this.handler.loadAllInhibitors(options);
20
+ }
21
+ }
@@ -0,0 +1,44 @@
1
+ export * from 'discord.js';
2
+ export * from 'dumfunctions';
3
+ import ExtensionBuilder from 'xernerx-extension-builder';
4
+ import XernerxClient from './client/XernerxClient.js';
5
+ import EventBuilder from './build/EventBuilder.js';
6
+ import InhibitorBuilder from './build/InhibitorBuilder.js';
7
+ import MessageCommandBuilder from './build/MessageCommandBuilder.js';
8
+ import ContextCommandBuilder from './build/ContextCommandBuilder.js';
9
+ import SlashCommandBuilder from './build/SlashCommandBuilder.js';
10
+ import { CommandType, EventEmitterType, ContextCommandType, InhibitorType } from './types/enums.js';
11
+ import XernerxError from './tools/XernerxError.js';
12
+ declare const xernerxVersion: string;
13
+ declare const _default: {
14
+ Client: typeof XernerxClient;
15
+ XernerxClient: typeof XernerxClient;
16
+ CommandType: typeof CommandType;
17
+ EventEmitterType: typeof EventEmitterType;
18
+ InhibitorType: typeof InhibitorType;
19
+ ContextCommandType: typeof ContextCommandType;
20
+ EventBuilder: typeof EventBuilder;
21
+ MessageCommandBuilder: typeof MessageCommandBuilder;
22
+ ContextCommandBuilder: typeof ContextCommandBuilder;
23
+ SlashCommandBuilder: typeof SlashCommandBuilder;
24
+ InhibitorBuilder: typeof InhibitorBuilder;
25
+ ExtensionBuilder: typeof ExtensionBuilder;
26
+ XernerxError: typeof XernerxError;
27
+ version: string;
28
+ };
29
+ export default _default;
30
+ export {
31
+ XernerxClient,
32
+ CommandType,
33
+ EventEmitterType,
34
+ InhibitorType,
35
+ ContextCommandType,
36
+ EventBuilder,
37
+ MessageCommandBuilder,
38
+ ContextCommandBuilder,
39
+ SlashCommandBuilder,
40
+ InhibitorBuilder,
41
+ ExtensionBuilder,
42
+ XernerxError,
43
+ xernerxVersion,
44
+ };
@@ -0,0 +1,52 @@
1
+ export * from 'discord.js';
2
+ export * from 'dumfunctions';
3
+ import ExtensionBuilder from 'xernerx-extension-builder';
4
+ import XernerxClient from './client/XernerxClient.js';
5
+ import EventBuilder from './build/EventBuilder.js';
6
+ import InhibitorBuilder from './build/InhibitorBuilder.js';
7
+ import MessageCommandBuilder from './build/MessageCommandBuilder.js';
8
+ import ContextCommandBuilder from './build/ContextCommandBuilder.js';
9
+ import SlashCommandBuilder from './build/SlashCommandBuilder.js';
10
+ import { CommandType, EventEmitterType, ContextCommandType, InhibitorType } from './types/enums.js';
11
+ import XernerxError from './tools/XernerxError.js';
12
+ import pkg from './tools/package.js';
13
+ const xernerxVersion = pkg.version;
14
+ export default {
15
+ // Client
16
+ Client: XernerxClient,
17
+ XernerxClient,
18
+ // Enums
19
+ CommandType,
20
+ EventEmitterType,
21
+ InhibitorType,
22
+ ContextCommandType,
23
+ // Builds
24
+ EventBuilder,
25
+ MessageCommandBuilder,
26
+ ContextCommandBuilder,
27
+ SlashCommandBuilder,
28
+ InhibitorBuilder,
29
+ ExtensionBuilder,
30
+ XernerxError,
31
+ // Constants
32
+ version: xernerxVersion,
33
+ };
34
+ export {
35
+ // Client
36
+ XernerxClient,
37
+ // Enums
38
+ CommandType,
39
+ EventEmitterType,
40
+ InhibitorType,
41
+ ContextCommandType,
42
+ // Builds
43
+ EventBuilder,
44
+ MessageCommandBuilder,
45
+ ContextCommandBuilder,
46
+ SlashCommandBuilder,
47
+ InhibitorBuilder,
48
+ ExtensionBuilder,
49
+ XernerxError,
50
+ // Constants
51
+ xernerxVersion,
52
+ };
@@ -0,0 +1,17 @@
1
+ import MessageCommandBuilder from '../build/MessageCommandBuilder.js';
2
+ import { XernerxInteraction, XernerxMessage } from '../types/types.js';
3
+ export declare class InteractionArguments {
4
+ interaction: XernerxInteraction;
5
+ constructor(interaction: XernerxInteraction);
6
+ group(): string | undefined;
7
+ subcommand(): string | undefined;
8
+ arguments(): Record<string, object>;
9
+ }
10
+ interface Flag {
11
+ flags: Record<string, string | boolean>;
12
+ }
13
+ interface Argument {
14
+ [index: string]: string | number | null;
15
+ }
16
+ export declare function messageArguments(message: XernerxMessage, command: MessageCommandBuilder): Promise<import('discord.js').Message<boolean> | Flag | Argument | undefined>;
17
+ export {};
@@ -0,0 +1,101 @@
1
+ export class InteractionArguments {
2
+ interaction;
3
+ constructor(interaction) {
4
+ this.interaction = interaction;
5
+ }
6
+ group() {
7
+ return this.interaction?.options?._group;
8
+ }
9
+ subcommand() {
10
+ return this.interaction?.options?._subcommand;
11
+ }
12
+ arguments() {
13
+ const options = {};
14
+ if (this.interaction?.options?._hoistedOptions) {
15
+ for (const option of this.interaction.options._hoistedOptions) {
16
+ options[option.name] = option.channel || option.user || option.role || option.value;
17
+ }
18
+ }
19
+ return options;
20
+ }
21
+ }
22
+ export async function messageArguments(message, command) {
23
+ let args = { flags: {} },
24
+ separator = command.separator || ' ',
25
+ i = 0;
26
+ if (!command.args) return;
27
+ command.args
28
+ .filter((c) => c.type == 'flag')
29
+ .map((flag) => {
30
+ args = args;
31
+ for (const flg of message.content.matchAll(flag.match)) {
32
+ if (flag.match == flg) {
33
+ message.content = message.content.replace(flag.match, '');
34
+ args.flags[flag.name] = true;
35
+ }
36
+ }
37
+ if (!args.flags[flag.name]) args.flags[flag.name] = false;
38
+ });
39
+ for (const argument of command.args) {
40
+ args = args;
41
+ let content = message.content
42
+ .split(/ +/)
43
+ .slice(1)
44
+ .join(separator)
45
+ .replace(new RegExp(`${separator}${separator}+`, 'g'), separator)
46
+ .split(separator)
47
+ .slice(i);
48
+ if (content.join(separator) != '' && argument.type !== 'flag') {
49
+ if (argument?.content?.includes(content[0])) {
50
+ args[argument.name] = content[0];
51
+ } else if (argument.type == 'string') {
52
+ args[argument.name] = content[0];
53
+ } else if (argument.type == 'number') {
54
+ args[argument.name] = parseInt(content[0]);
55
+ } else if (argument.type == 'boolean') {
56
+ if (content[0]?.toLowerCase() != 'true' && content[0]?.toLowerCase() != 'false') content[0] = null;
57
+ args[argument.name] = content[0];
58
+ } else if (argument.type == 'user') {
59
+ let user = message.client.users.cache.find((u) => u?.username?.toLowerCase()?.includes(content[0])) || null;
60
+ try {
61
+ user = (await message.client.users.fetch(user?.id || content[0].replace(/<@!?|>/g, ''))) || null;
62
+ } catch (e) {
63
+ user = null;
64
+ }
65
+ args[argument.name] = user;
66
+ } else if (argument.type == 'role') {
67
+ let role = message.guild?.roles.cache.find((r) => r?.name?.toLowerCase()?.includes(content[0])) || null;
68
+ try {
69
+ role = (await message.guild?.roles.fetch(role?.id || content[0].replace(/<@&?|>/g, ''))) || null;
70
+ } catch (e) {
71
+ role = null;
72
+ }
73
+ args[argument.name] = role;
74
+ } else if (argument.type == 'member') {
75
+ let member = message.guild?.members.cache.find((m) => m?.nickname?.toLowerCase()?.includes(content[0]) || m?.user?.username?.toLowerCase()?.includes(content[0])) || null;
76
+ try {
77
+ member = (await message.guild?.members.fetch(member?.id || content[0].replace(/<@!?|>/g, ''))) || null;
78
+ } catch (e) {
79
+ member = null;
80
+ }
81
+ args[argument.name] = member;
82
+ } else if (argument.type == 'channel') {
83
+ let channel = message.guild?.channels.cache.find((c) => c?.name?.toLowerCase()?.includes(content[0]));
84
+ try {
85
+ channel = await message.client.channels.fetch(channel?.id || content[0].replace(/<#|>/g, ''));
86
+ } catch (e) {
87
+ channel = null;
88
+ }
89
+ args[argument.name] = channel;
90
+ } else if (argument.type == 'rest') {
91
+ args[argument.name] = content.join(separator);
92
+ break;
93
+ } else if (argument.prompt) {
94
+ if (argument.prompt.reply) return message.util?.reply(argument.prompt.reply);
95
+ else if (argument.prompt.send) return message.channel.send(argument.prompt.send);
96
+ } else args[argument.name] = typeof argument.default == 'function' ? argument.default(message) : argument.default;
97
+ i++;
98
+ } else args[argument.name] = typeof argument.default == 'function' ? argument.default(message) : argument.default;
99
+ }
100
+ return args;
101
+ }
@@ -0,0 +1,24 @@
1
+ import XernerxClient from '../client/XernerxClient.js';
2
+ export declare class MessageCommandEvents {
3
+ client: XernerxClient;
4
+ constructor(client: XernerxClient);
5
+ messageCreate(): void;
6
+ messageUpdate(): void;
7
+ messageDelete(): void;
8
+ }
9
+ export declare class SlashCommandEvents {
10
+ client: XernerxClient;
11
+ constructor(client: XernerxClient);
12
+ slashCreate(): void;
13
+ }
14
+ export declare class ContextCommandEvents {
15
+ client: XernerxClient;
16
+ constructor(client: XernerxClient);
17
+ contextCreate(): void;
18
+ }
19
+ export declare class CommandsDeploy {
20
+ private client;
21
+ constructor(client: XernerxClient);
22
+ deploy(): void;
23
+ private put;
24
+ }
@@ -0,0 +1,295 @@
1
+ import { GatewayVersion, InteractionType, REST, Routes } from 'discord.js';
2
+ import { InteractionCommandUtil, MessageCommandUtil } from '../utils/CommandUtil.js';
3
+ import { InteractionArguments, messageArguments } from './CommandArguments.js';
4
+ import commandValidation from '../validators/CommandValidations.js';
5
+ import { Style } from 'dumfunctions';
6
+ import { InhibitorValidation } from '../validators/InhibitorValidations.js';
7
+ export class MessageCommandEvents {
8
+ client;
9
+ constructor(client) {
10
+ this.client = client;
11
+ }
12
+ messageCreate() {
13
+ this.client.on('messageCreate', async (message) => {
14
+ if (!message.author.bot) {
15
+ let command = undefined,
16
+ px = undefined;
17
+ message.author.isOwner = this.client.util.isOwner(message.author.id);
18
+ message.util = new MessageCommandUtil(this.client, message);
19
+ const commands = this.client.commands.message;
20
+ commands
21
+ .filter((c) => !c.regex)
22
+ .map(async (cmd) => {
23
+ if (cmd.prefix) {
24
+ cmd.prefix.map((prefix) => {
25
+ if (message.content.startsWith(prefix)) {
26
+ command = message.content.replace(prefix, '').split(/ +/).shift();
27
+ px = prefix;
28
+ }
29
+ });
30
+ }
31
+ if (this.client.handlerOptions.message?.prefix) {
32
+ const prefix = Array.isArray(this.client.handlerOptions.message.prefix) ? this.client.handlerOptions.message.prefix : [this.client.handlerOptions.message.prefix];
33
+ prefix.map((prefix) => {
34
+ if (message.content.startsWith(prefix)) {
35
+ command = message.content.replace(prefix, '').split(/ +/).shift();
36
+ px = prefix;
37
+ }
38
+ });
39
+ }
40
+ if (this.client.handlerOptions.message?.allowMention) {
41
+ if (message.mentions.users.has(this.client.user?.id) || message.mentions.repliedUser?.id === this.client.user?.id) {
42
+ command = message.content.replace(`<@${this.client.user?.id}>`, '').trim().split(/ +/).shift();
43
+ px = 'MentionPrefix';
44
+ }
45
+ }
46
+ const prefix = Array.isArray(this.client.handlerOptions.message?.prefix) ? this.client.handlerOptions.message?.prefix : [this.client.handlerOptions.message?.prefix];
47
+ if (
48
+ (cmd.name.toLowerCase() == command?.toLowerCase() || cmd.aliases?.map((c) => c.toLowerCase())?.includes(command?.toLowerCase())) &&
49
+ (cmd.prefix.includes(px) || prefix?.includes(px) || px === 'MentionPrefix')
50
+ ) {
51
+ try {
52
+ if (this.client.handlerOptions.message?.handleTyping) message.channel.sendTyping();
53
+ const inhibitor = new InhibitorValidation(this.client, message, command);
54
+ if (commandValidation(message, cmd, this.client)) return;
55
+ if (await inhibitor.inhibit()) return;
56
+ if (cmd.conditions && (await cmd.conditions(message, await messageArguments(message, cmd)))) return;
57
+ await cmd.exec(message, await messageArguments(message, cmd));
58
+ this.client.emit('commandRun', message, cmd);
59
+ } catch (error) {
60
+ return this.client.emit('commandError', message, error, cmd);
61
+ }
62
+ }
63
+ });
64
+ }
65
+ });
66
+ }
67
+ messageUpdate() {
68
+ this.client.on('messageUpdate', async (old, message) => {
69
+ message = message;
70
+ if (!message.author?.bot) {
71
+ let command = undefined,
72
+ px = undefined;
73
+ if (message.author) message.author.isOwner = this.client.util.isOwner(message.author.id);
74
+ message.util = new MessageCommandUtil(this.client, message);
75
+ const commands = this.client.commands.message;
76
+ commands
77
+ .filter((c) => !c.regex)
78
+ .map(async (cmd) => {
79
+ if (cmd.prefix) {
80
+ cmd.prefix.map((prefix) => {
81
+ if (message?.content?.startsWith(prefix)) {
82
+ command = message.content.replace(prefix, '').split(/ +/).shift();
83
+ px = prefix;
84
+ }
85
+ });
86
+ }
87
+ if (this.client.handlerOptions.message?.prefix) {
88
+ const prefix = Array.isArray(this.client.handlerOptions.message.prefix) ? this.client.handlerOptions.message.prefix : [this.client.handlerOptions.message.prefix];
89
+ prefix.map((prefix) => {
90
+ if (message?.content?.startsWith(prefix)) {
91
+ command = message.content.replace(prefix, '').split(/ +/).shift();
92
+ px = prefix;
93
+ }
94
+ });
95
+ }
96
+ if (this.client.handlerOptions.message?.allowMention) {
97
+ if (message.mentions.users.has(this.client.user?.id || '') || message.mentions.repliedUser?.id === this.client.user?.id) {
98
+ command = message?.content?.replace(`<@${this.client.user?.id}>`, '').trim().split(/ +/).shift();
99
+ px = 'MentionPrefix';
100
+ }
101
+ }
102
+ const prefix = Array.isArray(this.client.handlerOptions.message?.prefix) ? this.client.handlerOptions.message?.prefix : [this.client.handlerOptions.message?.prefix];
103
+ if (
104
+ (cmd.name.toLowerCase() == command?.toLowerCase() || cmd.aliases?.map((c) => c.toLowerCase())?.includes(command?.toLowerCase())) &&
105
+ (cmd.prefix.includes(px) || prefix?.includes(px) || px === 'MentionPrefix')
106
+ ) {
107
+ try {
108
+ if (this.client.handlerOptions.message?.handleTyping) message.channel.sendTyping();
109
+ message = message;
110
+ const inhibitor = new InhibitorValidation(this.client, message, command);
111
+ if (commandValidation(message, cmd, this.client)) return;
112
+ if (await inhibitor.inhibit()) return;
113
+ if (cmd.conditions && (await cmd.conditions(message, await messageArguments(message, cmd)))) return;
114
+ await cmd.exec(message, await messageArguments(message, cmd));
115
+ this.client.emit('commandRun', message, cmd);
116
+ } catch (error) {
117
+ return this.client.emit('commandError', message, error, cmd);
118
+ }
119
+ }
120
+ });
121
+ }
122
+ });
123
+ }
124
+ messageDelete() {
125
+ this.client.on('messageDelete', async (message) => {
126
+ if (this.client.cache.messages.has(message.id) && this.client.handlerOptions.message?.handleDeletes) {
127
+ try {
128
+ if (this.client.handlerOptions.message?.handleTyping) message.channel.sendTyping();
129
+ const msg = this.client.cache.messages.get(message.id);
130
+ const response = await message.channel.messages.fetch(msg?.response);
131
+ await response.delete();
132
+ } catch (error) {
133
+ this.client.emit('commandError', message, error, null);
134
+ }
135
+ }
136
+ });
137
+ }
138
+ }
139
+ export class SlashCommandEvents {
140
+ client;
141
+ constructor(client) {
142
+ this.client = client;
143
+ }
144
+ slashCreate() {
145
+ this.client.on('interactionCreate', async (interaction) => {
146
+ interaction.util = new InteractionCommandUtil(this.client, interaction);
147
+ interaction.user.isOwner = this.client.util.isOwner(interaction.user.id);
148
+ if (interaction.type === InteractionType.ApplicationCommand) {
149
+ if (this.client.commands.slash.has(interaction.commandName)) {
150
+ let command = this.client.commands.slash.get(interaction.commandName);
151
+ const argumentsInfo = new InteractionArguments(interaction);
152
+ try {
153
+ const inhibitor = new InhibitorValidation(this.client, interaction, command);
154
+ if (await inhibitor.inhibit()) return;
155
+ if (commandValidation(interaction, command, this.client)) return;
156
+ if (command.defer?.reply !== false && this.client.handlerOptions.slash?.defer?.reply)
157
+ await interaction.deferReply({
158
+ ephemeral: this.client.handlerOptions.slash?.defer?.ephemeral,
159
+ fetchReply: this.client.handlerOptions.slash?.defer?.fetchReply,
160
+ });
161
+ if (!(interaction.deferred || interaction.replied) && command.defer?.reply)
162
+ await interaction.deferReply({
163
+ ephemeral: command.defer?.ephemeral,
164
+ fetchReply: command.defer?.fetchReply,
165
+ });
166
+ if (
167
+ command.conditions &&
168
+ (await command.conditions(interaction, {
169
+ group: argumentsInfo.group(),
170
+ subcommand: argumentsInfo.subcommand(),
171
+ args: await argumentsInfo.arguments(),
172
+ }))
173
+ )
174
+ return;
175
+ await command.exec(interaction, {
176
+ group: argumentsInfo.group(),
177
+ subcommand: argumentsInfo.subcommand(),
178
+ args: await argumentsInfo.arguments(),
179
+ });
180
+ this.client.emit('commandRun', interaction, command);
181
+ } catch (error) {
182
+ this.client.emit('commandError', interaction, error, command);
183
+ }
184
+ }
185
+ }
186
+ });
187
+ }
188
+ }
189
+ export class ContextCommandEvents {
190
+ client;
191
+ constructor(client) {
192
+ this.client = client;
193
+ }
194
+ contextCreate() {
195
+ this.client.on('interactionCreate', async (interaction) => {
196
+ interaction.util = new InteractionCommandUtil(this.client, interaction);
197
+ interaction.user.isOwner = this.client.util.isOwner(interaction.user.id);
198
+ if (interaction.type === InteractionType.ApplicationCommand) {
199
+ if (this.client.commands.context.has(interaction.commandName)) {
200
+ let command = this.client.commands.context.get(interaction.commandName);
201
+ try {
202
+ const inhibitor = new InhibitorValidation(this.client, interaction, command);
203
+ if (commandValidation(interaction, command, this.client)) return;
204
+ if (await inhibitor.inhibit()) return;
205
+ if (command.conditions && (await command.conditions(interaction))) return;
206
+ if (command.defer?.reply !== false && this.client.handlerOptions.context?.defer?.reply)
207
+ await interaction.deferReply({
208
+ ephemeral: this.client.handlerOptions.context?.defer?.ephemeral,
209
+ fetchReply: this.client.handlerOptions.context?.defer?.fetchReply,
210
+ });
211
+ if (!(interaction.deferred || interaction.replied) && command.defer?.reply)
212
+ await interaction.deferReply({
213
+ ephemeral: command.defer?.ephemeral,
214
+ fetchReply: command.defer?.fetchReply,
215
+ });
216
+ let args = {};
217
+ if (command.type === 3) args = await interaction.channel.messages.fetch(interaction.targetId);
218
+ if (command.type === 2) args = await this.client.users.fetch(interaction.targetId);
219
+ await command.exec(interaction, args);
220
+ this.client.emit('commandRun', interaction, command);
221
+ } catch (error) {
222
+ this.client.emit('commandError', interaction, error, command);
223
+ }
224
+ }
225
+ }
226
+ });
227
+ }
228
+ }
229
+ export class CommandsDeploy {
230
+ client;
231
+ constructor(client) {
232
+ this.client = client;
233
+ }
234
+ deploy() {
235
+ this.client.once('ready', async (client) => {
236
+ const slashCommands = [],
237
+ contextCommands = [];
238
+ this.client.commands.context.map((command) => (command.data ? contextCommands.push(command.data.toJSON()) : null));
239
+ this.client.commands.slash.map((command) => (command.data ? slashCommands.push(command.data.toJSON()) : null));
240
+ try {
241
+ const global = {
242
+ slash: this.client.handlerOptions.slash?.global,
243
+ context: this.client.handlerOptions.context?.global,
244
+ };
245
+ const guild = {
246
+ slash: this.client.handlerOptions.slash?.guildId,
247
+ context: this.client.handlerOptions.context?.guildId,
248
+ };
249
+ if (!guild.slash && !guild.context) return;
250
+ if (global.slash && global.context) {
251
+ if (guild.slash !== guild.context)
252
+ console.info(
253
+ Style.log(
254
+ `Xernerx | Warning: slash and context commands are both set to global, but don't have a matching guildId, using ${
255
+ (await this.client.guilds.fetch(this.client.handlerOptions.slash?.guildId)).name
256
+ }!`,
257
+ { color: Style.TextColor.Red }
258
+ )
259
+ );
260
+ this.put('global', guild.slash, [...contextCommands, ...slashCommands]);
261
+ this.put('guild', guild.slash, []);
262
+ }
263
+ if (global.slash && global.context === false) {
264
+ this.put('global', guild.slash, slashCommands);
265
+ }
266
+ if (global.slash === false && global.context) {
267
+ this.put('global', guild.context, contextCommands);
268
+ }
269
+ if (global.slash === false && global.context === false) {
270
+ this.put('guild', guild.slash, [...contextCommands, ...slashCommands]);
271
+ }
272
+ if (this.client.handlerOptions.context?.logging || this.client.handlerOptions.slash?.logging)
273
+ console.info(
274
+ Style.log(
275
+ `Xernerx | Deployed ${slashCommands.length} slash commands ${global.slash ? 'globally' : 'locally'} and ${contextCommands.length} context commands ${
276
+ global.context ? 'globally' : 'locally'
277
+ }.`,
278
+ { color: Style.TextColor.Purple }
279
+ )
280
+ );
281
+ } catch (error) {
282
+ console.error(
283
+ Style.log(`Xernerx | Couldn't deploy interaction commands because <${error}>.`, {
284
+ color: Style.BackgroundColor.Red,
285
+ })
286
+ );
287
+ }
288
+ });
289
+ }
290
+ put(type, guild, body) {
291
+ const rest = new REST({ version: GatewayVersion }).setToken(this.client.token);
292
+ if (type === 'guild') rest.put(Routes.applicationGuildCommands(this.client.user?.id, guild), { body });
293
+ else rest.put(Routes.applicationCommands(this.client.user?.id), { body });
294
+ }
295
+ }
@@ -0,0 +1,7 @@
1
+ import XernerxExtensionBuilder from 'xernerx-extension-builder';
2
+ import XernerxClient from '../client/XernerxClient.js';
3
+ export default class Extensions {
4
+ client: XernerxClient;
5
+ constructor(client: XernerxClient);
6
+ load(extensions: Array<XernerxExtensionBuilder>, logging?: boolean): Promise<void>;
7
+ }
@@ -0,0 +1,23 @@
1
+ import { Style } from 'dumfunctions';
2
+ export default class Extensions {
3
+ client;
4
+ constructor(client) {
5
+ this.client = client;
6
+ }
7
+ async load(extensions, logging = false) {
8
+ const exts = [];
9
+ extensions.map((extension) => {
10
+ try {
11
+ this.client.extensions[extension.name] = extension;
12
+ exts.push(extension.name);
13
+ } catch (error) {
14
+ console.error(
15
+ Style.log(`Xernerx | An error occurred trying to load ${extension.name}, error: <${error}>`, {
16
+ color: Style.BackgroundColor.Red,
17
+ })
18
+ );
19
+ }
20
+ });
21
+ if (logging) console.info(Style.log(`Xernerx | Loaded ${exts.length} extensions: ${exts.join(', ')}`, { color: Style.TextColor.Cyan }));
22
+ }
23
+ }
@@ -0,0 +1,5 @@
1
+ export default class XernerxError {
2
+ name: string;
3
+ message: string;
4
+ constructor(message?: string);
5
+ }
@@ -0,0 +1,8 @@
1
+ export default class XernerxError {
2
+ name;
3
+ message;
4
+ constructor(message) {
5
+ this.name = 'XernerxError';
6
+ this.message = message || '';
7
+ }
8
+ }