xernerx 2.7.4 → 3.0.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 (76) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +0 -0
  3. package/dist/build/ContextCommand.d.ts +39 -0
  4. package/dist/build/ContextCommand.js +86 -0
  5. package/dist/build/Event.d.ts +15 -0
  6. package/dist/build/Event.js +31 -0
  7. package/dist/build/Inhibitor.d.ts +12 -0
  8. package/dist/build/Inhibitor.js +20 -0
  9. package/dist/build/MessageCommand.d.ts +39 -0
  10. package/dist/build/MessageCommand.js +77 -0
  11. package/dist/build/SlashCommand.d.ts +32 -0
  12. package/dist/build/SlashCommand.js +119 -0
  13. package/dist/client/XernerxClient.d.ts +22 -0
  14. package/dist/client/XernerxClient.js +76 -0
  15. package/dist/handlers/CommandHandler.d.ts +27 -0
  16. package/dist/handlers/CommandHandler.js +42 -0
  17. package/dist/handlers/EventHandler.d.ts +13 -0
  18. package/dist/handlers/EventHandler.js +16 -0
  19. package/dist/handlers/Handler.d.ts +37 -0
  20. package/dist/handlers/Handler.js +242 -0
  21. package/dist/handlers/InhibitorHandler.d.ts +18 -0
  22. package/dist/handlers/InhibitorHandler.js +21 -0
  23. package/dist/interfaces/ClientInterfaces.d.ts +58 -0
  24. package/dist/interfaces/ClientInterfaces.js +1 -0
  25. package/dist/interfaces/CommandInterfaces.d.ts +94 -0
  26. package/dist/interfaces/CommandInterfaces.js +1 -0
  27. package/dist/interfaces/HandlerInterfaces.d.ts +70 -0
  28. package/dist/interfaces/HandlerInterfaces.js +1 -0
  29. package/dist/main.d.ts +26 -0
  30. package/dist/main.js +40 -0
  31. package/dist/models/CommandArguments.d.ts +9 -0
  32. package/dist/models/CommandArguments.js +128 -0
  33. package/dist/models/CommandValidations.d.ts +3 -0
  34. package/dist/models/CommandValidations.js +193 -0
  35. package/dist/models/Events.d.ts +23 -0
  36. package/dist/models/Events.js +328 -0
  37. package/dist/models/Functions.d.ts +1 -0
  38. package/dist/models/Functions.js +30 -0
  39. package/dist/models/InhibitorValidations.d.ts +17 -0
  40. package/dist/models/InhibitorValidations.js +42 -0
  41. package/dist/types/EventTypes.d.ts +1 -0
  42. package/dist/types/EventTypes.js +1 -0
  43. package/dist/types/InhibitorTypes.d.ts +12 -0
  44. package/dist/types/InhibitorTypes.js +13 -0
  45. package/dist/types/Types.d.ts +24 -0
  46. package/dist/types/Types.js +21 -0
  47. package/dist/utils/ClientUtil.d.ts +25 -0
  48. package/dist/utils/ClientUtil.js +232 -0
  49. package/dist/utils/CommandUtil.d.ts +24 -0
  50. package/dist/utils/CommandUtil.js +163 -0
  51. package/package.json +5 -8
  52. package/main.js +0 -49
  53. package/models/Client.js +0 -60
  54. package/models/commands/ContextMenuCommand.js +0 -68
  55. package/models/commands/Event.js +0 -33
  56. package/models/commands/Inhibitor.js +0 -31
  57. package/models/commands/InteractionCommand.js +0 -142
  58. package/models/commands/MessageCommand.js +0 -86
  59. package/models/data/colors.json +0 -16
  60. package/models/data/options.json +0 -27
  61. package/models/events/interactionCreate.js +0 -84
  62. package/models/events/messageCreate.js +0 -84
  63. package/models/events/messageUpdate.js +0 -83
  64. package/models/events/readyOnce.js +0 -58
  65. package/models/handlers/CommandHandler.js +0 -37
  66. package/models/handlers/EventHandler.js +0 -67
  67. package/models/handlers/Handler.js +0 -111
  68. package/models/handlers/InhibitorHandler.js +0 -16
  69. package/models/handlers/LanguageHandler.js +0 -37
  70. package/models/utils/Arguments.js +0 -120
  71. package/models/utils/CommandValidation.js +0 -96
  72. package/models/utils/CommandsUtil.js +0 -70
  73. package/models/utils/Functions.js +0 -266
  74. package/models/utils/InhibitorsUtil.js +0 -24
  75. package/models/utils/InhibitorsValidation.js +0 -40
  76. package/models/utils/Util.js +0 -96
