xernerx 2.7.5 → 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
@@ -1,111 +0,0 @@
1
- const fs = require('fs');
2
- const Discord = require('discord.js');
3
- const { REST } = require('@discordjs/rest');
4
- const { Routes, GatewayVersion } = require('discord-api-types/v10');
5
- const { logStyle } = require('dumfunctions');
6
- const { importCommands, reimportCommands } = require('../utils/CommandsUtil.js');
7
- const { importInhibitors } = require('../utils/InhibitorsUtil.js');
8
-
9
- module.exports = class Handler {
10
- constructor(client) {
11
- this.client = client;
12
-
13
- this.commands = [];
14
- }
15
-
16
- loadAllInteractionCommands(path, logging = false) {
17
- const files = this.#readdir(path);
18
-
19
- importCommands(this.client, path, files, this.commands, 'interaction');
20
-
21
- this.#deployCommands("interaction commands", logging);
22
- }
23
-
24
- reloadAllInteractionCommands() {
25
- reimportCommands(this.client, this.commands, "interaction");
26
-
27
- return this.#redeployCommands()
28
- }
29
-
30
- loadAllContextMenuCommands(path, logging = false) {
31
- const files = this.#readdir(path);
32
-
33
- importCommands(this.client, path, files, this.commands, 'contextMenu');
34
-
35
- this.#deployCommands("context menu commands", logging);
36
- }
37
-
38
- reloadAllContextMenuCommands() {
39
- reimportCommands(this.client, this.commands, "contextMenu");
40
-
41
- return this.#redeployCommands()
42
- }
43
-
44
- loadAllMessageCommands(path) {
45
- const files = this.#readdir(path);
46
-
47
- importCommands(this.client, path, files, this.commands, 'message');
48
- }
49
-
50
- reloadAllMessageCommands() {
51
- return reimportCommands(this.client, this.commands, "message");
52
- }
53
-
54
- loadAllInhibitors(path) {
55
- const files = this.#readdir(path);
56
-
57
- importInhibitors(this.client, path, files);
58
- }
59
-
60
- #deployCommands(type, logging = false) {
61
- this.client.once('ready', async client => {
62
- const rest = new REST({ version: GatewayVersion }).setToken(client.token);
63
-
64
- try {
65
- if (client.settings.global == true) {
66
- if (logging || this.client.settings.logging) console.info(logStyle(`Loaded ${type} in ${(await client.guilds.fetch()).size} server(s) globally.`, 'text', 'purple'));
67
- rest.put(Routes.applicationCommands(client.user.id), {
68
- body: this.commands
69
- })
70
- }
71
- else {
72
- if (logging || this.client.settings.logging) console.info(logStyle(`Loaded ${type} locally.`, 'text', 'purple'));
73
- rest.put(Routes.applicationGuildCommands(client.user.id, client.settings.guildId), {
74
- body: this.commands
75
- })
76
- }
77
- }
78
- catch (e) {
79
- throw new Error(e)
80
- }
81
- })
82
- }
83
-
84
- #redeployCommands() {
85
- const rest = new REST({ version: GatewayVersion }).setToken(this.client.token);
86
-
87
- (async () => {
88
- try {
89
- if (this.client.settings.global == true) {
90
- rest.put(Routes.applicationCommands(this.client.user.id), {
91
- body: this.commands
92
- })
93
- }
94
- else {
95
- rest.put(Routes.applicationGuildCommands(this.client.user.id, this.client.settings.guildId), {
96
- body: this.commands
97
- })
98
- }
99
- }
100
- catch (e) {
101
- throw new Error(e)
102
- }
103
- })();
104
-
105
- return this.commands;
106
- }
107
-
108
- #readdir(path) {
109
- return fs.readdirSync(path).filter(file => file.endsWith('.js'));
110
- }
111
- }
@@ -1,16 +0,0 @@
1
- const Handler = require("./Handler");
2
- const Discord = require('discord.js');
3
-
4
- module.exports = class InhibitorHandler {
5
- constructor(client) {
6
- this.client = client;
7
-
8
- client.inhibitors = new Discord.Collection();
9
-
10
- this.load = new Handler(client);
11
- }
12
-
13
- loadAllInhibitors(path) {
14
- this.load.loadAllInhibitors(path);
15
- }
16
- }
@@ -1,37 +0,0 @@
1
- const { logStyle } = require('dumfunctions');
2
- const fs = require('fs');
3
- const i = require('i18next');
4
-
5
- class LanguageHandler {
6
- constructor(client) {
7
- this.client = client;
8
-
9
- i.init(this.client.language);
10
-
11
- this.client.languages = [];
12
- }
13
-
14
- loadAllLanguages(path, deep = true, overwrite = true) {
15
-
16
-
17
- const languages = fs.readdirSync(path).filter(file => file.endsWith('.json'));
18
-
19
- for (const file of languages) {
20
- const language = require(`${require("path").resolve(path)}/${file}`);
21
-
22
- i.addResourceBundle(
23
- file.replace('.json', ""),
24
- ...this.client.language.ns,
25
- language,
26
- deep,
27
- overwrite
28
- );
29
-
30
- this.client.languages.push(file.replace('.json', ""));
31
- }
32
-
33
- if (this.client.settings.logging) console.info(logStyle(`Loaded languages: ${this.client.languages.join(', ')}`, 'text', 'purple'));
34
- }
35
- }
36
-
37
- module.exports = { LanguageHandler };
@@ -1,120 +0,0 @@
1
- module.exports = new class Arguments {
2
- /**
3
- *
4
- * @param {object} interaction - Interaction event.
5
- * @returns argument options without having to do the whole builders way.
6
- */
7
- interactionArgs(interaction) {
8
- let group, sub, options = {};
9
-
10
- if (interaction?.options?._group) group = interaction.options._group;
11
-
12
- if (interaction?.options?._subcommand) sub = interaction.options._subcommand;
13
-
14
- if (interaction?.options?._hoistedOptions) {
15
- for (const option of interaction.options._hoistedOptions) {
16
- options[option.name] = option.channel || option.user || option.role || option.value;
17
- }
18
- }
19
-
20
- return { group, sub, options };
21
- }
22
-
23
- /**
24
- *
25
- * @param {object} message - Message Object.
26
- * @param {object} command - Command Class.
27
- * @returns argument options without having to make them yourself.
28
- */
29
- async messageArgs({ message: message, command: command }) {
30
- let args = { flags: {} }, separator = command.separator || ' ', i = 0;
31
-
32
- if (!command.args) return;
33
-
34
- command.args.filter(c => c.type == "flag").map(flag => {
35
- for (const flg of message.content.matchAll(flag.content)) {
36
- if (flag.content == flg) {
37
- message.content = message.content.replace(flag.content, "");
38
-
39
- args.flags[flag.name] = true;
40
- }
41
- }
42
-
43
- if (!args.flags[flag.name]) args.flags[flag.name] = false;
44
- })
45
-
46
- for (const argument of command.args) {
47
- let content = message.content.split(/ +/).slice(1).join(separator).replace(new RegExp(`${separator}${separator}+`, "g"), separator).split(separator).slice(i);
48
-
49
- if (content.join(separator) != '' && argument.type !== "flag") {
50
- if (argument?.content?.includes(content[0])) {
51
- args[argument.name] = content[0];
52
- }
53
-
54
- else if (argument.type == 'string') {
55
- args[argument.name] = content[0];
56
- }
57
-
58
- else if (argument.type == 'number') {
59
- args[argument.name] = parseInt(content[0]);
60
- }
61
-
62
- else if (argument.type == 'boolean') {
63
- if (content[0]?.toLowerCase() != 'true' && content[0]?.toLowerCase() != 'false') content[0] = undefined;
64
-
65
- args[argument.name] = content[0];
66
- }
67
-
68
- else if (argument.type == 'user') {
69
- let user = message.client.users.cache.find(u => u?.username?.toLowerCase()?.includes(content[0]));
70
-
71
- try { user = await message.client.users.fetch(user?.id || content[0].replace(/<@!?|>/g, "")) } catch (e) { user = new Error("Invalid user snowflake ID") };
72
-
73
- args[argument.name] = user;
74
- }
75
-
76
- else if (argument.type == 'role') {
77
- let role = message.guild.roles.cache.find(r => r?.name?.toLowerCase()?.includes(content[0]));
78
-
79
- try { role = await message.guild.roles.fetch(role?.id || content[0].replace(/<@&?|>/g, "")) } catch (e) { role = new Error("Invalid role snowflake ID") };
80
-
81
- args[argument.name] = role;
82
- }
83
-
84
- else if (argument.type == 'member') {
85
- let member = message.guild.members.cache.find(m => m?.nickname?.toLowerCase()?.includes(content[0]) || m?.user?.username?.toLowerCase()?.includes(content[0]));
86
-
87
- try { member = await message.guild.members.fetch(member?.id || content[0].replace(/<@!?|>/g, "")) } catch (e) { member = new Error("Invalid member snowflake ID") };
88
-
89
- args[argument.name] = member;
90
- }
91
-
92
- else if (argument.type == 'channel') {
93
- let channel = message.guild.channels.cache.find(c => c?.name?.toLowerCase()?.includes(content[0]));
94
-
95
- try { channel = await message.client.channels.fetch(channel?.id || content[0].replace(/<#|>/g, "")) } catch (e) { channel = new Error("Invalid channel snowflake ID") }
96
-
97
- args[argument.name] = channel;
98
- }
99
-
100
- else if (argument.type == 'rest') {
101
- args[argument.name] = content.join(separator);
102
- break;
103
- }
104
-
105
- else if (argument.prompt) {
106
- if (argument.prompt.reply) return message.reply(argument.prompt.reply);
107
- else if (argument.prompt.send) return message.channel.send(argument.prompt.send);
108
- }
109
-
110
- else args[argument.name] = typeof argument.default == 'function' ? argument.default(message) : argument.default;
111
-
112
- i++
113
- }
114
-
115
- else args[argument.name] = typeof argument.default == 'function' ? argument.default(message) : argument.default;
116
- }
117
-
118
- return args;
119
- }
120
- }
@@ -1,96 +0,0 @@
1
- const Discord = require('discord.js');
2
- const { toPascalCase } = require('dumfunctions');
3
-
4
- module.exports = new class CommandValidation {
5
- commandValidation(event, command, res = false) {
6
- function emit(reason, extra) {
7
- return event.client.emit('commandBlocked', event, reason, extra);
8
- }
9
-
10
- if ((command?.ignoreOwner || event?.client?.settings?.ignoreOwner) && event?.client?.settings?.ownerId?.includes((event.user || event.author).id)) return res;
11
-
12
- if (event.client.data.cooldowns[(event.user || event.author).id]) {
13
- res = true;
14
- return emit("command on cooldown", (event.client.data.cooldowns[(event.user || event.author).id] - (event.editedTimestamp || event.createdTimestamp)));
15
- }
16
-
17
- if (!event.client.data.cooldowns[(event.user || event.author).id]) {
18
- event.client.data.cooldowns[(event.user || event.author).id] = ((event.editedTimestamp || event.createdTimestamp) + (command.cooldown || event.client.settings.defaultCooldown || 0));
19
-
20
- setTimeout(() => {
21
- delete event.client.data.cooldowns[(event.user || event.author).id]
22
- }, command.cooldown || event?.client?.settings?.defaultCooldown || 0);
23
- }
24
-
25
- if (command?.owner && event?.client?.settings?.ownerId != undefined && !event?.client?.settings?.ownerId?.includes((event.user || event.author).id)) {
26
- res = true;
27
- return emit("missing ownership", event?.client?.settings?.ownerId)
28
- }
29
-
30
- if (command?.admin && event?.member?.permissions?.has(Discord.PermissionFlagsBits.Administrator) == false) {
31
- res = true;
32
- return emit("missing admin permission", "Administrator")
33
- }
34
-
35
- if (command?.channel == "guild" && event?.channel?.type != Discord.ChannelType.GuildText) {
36
- res = true
37
- return emit("not a guild channel");
38
- }
39
-
40
- if (command?.channel == "dm" && event?.type != null) {
41
- res = true;
42
- return emit("not a dm channel");
43
- }
44
-
45
- if (command?.inVoice && !event?.member?.voice?.channelId) {
46
- res = true;
47
- return emit("not a in a voice channel");
48
- }
49
-
50
- if (event?.guild && command?.userPermissions?.length >= 1 || event?.client?.settings?.userPermissions?.length >= 1) {
51
- let missingPerms = [];
52
-
53
- for (const permission of command.userPermissions) {
54
- if (!event?.member?.permissions?.has(Discord.PermissionFlagsBits[toPascalCase(permission)])) missingPerms.push(toPascalCase(permission));
55
- }
56
-
57
- for (const permission of event?.client?.settings?.userPermissions) {
58
- if (!event?.member?.permissions?.has(Discord.PermissionFlagsBits[toPascalCase(permission)])) missingPerms.push(toPascalCase(permission));
59
- }
60
-
61
- if (missingPerms?.length >= 1) {
62
- res = true;
63
- return emit("missing user permissions", missingPerms);
64
- }
65
- }
66
-
67
- if (event?.guild && command?.clientPermissions?.length >= 1 || event?.client?.settings?.clientPermissions?.length >= 1) {
68
- let missingPerms = [];
69
-
70
- for (const permission of command?.clientPermissions) {
71
- if (!event?.guild?.members?.me?.permissions?.has(Discord.PermissionFlagsBits[toPascalCase(permission)])) missingPerms.push(toPascalCase(permission));
72
- }
73
-
74
- for (const permission of event?.client?.settings?.clientPermissions) {
75
- if (!event?.guild?.members?.me?.permissions?.has(Discord.PermissionFlagsBits[toPascalCase(permission)])) missingPerms.push(toPascalCase(permission));
76
- }
77
-
78
- if (missingPerms.length >= 1) {
79
- res = true;
80
- return emit("missing client permissions", missingPerms);
81
- }
82
- }
83
-
84
- if (command?.guilds?.length >= 1 && !command?.guilds?.includes(event.guild)) {
85
- res = true;
86
- return emit('not in a specified guild', command.guilds);
87
- }
88
-
89
- if (command?.channels?.length >= 1 && !command?.channels?.includes(event.channel.id)) {
90
- res = true;
91
- return emit('not in a specified channel', command.channels);
92
- }
93
-
94
- return res;
95
- }
96
- }
@@ -1,70 +0,0 @@
1
- const { logStyle } = require("dumfunctions");
2
-
3
- module.exports = new class CommandsUtil {
4
- importCommands(client, path, files, commands, type) {
5
- for (const file of files) {
6
- try {
7
- let filepath = `${require("path").resolve(path)}/${file}`;
8
-
9
- let command = require(filepath);
10
-
11
- command = new command;
12
-
13
- command.filepath = filepath;
14
-
15
- command.runType = type;
16
-
17
- command.client = client;
18
-
19
- if (type !== 'message') {
20
- commands.push(command.data.toJSON());
21
-
22
- client.commands[type].set(command.data.name, command);
23
- }
24
-
25
- if (type === 'message') {
26
- client.commands[type].set(command.name, command);
27
- }
28
- }
29
- catch (error) {
30
- console.error(logStyle(`Couldn't load ${file} because of <${error.message}>!`, "text", "red"));
31
- }
32
- }
33
-
34
- return commands;
35
- }
36
-
37
- reimportCommands(client, cmds, type) {
38
- let commands = [];
39
-
40
- client.commands[type].map(command => { if (!commands.includes(command.filepath)) commands.push(command.filepath) });
41
-
42
- client.commands[type].sweep(() => true);
43
-
44
- commands.map(path => {
45
- delete require.cache[require.resolve(path)];
46
-
47
- let command = require(path);
48
-
49
- command = new command;
50
-
51
- command.filepath = path;
52
-
53
- command.runType = type;
54
-
55
- command.client = client;
56
-
57
- if (type !== 'message') {
58
- cmds.push(command.data.toJSON());
59
-
60
- client.commands[type].set(command.data.name, command);
61
- }
62
-
63
- if (type === 'message') {
64
- client.commands[type].set(command.name, command);
65
- }
66
- })
67
-
68
- return commands;
69
- }
70
- }