reciple 5.5.6 → 6.0.0-dev.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.
- package/dist/cjs/bin.js +6 -7
- package/dist/cjs/index.js +6 -5
- package/dist/cjs/reciple/classes/RecipleClient.js +21 -144
- package/dist/cjs/reciple/classes/builders/MessageCommandBuilder.js +13 -2
- package/dist/cjs/reciple/classes/builders/MessageCommandOptionBuilder.js +14 -0
- package/dist/cjs/reciple/classes/builders/SlashCommandBuilder.js +9 -0
- package/dist/cjs/reciple/classes/managers/ApplicationCommandManager.js +137 -0
- package/dist/cjs/reciple/classes/managers/ClientCommandManager.js +62 -0
- package/dist/cjs/reciple/classes/managers/ClientModuleManager.js +189 -0
- package/dist/cjs/reciple/classes/{CommandCooldownManager.js → managers/CommandCooldownManager.js} +8 -5
- package/dist/cjs/reciple/classes/{MessageCommandOptionManager.js → managers/MessageCommandOptionManager.js} +0 -0
- package/dist/cjs/reciple/permissions.js +0 -3
- package/dist/cjs/reciple/util.js +22 -1
- package/dist/cjs/reciple/version.js +1 -0
- package/dist/types/index.d.ts +6 -5
- package/dist/types/reciple/classes/RecipleClient.d.ts +21 -54
- package/dist/types/reciple/classes/RecipleConfig.d.ts +6 -0
- package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +53 -15
- package/dist/types/reciple/classes/builders/MessageCommandOptionBuilder.d.ts +10 -0
- package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +29 -14
- package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +20 -0
- package/dist/types/reciple/classes/managers/ClientCommandManager.d.ts +37 -0
- package/dist/types/reciple/classes/managers/ClientModuleManager.d.ts +79 -0
- package/dist/types/reciple/classes/{CommandCooldownManager.d.ts → managers/CommandCooldownManager.d.ts} +21 -2
- package/dist/types/reciple/classes/{MessageCommandOptionManager.d.ts → managers/MessageCommandOptionManager.d.ts} +1 -1
- package/dist/types/reciple/modules.d.ts +36 -4
- package/dist/types/reciple/permissions.d.ts +4 -2
- package/dist/types/reciple/types/builders.d.ts +16 -16
- package/dist/types/reciple/types/commands.d.ts +32 -13
- package/dist/types/reciple/types/paramOptions.d.ts +17 -16
- package/dist/types/reciple/util.d.ts +12 -1
- package/package.json +14 -10
- package/dist/cjs/reciple/registerApplicationCommands.js +0 -50
- package/dist/types/reciple/registerApplicationCommands.d.ts +0 -9
package/dist/cjs/bin.js
CHANGED
|
@@ -12,7 +12,6 @@ const flags_1 = require("./reciple/flags");
|
|
|
12
12
|
const fallout_utility_1 = require("fallout-utility");
|
|
13
13
|
const chalk_1 = __importDefault(require("chalk"));
|
|
14
14
|
require("dotenv/config");
|
|
15
|
-
const discord_js_1 = require("discord.js");
|
|
16
15
|
const path_1 = __importDefault(require("path"));
|
|
17
16
|
const allowedFiles = ['node_modules', 'reciple.yml', 'package.json'];
|
|
18
17
|
const configPath = path_1.default.join(flags_1.cwd, './reciple.yml');
|
|
@@ -34,15 +33,15 @@ const client = new RecipleClient_1.RecipleClient({ config: config, ...config.cli
|
|
|
34
33
|
if (config.fileLogging.clientLogs)
|
|
35
34
|
client.logger.info('Starting Reciple client v' + version_1.rawVersion);
|
|
36
35
|
(async () => {
|
|
37
|
-
|
|
36
|
+
client.addCommandListeners();
|
|
37
|
+
await client.modules.startModulesFromFiles({
|
|
38
|
+
files: await client.modules.getModuleFiles()
|
|
39
|
+
});
|
|
38
40
|
client.on('ready', async () => {
|
|
41
|
+
await client.modules.loadAll(true);
|
|
39
42
|
if (client.isClientLogsEnabled())
|
|
40
43
|
client.logger.warn(`Logged in as ${client.user?.tag || 'Unknown'}!`);
|
|
41
|
-
client.on('cacheSweep', () =>
|
|
42
|
-
client.cooldowns.clean();
|
|
43
|
-
});
|
|
44
|
-
await client.loadModules();
|
|
45
|
-
client.addCommandListeners();
|
|
44
|
+
client.on('cacheSweep', () => client.cooldowns.clean());
|
|
46
45
|
});
|
|
47
46
|
client.login(config.token).catch(err => {
|
|
48
47
|
if (client.isClientLogsEnabled())
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,13 +14,15 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./reciple/classes/CommandCooldownManager"), exports);
|
|
18
|
-
__exportStar(require("./reciple/classes/MessageCommandOptionManager"), exports);
|
|
19
|
-
__exportStar(require("./reciple/classes/RecipleClient"), exports);
|
|
20
|
-
__exportStar(require("./reciple/classes/RecipleConfig"), exports);
|
|
21
17
|
__exportStar(require("./reciple/classes/builders/MessageCommandBuilder"), exports);
|
|
22
18
|
__exportStar(require("./reciple/classes/builders/MessageCommandOptionBuilder"), exports);
|
|
23
19
|
__exportStar(require("./reciple/classes/builders/SlashCommandBuilder"), exports);
|
|
20
|
+
__exportStar(require("./reciple/classes/managers/ApplicationCommandManager"), exports);
|
|
21
|
+
__exportStar(require("./reciple/classes/managers/CommandCooldownManager"), exports);
|
|
22
|
+
__exportStar(require("./reciple/classes/managers/ClientCommandManager"), exports);
|
|
23
|
+
__exportStar(require("./reciple/classes/managers/MessageCommandOptionManager"), exports);
|
|
24
|
+
__exportStar(require("./reciple/classes/RecipleClient"), exports);
|
|
25
|
+
__exportStar(require("./reciple/classes/RecipleConfig"), exports);
|
|
24
26
|
__exportStar(require("./reciple/types/builders"), exports);
|
|
25
27
|
__exportStar(require("./reciple/types/commands"), exports);
|
|
26
28
|
__exportStar(require("./reciple/types/paramOptions"), exports);
|
|
@@ -28,6 +30,5 @@ __exportStar(require("./reciple/flags"), exports);
|
|
|
28
30
|
__exportStar(require("./reciple/logger"), exports);
|
|
29
31
|
__exportStar(require("./reciple/modules"), exports);
|
|
30
32
|
__exportStar(require("./reciple/permissions"), exports);
|
|
31
|
-
__exportStar(require("./reciple/registerApplicationCommands"), exports);
|
|
32
33
|
__exportStar(require("./reciple/util"), exports);
|
|
33
34
|
__exportStar(require("./reciple/version"), exports);
|
|
@@ -6,20 +6,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.RecipleClient = void 0;
|
|
7
7
|
const MessageCommandBuilder_1 = require("./builders/MessageCommandBuilder");
|
|
8
8
|
const SlashCommandBuilder_1 = require("./builders/SlashCommandBuilder");
|
|
9
|
-
const builders_1 = require("../types/builders");
|
|
10
|
-
const registerApplicationCommands_1 = require("../registerApplicationCommands");
|
|
11
9
|
const commands_1 = require("../types/commands");
|
|
10
|
+
const CommandCooldownManager_1 = require("./managers/CommandCooldownManager");
|
|
12
11
|
const permissions_1 = require("../permissions");
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
12
|
+
const MessageCommandOptionManager_1 = require("./managers/MessageCommandOptionManager");
|
|
13
|
+
const ApplicationCommandManager_1 = require("./managers/ApplicationCommandManager");
|
|
14
|
+
const builders_1 = require("../types/builders");
|
|
15
|
+
const ClientCommandManager_1 = require("./managers/ClientCommandManager");
|
|
16
16
|
const RecipleConfig_1 = require("./RecipleConfig");
|
|
17
|
-
const
|
|
17
|
+
const fallout_utility_1 = require("fallout-utility");
|
|
18
18
|
const logger_1 = require("../logger");
|
|
19
19
|
const version_1 = require("../version");
|
|
20
20
|
const flags_1 = require("../flags");
|
|
21
21
|
const path_1 = __importDefault(require("path"));
|
|
22
22
|
const discord_js_1 = require("discord.js");
|
|
23
|
+
const ClientModuleManager_1 = require("./managers/ClientModuleManager");
|
|
23
24
|
class RecipleClient extends discord_js_1.Client {
|
|
24
25
|
/**
|
|
25
26
|
* @param options Client options
|
|
@@ -27,139 +28,28 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
27
28
|
constructor(options) {
|
|
28
29
|
super(options);
|
|
29
30
|
this.config = RecipleConfig_1.RecipleConfig.getDefaultConfig();
|
|
30
|
-
this.commands =
|
|
31
|
-
this.additionalApplicationCommands = [];
|
|
31
|
+
this.commands = new ClientCommandManager_1.ClientCommandManager({ client: this });
|
|
32
32
|
this.cooldowns = new CommandCooldownManager_1.CommandCooldownManager();
|
|
33
|
-
this.modules =
|
|
33
|
+
this.modules = new ClientModuleManager_1.ClientModuleManager({ client: this });
|
|
34
34
|
this.version = version_1.version;
|
|
35
35
|
this.logger = (0, logger_1.createLogger)(!!options.config?.fileLogging.stringifyLoggedJSON, options.config?.fileLogging.debugmode);
|
|
36
|
-
if (!options.config)
|
|
37
|
-
throw new Error('Config is not defined.');
|
|
38
36
|
this.config = { ...this.config, ...(options.config ?? {}) };
|
|
39
37
|
if (this.config.fileLogging.enabled)
|
|
40
38
|
this.logger.logFile(path_1.default.join(flags_1.cwd, this.config.fileLogging.logFilePath ?? 'logs/latest.log'), false);
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Load modules from modules folder
|
|
44
|
-
* @param folders List of folders that contains the modules you want to load
|
|
45
|
-
*/
|
|
46
|
-
async startModules(...folders) {
|
|
47
|
-
folders = (0, discord_js_1.normalizeArray)(folders).map(f => path_1.default.join(flags_1.cwd, f));
|
|
48
|
-
for (const folder of folders) {
|
|
49
|
-
if (this.isClientLogsEnabled())
|
|
50
|
-
this.logger.info(`Loading Modules from ${folder}`);
|
|
51
|
-
const modules = await (0, modules_1.getModules)(this, folder).catch(() => null);
|
|
52
|
-
if (!modules) {
|
|
53
|
-
if (this.isClientLogsEnabled())
|
|
54
|
-
this.logger.error(`Failed to load modules from ${folder}`);
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
this.modules.push(...modules.modules);
|
|
58
|
-
}
|
|
59
|
-
return this;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Execute `onLoad()` from client modules and register application commands if enabled
|
|
63
|
-
*/
|
|
64
|
-
async loadModules() {
|
|
65
|
-
for (const m in this.modules) {
|
|
66
|
-
const index = (m);
|
|
67
|
-
const module_ = this.modules[index];
|
|
68
|
-
try {
|
|
69
|
-
if (typeof module_.script?.onLoad === 'function') {
|
|
70
|
-
await Promise.resolve(module_.script.onLoad(this)).catch(err => {
|
|
71
|
-
if (this.isClientLogsEnabled()) {
|
|
72
|
-
this.logger.error(`Error loading ${module_.info.filename ?? 'unknown module'}:`);
|
|
73
|
-
this.logger.error(err);
|
|
74
|
-
}
|
|
75
|
-
this.modules.splice(index);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
catch (err) {
|
|
80
|
-
if (this.isClientLogsEnabled()) {
|
|
81
|
-
this.logger.error(`Error loading ${module_.info.filename ?? 'unknown module'}:`);
|
|
82
|
-
this.logger.error(err);
|
|
83
|
-
}
|
|
84
|
-
this.modules.splice(index);
|
|
85
|
-
}
|
|
86
|
-
if (module_.script?.commands && Array.isArray(module_.script?.commands)) {
|
|
87
|
-
for (const command of module_.script.commands) {
|
|
88
|
-
this.addCommand(command);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (this.isClientLogsEnabled()) {
|
|
93
|
-
this.logger.info(`${this.modules.length} modules loaded.`);
|
|
94
|
-
this.logger.info(`${this.commands.messageCommands.size} message commands loaded.`);
|
|
95
|
-
this.logger.info(`${this.commands.slashCommands.size} slash commands loaded.`);
|
|
96
|
-
}
|
|
97
|
-
if (this.config.commands.slashCommand.registerCommands) {
|
|
98
|
-
await (0, registerApplicationCommands_1.registerApplicationCommands)({
|
|
99
|
-
client: this,
|
|
100
|
-
commands: [...this.commands.slashCommands.toJSON(), ...this.additionalApplicationCommands],
|
|
101
|
-
guilds: this.config.commands.slashCommand.guilds
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
return this;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Add module
|
|
108
|
-
* @param options Module options
|
|
109
|
-
*/
|
|
110
|
-
async addModule(options) {
|
|
111
|
-
const { script } = options;
|
|
112
|
-
const registerCommands = options.registerApplicationCommands;
|
|
113
|
-
const info = options.moduleInfo;
|
|
114
|
-
this.modules.push({
|
|
115
|
-
script,
|
|
116
|
-
info: {
|
|
117
|
-
filename: undefined,
|
|
118
|
-
versions: typeof script.versions == 'string' ? [script.versions] : script.versions,
|
|
119
|
-
path: undefined,
|
|
120
|
-
...info
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
if (typeof script?.onLoad === 'function')
|
|
124
|
-
await Promise.resolve(script.onLoad(this));
|
|
125
|
-
if (this.isClientLogsEnabled())
|
|
126
|
-
this.logger.info(`${this.modules.length} modules loaded.`);
|
|
127
|
-
for (const command of script.commands ?? []) {
|
|
128
|
-
if (!command.name)
|
|
129
|
-
continue;
|
|
130
|
-
this.addCommand(command);
|
|
131
|
-
}
|
|
132
|
-
if (registerCommands)
|
|
133
|
-
await (0, registerApplicationCommands_1.registerApplicationCommands)({
|
|
134
|
-
client: this,
|
|
135
|
-
commands: [...this.commands.slashCommands.toJSON(), ...this.additionalApplicationCommands],
|
|
136
|
-
guilds: this.config.commands.slashCommand.guilds
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Add slash or message command to client
|
|
141
|
-
* @param command Slash/Message command builder
|
|
142
|
-
*/
|
|
143
|
-
addCommand(command) {
|
|
144
|
-
if (command.type === builders_1.CommandBuilderType.SlashCommand) {
|
|
145
|
-
this.commands.slashCommands.set(command.name, SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command));
|
|
146
|
-
}
|
|
147
|
-
else if (command.type === builders_1.CommandBuilderType.MessageCommand) {
|
|
148
|
-
this.commands.messageCommands.set(command.name, MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command));
|
|
149
|
-
}
|
|
150
|
-
else if (this.isClientLogsEnabled()) {
|
|
151
|
-
this.logger.error(`Unknow command "${typeof command ?? 'unknown'}".`);
|
|
152
|
-
}
|
|
153
|
-
return this;
|
|
39
|
+
this.applicationCommands = new ApplicationCommandManager_1.ApplicationCommandManager(this);
|
|
154
40
|
}
|
|
155
41
|
/**
|
|
156
42
|
* Listed to command executions
|
|
157
43
|
*/
|
|
158
44
|
addCommandListeners() {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
45
|
+
this.on('messageCreate', (message) => {
|
|
46
|
+
if (this.config.commands.messageCommand.enabled)
|
|
47
|
+
this.messageCommandExecute(message);
|
|
48
|
+
});
|
|
49
|
+
this.on('interactionCreate', (interaction) => {
|
|
50
|
+
if (this.config.commands.slashCommand.enabled)
|
|
51
|
+
this.slashCommandExecute(interaction);
|
|
52
|
+
});
|
|
163
53
|
return this;
|
|
164
54
|
}
|
|
165
55
|
/**
|
|
@@ -171,7 +61,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
171
61
|
return;
|
|
172
62
|
if (!this.config.commands.slashCommand.acceptRepliedInteractions && (interaction.replied || interaction.deferred))
|
|
173
63
|
return;
|
|
174
|
-
const command = this.
|
|
64
|
+
const command = this.commands.get(interaction.commandName, builders_1.CommandBuilderType.SlashCommand);
|
|
175
65
|
if (!command)
|
|
176
66
|
return;
|
|
177
67
|
const executeData = {
|
|
@@ -225,7 +115,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
225
115
|
const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.commands.messageCommand.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
|
|
226
116
|
if (!parseCommand || !parseCommand?.command)
|
|
227
117
|
return;
|
|
228
|
-
const command = this.
|
|
118
|
+
const command = this.commands.get(parseCommand.command, builders_1.CommandBuilderType.MessageCommand);
|
|
229
119
|
if (!command)
|
|
230
120
|
return;
|
|
231
121
|
const commandOptions = await (0, MessageCommandBuilder_1.validateMessageCommandOptions)(command, parseCommand);
|
|
@@ -293,19 +183,6 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
293
183
|
getConfigMessage(messageKey, defaultMessage) {
|
|
294
184
|
return this.config.messages[messageKey] ?? defaultMessage ?? messageKey;
|
|
295
185
|
}
|
|
296
|
-
findCommand(command, type) {
|
|
297
|
-
switch (type) {
|
|
298
|
-
case builders_1.CommandBuilderType.SlashCommand:
|
|
299
|
-
return this.commands.slashCommands.get(command);
|
|
300
|
-
case builders_1.CommandBuilderType.MessageCommand:
|
|
301
|
-
return this.commands.messageCommands.get(command.toLowerCase())
|
|
302
|
-
?? (this.config.commands.messageCommand.allowCommandAlias
|
|
303
|
-
? this.commands.messageCommands.find(c => c.aliases.some(a => a == command?.toLowerCase()))
|
|
304
|
-
: undefined);
|
|
305
|
-
default:
|
|
306
|
-
throw new TypeError('Unknown command type');
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
186
|
/**
|
|
310
187
|
* Returns true if client logs is enabled
|
|
311
188
|
*/
|
|
@@ -313,7 +190,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
313
190
|
return !!this.config.fileLogging.clientLogs;
|
|
314
191
|
}
|
|
315
192
|
/**
|
|
316
|
-
* Emits the "recipleReplyError" event
|
|
193
|
+
* Emits the {@link RecipleClientEvents["recipleReplyError"]} event
|
|
317
194
|
* @param error Received Error
|
|
318
195
|
*/
|
|
319
196
|
_replyError(error) {
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.validateMessageCommandOptions = exports.MessageCommandBuilder = void 0;
|
|
4
4
|
const builders_1 = require("../../types/builders");
|
|
5
5
|
const discord_js_1 = require("discord.js");
|
|
6
|
-
const MessageCommandOptionManager_1 = require("../MessageCommandOptionManager");
|
|
6
|
+
const MessageCommandOptionManager_1 = require("../managers/MessageCommandOptionManager");
|
|
7
7
|
const MessageCommandOptionBuilder_1 = require("./MessageCommandOptionBuilder");
|
|
8
8
|
/**
|
|
9
9
|
* Reciple builder for message command
|
|
@@ -116,7 +116,7 @@ class MessageCommandBuilder {
|
|
|
116
116
|
throw new TypeError('option with name "' + option.name + '" already exists.');
|
|
117
117
|
if (this.options.length > 0 && !this.options[this.options.length - 1 < 0 ? 0 : this.options.length - 1].required && option.required)
|
|
118
118
|
throw new TypeError('All required options must be before optional options.');
|
|
119
|
-
this.options
|
|
119
|
+
this.options.push(option);
|
|
120
120
|
return this;
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
@@ -176,23 +176,34 @@ class MessageCommandBuilder {
|
|
|
176
176
|
options: this.options.map(o => o.toJSON()),
|
|
177
177
|
};
|
|
178
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Resolve message command data/builder
|
|
181
|
+
* @param commandData Command data to resolve
|
|
182
|
+
*/
|
|
179
183
|
static resolveMessageCommand(commandData) {
|
|
180
184
|
return this.isMessageCommandBuilder(commandData) ? commandData : new MessageCommandBuilder(commandData);
|
|
181
185
|
}
|
|
182
186
|
/**
|
|
183
187
|
* Is a message command builder
|
|
188
|
+
* @param builder data to check
|
|
184
189
|
*/
|
|
185
190
|
static isMessageCommandBuilder(builder) {
|
|
186
191
|
return builder instanceof MessageCommandBuilder;
|
|
187
192
|
}
|
|
188
193
|
/**
|
|
189
194
|
* Is a message command execute data
|
|
195
|
+
* @param executeData data to check
|
|
190
196
|
*/
|
|
191
197
|
static isMessageCommandExecuteData(executeData) {
|
|
192
198
|
return executeData.builder !== undefined && this.isMessageCommandBuilder(executeData.builder);
|
|
193
199
|
}
|
|
194
200
|
}
|
|
195
201
|
exports.MessageCommandBuilder = MessageCommandBuilder;
|
|
202
|
+
/**
|
|
203
|
+
* Validate message command options
|
|
204
|
+
* @param builder Command builder
|
|
205
|
+
* @param options Parsed command args
|
|
206
|
+
*/
|
|
196
207
|
async function validateMessageCommandOptions(builder, options) {
|
|
197
208
|
const args = options.args || [];
|
|
198
209
|
const required = builder.options.filter(o => o.required);
|
|
@@ -67,5 +67,19 @@ class MessageCommandOptionBuilder {
|
|
|
67
67
|
validator: this.validator,
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Resolves message command option data/builder
|
|
72
|
+
* @param option Option data to resolve
|
|
73
|
+
*/
|
|
74
|
+
static resolveMessageCommandOption(option) {
|
|
75
|
+
return this.isMessageCommandOption(option) ? option : new MessageCommandOptionBuilder(option);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Is a Message command option builder
|
|
79
|
+
* @param builder data to check
|
|
80
|
+
*/
|
|
81
|
+
static isMessageCommandOption(builder) {
|
|
82
|
+
return builder instanceof MessageCommandOptionBuilder;
|
|
83
|
+
}
|
|
70
84
|
}
|
|
71
85
|
exports.MessageCommandOptionBuilder = MessageCommandOptionBuilder;
|
|
@@ -79,6 +79,8 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* Add option builder to command builder
|
|
82
|
+
* @param builder Command/Subcommand builder
|
|
83
|
+
* @param option Option builder
|
|
82
84
|
*/
|
|
83
85
|
static addOption(builder, option) {
|
|
84
86
|
if (option instanceof discord_js_1.SlashCommandAttachmentOption) {
|
|
@@ -120,6 +122,7 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
|
120
122
|
}
|
|
121
123
|
/**
|
|
122
124
|
* Resolve option data
|
|
125
|
+
* @param option Option dara to resolve
|
|
123
126
|
*/
|
|
124
127
|
static resolveOption(option) {
|
|
125
128
|
let builder;
|
|
@@ -199,17 +202,23 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
|
199
202
|
.setNameLocalizations(option.nameLocalizations ?? null)
|
|
200
203
|
.setDescriptionLocalizations(option.descriptionLocalizations ?? null);
|
|
201
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* Resolve slash command data/builder
|
|
207
|
+
* @param commandData Command data to resolve
|
|
208
|
+
*/
|
|
202
209
|
static resolveSlashCommand(commandData) {
|
|
203
210
|
return this.isSlashCommandBuilder(commandData) ? commandData : new SlashCommandBuilder(commandData);
|
|
204
211
|
}
|
|
205
212
|
/**
|
|
206
213
|
* Is a slash command builder
|
|
214
|
+
* @param builder data to check
|
|
207
215
|
*/
|
|
208
216
|
static isSlashCommandBuilder(builder) {
|
|
209
217
|
return builder instanceof SlashCommandBuilder;
|
|
210
218
|
}
|
|
211
219
|
/**
|
|
212
220
|
* Is a slash command execute data
|
|
221
|
+
* @param executeData data to check
|
|
213
222
|
*/
|
|
214
223
|
static isSlashCommandExecuteData(executeData) {
|
|
215
224
|
return executeData.builder !== undefined && this.isSlashCommandBuilder(executeData.builder);
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApplicationCommandManager = void 0;
|
|
4
|
+
const discord_js_1 = require("discord.js");
|
|
5
|
+
const SlashCommandBuilder_1 = require("../builders/SlashCommandBuilder");
|
|
6
|
+
class ApplicationCommandManager {
|
|
7
|
+
constructor(client) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
}
|
|
10
|
+
get commands() { return this.client.application?.commands; }
|
|
11
|
+
async set(commands, guilds) {
|
|
12
|
+
if (!this.client.isReady())
|
|
13
|
+
throw new Error('Client is not ready');
|
|
14
|
+
if (guilds && guilds.length > 1) {
|
|
15
|
+
for (const guild of guilds) {
|
|
16
|
+
await this.set(commands, [guild]);
|
|
17
|
+
}
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
let guild = guilds?.shift();
|
|
21
|
+
guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
|
|
22
|
+
if (!guild) {
|
|
23
|
+
this.client.application.commands.set(commands);
|
|
24
|
+
if (this.client.isClientLogsEnabled())
|
|
25
|
+
this.client.logger.log(`Registered ${this.client.commands.applicationCommandsSize} application command(s) globally...`);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this.client.application.commands.set(commands, guild);
|
|
29
|
+
if (this.client.isClientLogsEnabled())
|
|
30
|
+
this.client.logger.log(`Registered ${this.client.commands.applicationCommandsSize} application command(s) to guild ${guild}...`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async add(command, guilds) {
|
|
34
|
+
if (!this.client.isReady())
|
|
35
|
+
throw new Error('Client is not ready');
|
|
36
|
+
if (!command)
|
|
37
|
+
throw new Error('Command is undefined');
|
|
38
|
+
if (guilds && guilds.length > 1) {
|
|
39
|
+
for (const guild of guilds) {
|
|
40
|
+
await this.add(command, [guild]);
|
|
41
|
+
}
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
let guild = guilds?.shift();
|
|
45
|
+
guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
|
|
46
|
+
if (!guild) {
|
|
47
|
+
this.client.application.commands.create(command);
|
|
48
|
+
if (this.client.isClientLogsEnabled())
|
|
49
|
+
this.client.logger.log(`Created application command '${command.name}' globally`);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
this.client.application.commands.create(command, guild);
|
|
53
|
+
if (this.client.isClientLogsEnabled())
|
|
54
|
+
this.client.logger.log(`Created application command '${command.name}' to guild ${guild}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async remove(command, guilds) {
|
|
58
|
+
if (!this.client.isReady())
|
|
59
|
+
throw new Error('Client is not ready');
|
|
60
|
+
if (!command)
|
|
61
|
+
throw new Error('Command is undefined');
|
|
62
|
+
if (guilds && guilds.length > 1) {
|
|
63
|
+
for (const guild of guilds) {
|
|
64
|
+
await this.remove(command, [guild]);
|
|
65
|
+
}
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
let guild = guilds?.shift();
|
|
69
|
+
guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
|
|
70
|
+
if (!guild) {
|
|
71
|
+
this.client.application.commands.delete(command);
|
|
72
|
+
if (this.client.isClientLogsEnabled())
|
|
73
|
+
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' globally`);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
this.client.application.commands.delete(command, guild);
|
|
77
|
+
if (this.client.isClientLogsEnabled())
|
|
78
|
+
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' from guild ${guild}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async edit(command, newCommand, guilds) {
|
|
82
|
+
if (!this.client.isReady())
|
|
83
|
+
throw new Error('Client is not ready');
|
|
84
|
+
if (!command)
|
|
85
|
+
throw new Error('Command is undefined');
|
|
86
|
+
if (guilds && guilds.length > 1) {
|
|
87
|
+
for (const guild of guilds) {
|
|
88
|
+
await this.edit(command, newCommand, [guild]);
|
|
89
|
+
}
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
let guild = guilds?.shift();
|
|
93
|
+
guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
|
|
94
|
+
if (!guild) {
|
|
95
|
+
this.client.application.commands.edit(command, newCommand);
|
|
96
|
+
if (this.client.isClientLogsEnabled())
|
|
97
|
+
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' globally`);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
this.client.application.commands.edit(command, newCommand, guild);
|
|
101
|
+
if (this.client.isClientLogsEnabled())
|
|
102
|
+
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' from guild ${guild}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
get(command, guild) {
|
|
106
|
+
const commands = guild ? this.client.guilds.resolve(guild)?.commands.cache : this.client.application?.commands.cache;
|
|
107
|
+
if (!commands)
|
|
108
|
+
throw new Error('Guild not found in cache');
|
|
109
|
+
return commands.find(cmd => typeof command === 'string'
|
|
110
|
+
? (cmd.id === command || cmd.name === command)
|
|
111
|
+
: (cmd.name === command.name || (command instanceof discord_js_1.ApplicationCommand && cmd.id === command.id)));
|
|
112
|
+
}
|
|
113
|
+
async fetch(commandId, guild) {
|
|
114
|
+
const manager = guild ? this.client.guilds.resolve(guild)?.commands : this.client.application?.commands;
|
|
115
|
+
if (!manager)
|
|
116
|
+
throw new Error('Guild not found in cache');
|
|
117
|
+
return manager.fetch(commandId);
|
|
118
|
+
}
|
|
119
|
+
parseCommands(commands, setPermissions = true) {
|
|
120
|
+
return commands.map(cmd => {
|
|
121
|
+
if (cmd?.toJSON === undefined)
|
|
122
|
+
return (cmd);
|
|
123
|
+
if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandBuilder(cmd) && this.client.config.commands.slashCommand.setRequiredPermissions) {
|
|
124
|
+
const permissions = (setPermissions || this.client.config.commands.slashCommand.permissions.enabled)
|
|
125
|
+
? this.client.config.commands.slashCommand.permissions.commands.find(cmd_ => cmd_.command.toLowerCase() === cmd.name.toLowerCase())?.permissions
|
|
126
|
+
: undefined;
|
|
127
|
+
if (permissions) {
|
|
128
|
+
cmd.setRequiredMemberPermissions(...permissions);
|
|
129
|
+
if (this.client.isClientLogsEnabled())
|
|
130
|
+
this.client.logger.debug(`Set required permissions for ${cmd.name}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return cmd.toJSON();
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.ApplicationCommandManager = ApplicationCommandManager;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientCommandManager = void 0;
|
|
4
|
+
const discord_js_1 = require("discord.js");
|
|
5
|
+
const builders_1 = require("../../types/builders");
|
|
6
|
+
const MessageCommandBuilder_1 = require("../builders/MessageCommandBuilder");
|
|
7
|
+
const SlashCommandBuilder_1 = require("../builders/SlashCommandBuilder");
|
|
8
|
+
class ClientCommandManager {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.slashCommands = new discord_js_1.Collection();
|
|
11
|
+
this.messageCommands = new discord_js_1.Collection();
|
|
12
|
+
this.additionalApplicationCommands = [];
|
|
13
|
+
this.client = options.client;
|
|
14
|
+
options.slashCommands?.forEach(e => this.slashCommands.set(e.name, SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(e)));
|
|
15
|
+
options.messageCommands?.forEach(e => this.messageCommands.set(e.name, MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(e)));
|
|
16
|
+
}
|
|
17
|
+
get applicationCommandsSize() { return this.client.commands.slashCommands.size + this.client.commands.additionalApplicationCommands.length; }
|
|
18
|
+
/**
|
|
19
|
+
* Add command to command manager
|
|
20
|
+
* @param commands Any command data or builder
|
|
21
|
+
*/
|
|
22
|
+
add(...commands) {
|
|
23
|
+
for (const command of (0, discord_js_1.normalizeArray)(commands)) {
|
|
24
|
+
if (command.type === builders_1.CommandBuilderType.SlashCommand) {
|
|
25
|
+
this.slashCommands.set(command.name, SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command));
|
|
26
|
+
}
|
|
27
|
+
else if (command.type === builders_1.CommandBuilderType.MessageCommand) {
|
|
28
|
+
this.messageCommands.set(command.name, MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
get(command, type) {
|
|
34
|
+
switch (type) {
|
|
35
|
+
case builders_1.CommandBuilderType.SlashCommand:
|
|
36
|
+
return this.slashCommands.get(command);
|
|
37
|
+
case builders_1.CommandBuilderType.MessageCommand:
|
|
38
|
+
return this.messageCommands.get(command.toLowerCase())
|
|
39
|
+
?? (this.client.config.commands.messageCommand.allowCommandAlias
|
|
40
|
+
? this.messageCommands.find(c => c.aliases.some(a => a == command?.toLowerCase()))
|
|
41
|
+
: undefined);
|
|
42
|
+
default:
|
|
43
|
+
throw new TypeError('Unknown command type');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Register application commands
|
|
48
|
+
* @param guilds Register application commands to guilds
|
|
49
|
+
*/
|
|
50
|
+
async registerApplicationCommands(...guilds) {
|
|
51
|
+
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
52
|
+
guilds = guilds.length
|
|
53
|
+
? guilds
|
|
54
|
+
: (0, discord_js_1.normalizeArray)([this.client.config.commands.slashCommand.guilds]);
|
|
55
|
+
if (this.client.isClientLogsEnabled())
|
|
56
|
+
this.client.logger.log(`Regestering ${this.applicationCommandsSize} application command(s) ${!guilds.length ? 'globaly' : 'to ' + guilds.length + ' guilds'}...`);
|
|
57
|
+
await this.client.applicationCommands.set([...this.slashCommands.toJSON(), ...this.additionalApplicationCommands], guilds);
|
|
58
|
+
this.client.emit('RegisterApplicationCommands');
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.ClientCommandManager = ClientCommandManager;
|