xernerx 3.5.0 → 3.5.2

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