package/dist/main.js ADDED
@@ -0,0 +1,40 @@
1
+ import Discord from "discord.js";
2
+ import XernerxClient from "./client/XernerxClient.js";
3
+ import { Event } from "./build/Event.js";
4
+ import { Inhibitor } from "./build/Inhibitor.js";
5
+ import { MessageCommand } from "./build/MessageCommand.js";
6
+ import { ContextCommand } from "./build/ContextCommand.js";
7
+ import { SlashCommand } from "./build/SlashCommand.js";
8
+ import { CommandType, EventEmitterType } from "./types/Types.js";
9
+ import { InhibitorType } from "./types/InhibitorTypes.js";
10
+ const version = "3.0.0";
11
+ export default {
12
+ // Imported methods
13
+ Discord,
14
+ // Client
15
+ Client: XernerxClient,
16
+ XernerxClient,
17
+ // Types
18
+ CommandType,
19
+ EventEmitterType,
20
+ InhibitorType,
21
+ // Builds
22
+ Event,
23
+ MessageCommand,
24
+ ContextCommand,
25
+ SlashCommand,
26
+ Inhibitor,
27
+ // Constants
28
+ version,
29
+ };
30
+ export {
31
+ // Imported methods
32
+ Discord,
33
+ // Client
34
+ XernerxClient,
35
+ // Types
36
+ CommandType, EventEmitterType, InhibitorType,
37
+ // Builds
38
+ Event, MessageCommand, ContextCommand, SlashCommand, Inhibitor,
39
+ // Constants
40
+ version, };
@@ -0,0 +1,9 @@
1
+ import { Interaction, Message } from "discord.js";
2
+ export declare class CommandArguments {
3
+ action: any;
4
+ constructor(action: Message | Interaction);
5
+ group(): any;
6
+ subcommand(): any;
7
+ arguments(): Record<string, object>;
8
+ }
9
+ export declare function messageArgs(message: any, command: any): Promise<any>;
@@ -0,0 +1,128 @@
1
+ export class CommandArguments {
2
+ action;
3
+ constructor(action) {
4
+ this.action = action;
5
+ }
6
+ group() {
7
+ return this.action?.options?._group;
8
+ }
9
+ subcommand() {
10
+ return this.action?.options?._subcommand;
11
+ }
12
+ arguments() {
13
+ const options = {};
14
+ if (this.action?.options?._hoistedOptions) {
15
+ for (const option of this.action.options._hoistedOptions) {
16
+ options[option.name] =
17
+ option.channel || option.user || option.role || option.value;
18
+ }
19
+ }
20
+ return options;
21
+ }
22
+ }
23
+ export async function messageArgs(message, command) {
24
+ let args = { flags: {} }, separator = command.separator || " ", i = 0;
25
+ if (!command.args)
26
+ return;
27
+ command.args
28
+ .filter((c) => c.type == "flag")
29
+ .map((flag) => {
30
+ for (const flg of message.content.matchAll(flag.content)) {
31
+ if (flag.content == flg) {
32
+ message.content = message.content.replace(flag.content, "");
33
+ args.flags[flag.name] = true;
34
+ }
35
+ }
36
+ if (!args.flags[flag.name])
37
+ args.flags[flag.name] = false;
38
+ });
39
+ for (const argument of command.args) {
40
+ let content = message.content
41
+ .split(/ +/)
42
+ .slice(1)
43
+ .join(separator)
44
+ .replace(new RegExp(`${separator}${separator}+`, "g"), separator)
45
+ .split(separator)
46
+ .slice(i);
47
+ if (content.join(separator) != "" && argument.type !== "flag") {
48
+ if (argument?.content?.includes(content[0])) {
49
+ args[argument.name] = content[0];
50
+ }
51
+ else if (argument.type == "string") {
52
+ args[argument.name] = content[0];
53
+ }
54
+ else if (argument.type == "number") {
55
+ args[argument.name] = parseInt(content[0]);
56
+ }
57
+ else if (argument.type == "boolean") {
58
+ if (content[0]?.toLowerCase() != "true" &&
59
+ content[0]?.toLowerCase() != "false")
60
+ content[0] = undefined;
61
+ args[argument.name] = content[0];
62
+ }
63
+ else if (argument.type == "user") {
64
+ let user = message.client.users.cache.find((u) => u?.username?.toLowerCase()?.includes(content[0]));
65
+ try {
66
+ user = await message.client.users.fetch(user?.id || content[0].replace(/<@!?|>/g, ""));
67
+ }
68
+ catch (e) {
69
+ user = new Error("Invalid user snowflake ID");
70
+ }
71
+ args[argument.name] = user;
72
+ }
73
+ else if (argument.type == "role") {
74
+ let role = message.guild.roles.cache.find((r) => r?.name?.toLowerCase()?.includes(content[0]));
75
+ try {
76
+ role = await message.guild.roles.fetch(role?.id || content[0].replace(/<@&?|>/g, ""));
77
+ }
78
+ catch (e) {
79
+ role = new Error("Invalid role snowflake ID");
80
+ }
81
+ args[argument.name] = role;
82
+ }
83
+ else if (argument.type == "member") {
84
+ let member = message.guild.members.cache.find((m) => m?.nickname?.toLowerCase()?.includes(content[0]) ||
85
+ m?.user?.username?.toLowerCase()?.includes(content[0]));
86
+ try {
87
+ member = await message.guild.members.fetch(member?.id || content[0].replace(/<@!?|>/g, ""));
88
+ }
89
+ catch (e) {
90
+ member = new Error("Invalid member snowflake ID");
91
+ }
92
+ args[argument.name] = member;
93
+ }
94
+ else if (argument.type == "channel") {
95
+ let channel = message.guild.channels.cache.find((c) => c?.name?.toLowerCase()?.includes(content[0]));
96
+ try {
97
+ channel = await message.client.channels.fetch(channel?.id || content[0].replace(/<#|>/g, ""));
98
+ }
99
+ catch (e) {
100
+ channel = new Error("Invalid channel snowflake ID");
101
+ }
102
+ args[argument.name] = channel;
103
+ }
104
+ else if (argument.type == "rest") {
105
+ args[argument.name] = content.join(separator);
106
+ break;
107
+ }
108
+ else if (argument.prompt) {
109
+ if (argument.prompt.reply)
110
+ return message.reply(argument.prompt.reply);
111
+ else if (argument.prompt.send)
112
+ return message.channel.send(argument.prompt.send);
113
+ }
114
+ else
115
+ args[argument.name] =
116
+ typeof argument.default == "function"
117
+ ? argument.default(message)
118
+ : argument.default;
119
+ i++;
120
+ }
121
+ else
122
+ args[argument.name] =
123
+ typeof argument.default == "function"
124
+ ? argument.default(message)
125
+ : argument.default;
126
+ }
127
+ return args;
128
+ }
@@ -0,0 +1,3 @@
1
+ import { Interaction, Message } from "discord.js";
2
+ import { XernerxClient, SlashCommand, MessageCommand, ContextCommand } from "../main.js";
3
+ export default function commandValidation(action: Message | Interaction, command: SlashCommand | MessageCommand | ContextCommand | any, client: XernerxClient, res?: boolean): boolean;
@@ -0,0 +1,193 @@
1
+ import { Message } from "discord.js";
2
+ import { CommandType } from "../types/Types.js";
3
+ function getUser(from) {
4
+ if (from instanceof Message)
5
+ return from.author;
6
+ else
7
+ return from.user;
8
+ }
9
+ export default function commandValidation(action, command, client, res = false) {
10
+ let user = getUser(action);
11
+ if ((command.ignoreOwner || client.settings.ignoreOwner) &&
12
+ client.util.isOwner(user.id))
13
+ return res;
14
+ else if (inCooldown(user, client, command, action))
15
+ return true;
16
+ else if (command.owner && !client.util.isOwner(user.id)) {
17
+ res = true;
18
+ emit(client, action, "Not an owner", client.settings.ownerId);
19
+ }
20
+ else if (command.channelType?.length > 0 || command.channelType) {
21
+ if (!Array.isArray(command.channelType))
22
+ command.channelType = [command.channelType];
23
+ if (!command?.channelType?.includes(action.channel?.type)) {
24
+ res = true;
25
+ emit(client, action, "Not the correct channel", command.channelType);
26
+ }
27
+ }
28
+ else if (command.channels?.length > 0 &&
29
+ !command.channels.includes(action.channel?.id)) {
30
+ res = true;
31
+ emit(client, action, "Not a whitelisted channel", command.channels);
32
+ }
33
+ else if (command.guilds?.length > 0 &&
34
+ !command.guilds.includes(action.guild?.id)) {
35
+ res = true;
36
+ emit(client, action, "Not a whitelisted guild", command.guilds);
37
+ }
38
+ else if (action?.guild &&
39
+ (command.userPermissions || client.settings.userPermissions)) {
40
+ const permissions = command.userPermissions ||
41
+ client?.settings?.userPermissions?.push(...handlerPermissions(client, command.commandType, "user")), missing = [];
42
+ if (Array.isArray(permissions))
43
+ permissions.map((permission) => {
44
+ if (!(action.member?.permissions).has(permission)) {
45
+ missing.push(permission);
46
+ }
47
+ });
48
+ if (missing.length > 0) {
49
+ res = true;
50
+ emit(client, action, "Missing User Permissions", missing);
51
+ }
52
+ }
53
+ else if (action?.guild &&
54
+ (command.clientPermissions || client.settings.clientPermissions)) {
55
+ const permissions = command.clientPermissions ||
56
+ client?.settings?.clientPermissions?.push(...handlerPermissions(client, command.commandType, "client")), missing = [];
57
+ if (Array.isArray(permissions))
58
+ permissions.map((permission) => {
59
+ if (!(action.member?.permissions).has(permission)) {
60
+ missing.push(permission);
61
+ }
62
+ });
63
+ if (missing.length > 0) {
64
+ res = true;
65
+ emit(client, action, "Missing Client Permissions", missing);
66
+ }
67
+ }
68
+ return res;
69
+ }
70
+ function emit(client, action, reason, extra) {
71
+ return client.emit("commandBlock", action, reason, extra);
72
+ }
73
+ function inCooldown(user, client, command, action) {
74
+ let res = false, downs = {};
75
+ const { cooldowns, messageCommands, slashCommands, contextCommands, commands, } = client.cache;
76
+ if (command.commandType === CommandType.MessageCommand &&
77
+ client.handlerOptions.message.cooldown) {
78
+ if (messageCommands.has(user.id)) {
79
+ const usr = messageCommands.get(user.id);
80
+ usr.timeRemaining = usr.endsAt - Date.now();
81
+ downs.message = usr;
82
+ res = true;
83
+ }
84
+ if (!messageCommands.has(user.id)) {
85
+ messageCommands.set(user.id, toCooldown(action, command, client.handlerOptions.message.cooldown, user.id));
86
+ setInterval(() => {
87
+ messageCommands.delete(user.id);
88
+ }, client.handlerOptions.message.cooldown);
89
+ }
90
+ }
91
+ if (command.commandType === CommandType.SlashCommand &&
92
+ client.handlerOptions.slash.cooldown) {
93
+ if (slashCommands.has(user.id)) {
94
+ const usr = slashCommands.get(user.id);
95
+ usr.timeRemaining = usr.endsAt - Date.now();
96
+ downs.slash = usr;
97
+ res = true;
98
+ }
99
+ if (!slashCommands.has(user.id)) {
100
+ slashCommands.set(user.id, toCooldown(action, command, client.handlerOptions.slash.cooldown, user.id));
101
+ setInterval(() => {
102
+ slashCommands.delete(user.id);
103
+ }, client.handlerOptions.slash.cooldown);
104
+ }
105
+ }
106
+ if (command.commandType === CommandType.ContextCommand &&
107
+ client.handlerOptions.context.cooldown) {
108
+ if (contextCommands.has(user.id)) {
109
+ const usr = contextCommands.get(user.id);
110
+ usr.timeRemaining = usr.endsAt - Date.now();
111
+ downs.context = usr;
112
+ res = true;
113
+ }
114
+ if (!contextCommands.has(user.id)) {
115
+ contextCommands.set(user.id, toCooldown(action, command, client.handlerOptions.context.cooldown, user.id));
116
+ setInterval(() => {
117
+ contextCommands.delete(user.id);
118
+ }, client.handlerOptions.context.cooldown);
119
+ }
120
+ }
121
+ if (client.settings.cooldown.default) {
122
+ if (cooldowns.has(user.id)) {
123
+ const usr = cooldowns.get(user.id);
124
+ usr.timeRemaining = usr.endsAt - Date.now();
125
+ downs.default = usr;
126
+ res = true;
127
+ }
128
+ if (!cooldowns.has(user.id)) {
129
+ cooldowns.set(user.id, toCooldown(action, command, client.settings.cooldown.default, user.id));
130
+ setInterval(() => {
131
+ cooldowns.delete(user.id);
132
+ }, client.settings.cooldown.default);
133
+ }
134
+ }
135
+ if (command.cooldown) {
136
+ const name = user.id +
137
+ "-" +
138
+ (command.data?.name || command?.name) +
139
+ "-" +
140
+ command.commandType;
141
+ if (commands.has(name)) {
142
+ const usr = commands.get(name);
143
+ usr.timeRemaining = usr.endsAt - Date.now();
144
+ downs.command = usr;
145
+ res = true;
146
+ }
147
+ if (!commands.has(name)) {
148
+ commands.set(name, toCooldown(action, command, command.cooldown, name));
149
+ setInterval(() => {
150
+ commands.delete(name);
151
+ }, command.cooldown);
152
+ }
153
+ }
154
+ if (Object.keys(downs).length > 0)
155
+ client.emit("commandCooldown", action, command, downs);
156
+ return res;
157
+ }
158
+ function toCooldown(action, command, cooldown, name) {
159
+ let user = getUser(action);
160
+ return {
161
+ name,
162
+ id: user.id,
163
+ tag: user.tag,
164
+ commandType: command.commandType,
165
+ commandName: command?.data?.name || command?.name,
166
+ guildId: action?.guild?.id,
167
+ channelId: action?.channel?.id,
168
+ startsAt: Number(Date.now()),
169
+ endsAt: Number(Date.now()) + cooldown,
170
+ };
171
+ }
172
+ function handlerPermissions(client, commandType, type) {
173
+ let permissions = [];
174
+ if (commandType === CommandType.MessageCommand) {
175
+ if (type === "user")
176
+ permissions = client.handlerOptions.message?.userPermissions || [];
177
+ else if (type === "client")
178
+ permissions = client.handlerOptions.message?.clientPermissions || [];
179
+ }
180
+ else if (commandType === CommandType.SlashCommand) {
181
+ if (type === "user")
182
+ permissions = client.handlerOptions.slash?.userPermissions || [];
183
+ else if (type === "client")
184
+ permissions = client.handlerOptions.slash?.clientPermissions || [];
185
+ }
186
+ else if (commandType === CommandType.ContextCommand) {
187
+ if (type === "user")
188
+ permissions = client.handlerOptions.context?.userPermissions || [];
189
+ else if (type === "client")
190
+ permissions = client.handlerOptions.context?.clientPermissions || [];
191
+ }
192
+ return permissions;
193
+ }
@@ -0,0 +1,23 @@
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
+ client: XernerxClient;
21
+ constructor(client: XernerxClient);
22
+ deploy(): void;
23
+ }