reciple 6.0.0-dev.2 → 6.0.0-dev.21
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/lib/bin.mjs +65 -0
- package/dist/lib/esm.mjs +1 -0
- package/dist/{cjs → lib}/index.js +18 -17
- package/dist/{cjs → lib}/reciple/classes/RecipleClient.js +19 -22
- package/dist/{cjs → lib}/reciple/classes/RecipleConfig.js +10 -10
- package/dist/lib/reciple/classes/RecipleModule.js +94 -0
- package/dist/lib/reciple/classes/builders/MessageCommandBuilder.js +325 -0
- package/dist/{cjs → lib}/reciple/classes/builders/MessageCommandOptionBuilder.js +35 -13
- package/dist/{cjs → lib}/reciple/classes/builders/SlashCommandBuilder.js +42 -15
- package/dist/{cjs → lib}/reciple/classes/managers/ApplicationCommandManager.js +64 -23
- package/dist/{cjs → lib}/reciple/classes/managers/CommandCooldownManager.js +0 -0
- package/dist/{cjs/reciple/classes/managers/ClientCommandManager.js → lib/reciple/classes/managers/CommandManager.js} +14 -15
- package/dist/{cjs → lib}/reciple/classes/managers/MessageCommandOptionManager.js +0 -0
- package/dist/lib/reciple/classes/managers/ModuleManager.js +179 -0
- package/dist/{cjs → lib}/reciple/flags.js +2 -2
- package/dist/{cjs → lib}/reciple/permissions.js +0 -0
- package/dist/lib/reciple/types/builders.js +11 -0
- package/dist/{cjs → lib}/reciple/types/commands.js +6 -6
- package/dist/{cjs → lib}/reciple/types/paramOptions.js +0 -0
- package/dist/{cjs/reciple/logger.js → lib/reciple/util.js} +33 -2
- package/dist/{cjs → lib}/reciple/version.js +0 -1
- package/dist/types/{bin.d.ts → bin.d.mts} +0 -0
- package/dist/types/esm.d.mts +1 -0
- package/dist/types/index.d.ts +18 -17
- package/dist/types/reciple/classes/RecipleClient.d.ts +7 -5
- package/dist/types/reciple/classes/RecipleConfig.d.ts +3 -2
- package/dist/types/reciple/classes/RecipleModule.d.ts +56 -0
- package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +60 -26
- package/dist/types/reciple/classes/builders/MessageCommandOptionBuilder.d.ts +15 -7
- package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +20 -10
- package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +43 -10
- package/dist/types/reciple/classes/managers/CommandCooldownManager.d.ts +2 -2
- package/dist/types/reciple/classes/managers/{ClientCommandManager.d.ts → CommandManager.d.ts} +6 -7
- package/dist/types/reciple/classes/managers/ModuleManager.d.ts +49 -0
- package/dist/types/reciple/types/builders.d.ts +8 -8
- package/dist/types/reciple/types/commands.d.ts +16 -16
- package/dist/types/reciple/types/paramOptions.d.ts +79 -18
- package/dist/types/reciple/util.d.ts +11 -0
- package/package.json +28 -21
- package/resource/reciple.yml +25 -22
- package/dist/cjs/bin.js +0 -50
- package/dist/cjs/reciple/classes/builders/MessageCommandBuilder.js +0 -242
- package/dist/cjs/reciple/classes/managers/ClientModuleManager.js +0 -193
- package/dist/cjs/reciple/types/builders.js +0 -11
- package/dist/cjs/reciple/util.js +0 -32
- package/dist/types/reciple/classes/managers/ClientModuleManager.d.ts +0 -79
- package/dist/types/reciple/logger.d.ts +0 -8
- package/docs/README.md +0 -1
|
@@ -8,122 +8,163 @@ class ApplicationCommandManager {
|
|
|
8
8
|
this.client = client;
|
|
9
9
|
}
|
|
10
10
|
get commands() {
|
|
11
|
-
return this.client.
|
|
11
|
+
return [...this.client.commands.additionalApplicationCommands, ...this.client.commands.slashCommands.toJSON()];
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
get size() {
|
|
14
|
+
return this.commands.length;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Sets application commands globally or in guilds
|
|
18
|
+
* @param commands Application commands
|
|
19
|
+
* @param guilds set only to guilds
|
|
20
|
+
*/
|
|
21
|
+
async set(commands, ...guilds) {
|
|
22
|
+
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
14
23
|
if (!this.client.isReady())
|
|
15
24
|
throw new Error('Client is not ready');
|
|
16
25
|
if (guilds && guilds.length > 1) {
|
|
17
26
|
for (const guild of guilds) {
|
|
18
|
-
await this.set(commands,
|
|
27
|
+
await this.set(commands, guild);
|
|
19
28
|
}
|
|
20
29
|
return;
|
|
21
30
|
}
|
|
22
31
|
let guild = guilds?.shift();
|
|
23
32
|
guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
|
|
24
33
|
if (!guild) {
|
|
25
|
-
this.client.application.commands.set(commands);
|
|
34
|
+
await this.client.application.commands.set(commands);
|
|
26
35
|
if (!this.client.isClientLogsSilent)
|
|
27
|
-
this.client.logger.log(`Registered ${this.client.
|
|
36
|
+
this.client.logger.log(`Registered ${this.client.applicationCommands.size} application command(s) globally...`);
|
|
28
37
|
}
|
|
29
38
|
else {
|
|
30
|
-
this.client.application.commands.set(commands, guild);
|
|
39
|
+
await this.client.application.commands.set(commands, guild);
|
|
31
40
|
if (!this.client.isClientLogsSilent)
|
|
32
|
-
this.client.logger.log(`Registered ${this.client.
|
|
41
|
+
this.client.logger.log(`Registered ${this.client.applicationCommands.size} application command(s) to guild ${guild}`);
|
|
33
42
|
}
|
|
34
43
|
}
|
|
35
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Add command globally or in guilds
|
|
46
|
+
* @param command Application command
|
|
47
|
+
* @param guilds add only in guilds
|
|
48
|
+
*/
|
|
49
|
+
async add(command, ...guilds) {
|
|
50
|
+
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
36
51
|
if (!this.client.isReady())
|
|
37
52
|
throw new Error('Client is not ready');
|
|
38
53
|
if (!command)
|
|
39
54
|
throw new Error('Command is undefined');
|
|
40
55
|
if (guilds && guilds.length > 1) {
|
|
41
56
|
for (const guild of guilds) {
|
|
42
|
-
await this.add(command,
|
|
57
|
+
await this.add(command, guild);
|
|
43
58
|
}
|
|
44
59
|
return;
|
|
45
60
|
}
|
|
46
61
|
let guild = guilds?.shift();
|
|
47
62
|
guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
|
|
48
63
|
if (!guild) {
|
|
49
|
-
this.client.application.commands.create(command);
|
|
64
|
+
await this.client.application.commands.create(command);
|
|
50
65
|
if (!this.client.isClientLogsSilent)
|
|
51
66
|
this.client.logger.log(`Created application command '${command.name}' globally`);
|
|
52
67
|
}
|
|
53
68
|
else {
|
|
54
|
-
this.client.application.commands.create(command, guild);
|
|
69
|
+
await this.client.application.commands.create(command, guild);
|
|
55
70
|
if (!this.client.isClientLogsSilent)
|
|
56
71
|
this.client.logger.log(`Created application command '${command.name}' to guild ${guild}`);
|
|
57
72
|
}
|
|
58
73
|
}
|
|
59
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Remove application command globally or in guilds
|
|
76
|
+
* @param command id of application commmand or ApplicationCommand class
|
|
77
|
+
* @param guilds Remove from guilds
|
|
78
|
+
*/
|
|
79
|
+
async remove(command, ...guilds) {
|
|
80
|
+
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
60
81
|
if (!this.client.isReady())
|
|
61
82
|
throw new Error('Client is not ready');
|
|
62
83
|
if (!command)
|
|
63
84
|
throw new Error('Command is undefined');
|
|
64
85
|
if (guilds && guilds.length > 1) {
|
|
65
86
|
for (const guild of guilds) {
|
|
66
|
-
await this.remove(command,
|
|
87
|
+
await this.remove(command, guild);
|
|
67
88
|
}
|
|
68
89
|
return;
|
|
69
90
|
}
|
|
70
91
|
let guild = guilds?.shift();
|
|
71
92
|
guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
|
|
72
93
|
if (!guild) {
|
|
73
|
-
this.client.application.commands.delete(command);
|
|
94
|
+
await this.client.application.commands.delete(command);
|
|
74
95
|
if (!this.client.isClientLogsSilent)
|
|
75
96
|
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' globally`);
|
|
76
97
|
}
|
|
77
98
|
else {
|
|
78
|
-
this.client.application.commands.delete(command, guild);
|
|
99
|
+
await this.client.application.commands.delete(command, guild);
|
|
79
100
|
if (!this.client.isClientLogsSilent)
|
|
80
101
|
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' from guild ${guild}`);
|
|
81
102
|
}
|
|
82
103
|
}
|
|
83
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Edit application command globally or in guilds
|
|
106
|
+
* @param command id of application command or ApplicationCommand class
|
|
107
|
+
* @param newCommand new application command data
|
|
108
|
+
* @param guilds Edit only from guilds
|
|
109
|
+
*/
|
|
110
|
+
async edit(command, newCommand, ...guilds) {
|
|
111
|
+
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
84
112
|
if (!this.client.isReady())
|
|
85
113
|
throw new Error('Client is not ready');
|
|
86
114
|
if (!command)
|
|
87
115
|
throw new Error('Command is undefined');
|
|
88
116
|
if (guilds && guilds.length > 1) {
|
|
89
117
|
for (const guild of guilds) {
|
|
90
|
-
await this.edit(command, newCommand,
|
|
118
|
+
await this.edit(command, newCommand, guild);
|
|
91
119
|
}
|
|
92
120
|
return;
|
|
93
121
|
}
|
|
94
122
|
let guild = guilds?.shift();
|
|
95
123
|
guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
|
|
96
124
|
if (!guild) {
|
|
97
|
-
this.client.application.commands.edit(command, newCommand);
|
|
125
|
+
await this.client.application.commands.edit(command, newCommand);
|
|
98
126
|
if (!this.client.isClientLogsSilent)
|
|
99
127
|
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' globally`);
|
|
100
128
|
}
|
|
101
129
|
else {
|
|
102
|
-
this.client.application.commands.edit(command, newCommand, guild);
|
|
130
|
+
await this.client.application.commands.edit(command, newCommand, guild);
|
|
103
131
|
if (!this.client.isClientLogsSilent)
|
|
104
132
|
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' from guild ${guild}`);
|
|
105
133
|
}
|
|
106
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Get application command from cache by application command data, builder, id, or name globally or from guid
|
|
137
|
+
* @param command application command data, builder, id, or name
|
|
138
|
+
* @param guild get command from guild
|
|
139
|
+
*/
|
|
107
140
|
get(command, guild) {
|
|
108
141
|
const commands = guild ? this.client.guilds.resolve(guild)?.commands.cache : this.client.application?.commands.cache;
|
|
109
142
|
if (!commands)
|
|
110
143
|
throw new Error('Guild not found in cache');
|
|
111
|
-
return commands.find(cmd => typeof command === 'string' ? cmd.id === command || cmd.name === command : cmd.name === command.name || (command instanceof discord_js_1.ApplicationCommand && cmd.id === command.id));
|
|
144
|
+
return commands.find(cmd => (typeof command === 'string' ? cmd.id === command || cmd.name === command : cmd.name === command.name || (command instanceof discord_js_1.ApplicationCommand && cmd.id === command.id)));
|
|
112
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Fetch application command by id globally or from guild
|
|
148
|
+
* @param commandId command id
|
|
149
|
+
* @param guild fetch from guild
|
|
150
|
+
*/
|
|
113
151
|
async fetch(commandId, guild) {
|
|
114
152
|
const manager = guild ? this.client.guilds.resolve(guild)?.commands : this.client.application?.commands;
|
|
115
153
|
if (!manager)
|
|
116
154
|
throw new Error('Guild not found in cache');
|
|
117
155
|
return manager.fetch(commandId);
|
|
118
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Parse application command builders to command data
|
|
159
|
+
* @param commands Application command builders
|
|
160
|
+
* @param setPermissions set slash commands permissions
|
|
161
|
+
*/
|
|
119
162
|
parseCommands(commands, setPermissions = true) {
|
|
120
163
|
return commands.map(cmd => {
|
|
121
164
|
if (cmd?.toJSON === undefined)
|
|
122
165
|
return cmd;
|
|
123
166
|
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;
|
|
167
|
+
const permissions = setPermissions || this.client.config.commands.slashCommand.permissions.enabled ? this.client.config.commands.slashCommand.permissions.commands.find(cmd_ => cmd_.command.toLowerCase() === cmd.name.toLowerCase())?.permissions : undefined;
|
|
127
168
|
if (permissions) {
|
|
128
169
|
cmd.setRequiredMemberPermissions(...permissions);
|
|
129
170
|
if (!this.client.isClientLogsSilent)
|
|
File without changes
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.CommandManager = void 0;
|
|
4
4
|
const discord_js_1 = require("discord.js");
|
|
5
5
|
const builders_1 = require("../../types/builders");
|
|
6
6
|
const MessageCommandBuilder_1 = require("../builders/MessageCommandBuilder");
|
|
7
7
|
const SlashCommandBuilder_1 = require("../builders/SlashCommandBuilder");
|
|
8
|
-
class
|
|
8
|
+
class CommandManager {
|
|
9
9
|
constructor(options) {
|
|
10
10
|
this.slashCommands = new discord_js_1.Collection();
|
|
11
11
|
this.messageCommands = new discord_js_1.Collection();
|
|
@@ -14,31 +14,30 @@ class ClientCommandManager {
|
|
|
14
14
|
options.slashCommands?.forEach(e => this.slashCommands.set(e.name, SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(e)));
|
|
15
15
|
options.messageCommands?.forEach(e => this.messageCommands.set(e.name, MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(e)));
|
|
16
16
|
}
|
|
17
|
-
get applicationCommandsSize() {
|
|
18
|
-
return this.client.commands.slashCommands.size + this.client.commands.additionalApplicationCommands.length;
|
|
19
|
-
}
|
|
20
17
|
/**
|
|
21
18
|
* Add command to command manager
|
|
22
19
|
* @param commands Any command data or builder
|
|
23
20
|
*/
|
|
24
21
|
add(...commands) {
|
|
25
22
|
for (const command of (0, discord_js_1.normalizeArray)(commands)) {
|
|
26
|
-
if (command.type === builders_1.
|
|
23
|
+
if (command.type === builders_1.CommandType.SlashCommand) {
|
|
27
24
|
this.slashCommands.set(command.name, SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command));
|
|
28
25
|
}
|
|
29
|
-
else if (command.type === builders_1.
|
|
26
|
+
else if (command.type === builders_1.CommandType.MessageCommand) {
|
|
30
27
|
this.messageCommands.set(command.name, MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command));
|
|
31
28
|
}
|
|
29
|
+
else {
|
|
30
|
+
throw new Error(`Unknown reciple command type`);
|
|
31
|
+
}
|
|
32
32
|
}
|
|
33
33
|
return this;
|
|
34
34
|
}
|
|
35
35
|
get(command, type) {
|
|
36
36
|
switch (type) {
|
|
37
|
-
case builders_1.
|
|
37
|
+
case builders_1.CommandType.SlashCommand:
|
|
38
38
|
return this.slashCommands.get(command);
|
|
39
|
-
case builders_1.
|
|
40
|
-
return
|
|
41
|
-
(this.client.config.commands.messageCommand.allowCommandAlias ? this.messageCommands.find(c => c.aliases.some(a => a == command?.toLowerCase())) : undefined));
|
|
39
|
+
case builders_1.CommandType.MessageCommand:
|
|
40
|
+
return this.messageCommands.get(command.toLowerCase()) ?? (this.client.config.commands.messageCommand.allowCommandAlias ? this.messageCommands.find(c => c.aliases.some(a => a == command?.toLowerCase())) : undefined);
|
|
42
41
|
default:
|
|
43
42
|
throw new TypeError('Unknown command type');
|
|
44
43
|
}
|
|
@@ -51,10 +50,10 @@ class ClientCommandManager {
|
|
|
51
50
|
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
52
51
|
guilds = guilds.length ? guilds : (0, discord_js_1.normalizeArray)([this.client.config.commands.slashCommand.guilds]);
|
|
53
52
|
if (!this.client.isClientLogsSilent)
|
|
54
|
-
this.client.logger.log(`Regestering ${this.
|
|
55
|
-
await this.client.applicationCommands.set([...this.
|
|
56
|
-
this.client.emit('
|
|
53
|
+
this.client.logger.log(`Regestering ${this.client.applicationCommands.size} application command(s) ${!guilds.length ? 'globaly' : 'to ' + guilds.length + ' guilds'}...`);
|
|
54
|
+
await this.client.applicationCommands.set([...this.client.applicationCommands.commands], guilds);
|
|
55
|
+
this.client.emit('recipleRegisterApplicationCommands');
|
|
57
56
|
return this;
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
|
-
exports.
|
|
59
|
+
exports.CommandManager = CommandManager;
|
|
File without changes
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ModuleManager = void 0;
|
|
7
|
+
const discord_js_1 = require("discord.js");
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const util_1 = require("util");
|
|
10
|
+
const wildcard_match_1 = __importDefault(require("wildcard-match"));
|
|
11
|
+
const RecipleModule_1 = require("../RecipleModule");
|
|
12
|
+
const util_2 = require("../../util");
|
|
13
|
+
class ModuleManager {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.modules = new discord_js_1.Collection();
|
|
16
|
+
this.client = options.client;
|
|
17
|
+
options.modules?.forEach(m => (m instanceof RecipleModule_1.RecipleModule ? m : new RecipleModule_1.RecipleModule({ client: this.client, script: m })));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Start modules
|
|
21
|
+
* @param options start modules options
|
|
22
|
+
* @returns started modules
|
|
23
|
+
*/
|
|
24
|
+
async startModules(options) {
|
|
25
|
+
const startedModules = [];
|
|
26
|
+
for (const module_ of options.modules) {
|
|
27
|
+
if (!this.client.isClientLogsSilent)
|
|
28
|
+
this.client.logger.log(`Starting module '${module_}'`);
|
|
29
|
+
try {
|
|
30
|
+
let error;
|
|
31
|
+
const start = await module_.start().catch(err => {
|
|
32
|
+
error = err;
|
|
33
|
+
return false;
|
|
34
|
+
});
|
|
35
|
+
if (error)
|
|
36
|
+
throw new Error(`An error occured while loading module '${module_}': \n${(0, util_1.inspect)(error)}`);
|
|
37
|
+
if (!start) {
|
|
38
|
+
if (!this.client.isClientLogsSilent)
|
|
39
|
+
this.client.logger.error(`Module '${module_}' returned false onStart`);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (options.addToModulesCollection !== false)
|
|
43
|
+
this.modules.set(module_.id, module_);
|
|
44
|
+
startedModules.push(module_);
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
if (options?.ignoreErrors === false)
|
|
48
|
+
throw err;
|
|
49
|
+
if (!this.client.isClientLogsSilent)
|
|
50
|
+
this.client.logger.error(`Failed to start module '${module_}': `, err);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return startedModules;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Load modules
|
|
57
|
+
* @param options load modules options
|
|
58
|
+
* @returns loaded modules
|
|
59
|
+
*/
|
|
60
|
+
async loadModules(options) {
|
|
61
|
+
const loadedModules = [];
|
|
62
|
+
for (const module_ of options?.modules ?? this.modules.toJSON()) {
|
|
63
|
+
try {
|
|
64
|
+
await module_.load().catch(err => {
|
|
65
|
+
throw err;
|
|
66
|
+
});
|
|
67
|
+
if (options?.resolveCommands !== false) {
|
|
68
|
+
module_.resolveCommands();
|
|
69
|
+
this.client.commands.add(module_.commands);
|
|
70
|
+
}
|
|
71
|
+
loadedModules.push(module_);
|
|
72
|
+
if (!this.client.isClientLogsSilent)
|
|
73
|
+
this.client.logger.log(`Loaded module '${module_}'`);
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
if (options?.ignoreErrors === false)
|
|
77
|
+
throw err;
|
|
78
|
+
if (!this.client.isClientLogsSilent)
|
|
79
|
+
this.client.logger.error(`Failed to load module '${module_}': `, err);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return loadedModules;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Unload modules
|
|
86
|
+
* @param options unload modules options
|
|
87
|
+
* @returns unloaded modules
|
|
88
|
+
*/
|
|
89
|
+
async unloadModules(options) {
|
|
90
|
+
const unloadedModules = [];
|
|
91
|
+
for (const module_ of options?.modules ?? this.modules.toJSON()) {
|
|
92
|
+
try {
|
|
93
|
+
await module_.unload().catch(err => {
|
|
94
|
+
throw err;
|
|
95
|
+
});
|
|
96
|
+
unloadedModules.push(module_);
|
|
97
|
+
if (!this.client.isClientLogsSilent)
|
|
98
|
+
this.client.logger.log(`Unloaded module '${module_}'`);
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
if (options?.ignoreErrors === false)
|
|
102
|
+
throw err;
|
|
103
|
+
if (!this.client.isClientLogsSilent)
|
|
104
|
+
this.client.logger.error(`Failed to unLoad module '${module_}': `, err);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return unloadedModules;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Resolve modules from file paths
|
|
111
|
+
* @param options resolve module files options
|
|
112
|
+
* @returns resolved modules
|
|
113
|
+
*/
|
|
114
|
+
async resolveModuleFiles(options) {
|
|
115
|
+
const modules = [];
|
|
116
|
+
for (const file of options.files) {
|
|
117
|
+
try {
|
|
118
|
+
const resolveFile = await import((util_2.path.isAbsolute(file) ? 'file://' : '') + file);
|
|
119
|
+
let script = resolveFile instanceof RecipleModule_1.RecipleModule || ModuleManager.validateScript(resolveFile) ? resolveFile : resolveFile?.default?.default instanceof RecipleModule_1.RecipleModule || ModuleManager.validateScript(resolveFile?.default?.default) ? resolveFile.default.default : resolveFile?.default;
|
|
120
|
+
if (script instanceof RecipleModule_1.RecipleModule) {
|
|
121
|
+
modules.push(script);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (!ModuleManager.validateScript(script))
|
|
125
|
+
throw new Error(`Invalid module script: ${file}`);
|
|
126
|
+
modules.push(new RecipleModule_1.RecipleModule({
|
|
127
|
+
client: this.client,
|
|
128
|
+
script,
|
|
129
|
+
filePath: file,
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
catch (err) {
|
|
133
|
+
if (options.ignoreErrors === false)
|
|
134
|
+
throw err;
|
|
135
|
+
if (!this.client.isClientLogsSilent)
|
|
136
|
+
this.client.logger.error(`Can't resolve module from: ${file}`, err);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return modules;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Validate module script
|
|
143
|
+
* @param script module script
|
|
144
|
+
* @returns `true` if script is valid
|
|
145
|
+
*/
|
|
146
|
+
static validateScript(script) {
|
|
147
|
+
const s = script;
|
|
148
|
+
if (typeof s !== 'object')
|
|
149
|
+
return false;
|
|
150
|
+
if (typeof s.versions !== 'string' && !Array.isArray(s.versions))
|
|
151
|
+
return false;
|
|
152
|
+
if (typeof s.onStart !== 'function')
|
|
153
|
+
return false;
|
|
154
|
+
if (s.onLoad && typeof s.onLoad !== 'function')
|
|
155
|
+
return false;
|
|
156
|
+
if (s.onUnload && typeof s.onUnload !== 'function')
|
|
157
|
+
return false;
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Get module file paths from folders
|
|
162
|
+
* @param options get module paths options
|
|
163
|
+
* @returns module paths
|
|
164
|
+
*/
|
|
165
|
+
async getModulePaths(options) {
|
|
166
|
+
const modules = [];
|
|
167
|
+
for (const dir of options?.folders ?? (0, discord_js_1.normalizeArray)([this.client.config.modulesFolder])) {
|
|
168
|
+
if (!(0, fs_1.existsSync)(dir))
|
|
169
|
+
(0, fs_1.mkdirSync)(dir, { recursive: true });
|
|
170
|
+
if (!(0, fs_1.lstatSync)(dir).isDirectory())
|
|
171
|
+
continue;
|
|
172
|
+
modules.push(...(0, fs_1.readdirSync)(dir)
|
|
173
|
+
.map(file => util_2.path.join(!dir.startsWith('/') ? this.client.cwd : '', dir, file))
|
|
174
|
+
.filter(file => (options?.filter ? options.filter(file) : file.endsWith('.js'))));
|
|
175
|
+
}
|
|
176
|
+
return modules.filter(file => !(options?.ignoredFiles ?? this.client.config.ignoredFiles).some(ignored => (0, wildcard_match_1.default)(ignored)(util_2.path.basename(file))));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
exports.ModuleManager = ModuleManager;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cwd = exports.token = exports.flags = exports.commander = void 0;
|
|
4
|
-
const
|
|
4
|
+
const version_js_1 = require("./version.js");
|
|
5
5
|
const commander_1 = require("commander");
|
|
6
6
|
/**
|
|
7
7
|
* Commander
|
|
@@ -9,7 +9,7 @@ const commander_1 = require("commander");
|
|
|
9
9
|
exports.commander = new commander_1.Command()
|
|
10
10
|
.name('reciple')
|
|
11
11
|
.description('Reciple.js - Discord.js handler cli')
|
|
12
|
-
.version(`v${
|
|
12
|
+
.version(`v${version_js_1.rawVersion}`, '-v, --version')
|
|
13
13
|
.argument('[current-working-directory]', 'Change the current working directory')
|
|
14
14
|
.option('-t, --token <token>', 'Replace used bot token')
|
|
15
15
|
.option('-c, --config <config>', 'Change path to config file')
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandType = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Types of command builders
|
|
6
|
+
*/
|
|
7
|
+
var CommandType;
|
|
8
|
+
(function (CommandType) {
|
|
9
|
+
CommandType[CommandType["SlashCommand"] = 1] = "SlashCommand";
|
|
10
|
+
CommandType[CommandType["MessageCommand"] = 2] = "MessageCommand";
|
|
11
|
+
})(CommandType = exports.CommandType || (exports.CommandType = {}));
|
|
@@ -6,10 +6,10 @@ exports.CommandHaltReason = void 0;
|
|
|
6
6
|
*/
|
|
7
7
|
var CommandHaltReason;
|
|
8
8
|
(function (CommandHaltReason) {
|
|
9
|
-
CommandHaltReason[CommandHaltReason["Error"] =
|
|
10
|
-
CommandHaltReason[CommandHaltReason["Cooldown"] =
|
|
11
|
-
CommandHaltReason[CommandHaltReason["InvalidArguments"] =
|
|
12
|
-
CommandHaltReason[CommandHaltReason["MissingArguments"] =
|
|
13
|
-
CommandHaltReason[CommandHaltReason["MissingMemberPermissions"] =
|
|
14
|
-
CommandHaltReason[CommandHaltReason["MissingBotPermissions"] =
|
|
9
|
+
CommandHaltReason[CommandHaltReason["Error"] = 1] = "Error";
|
|
10
|
+
CommandHaltReason[CommandHaltReason["Cooldown"] = 2] = "Cooldown";
|
|
11
|
+
CommandHaltReason[CommandHaltReason["InvalidArguments"] = 3] = "InvalidArguments";
|
|
12
|
+
CommandHaltReason[CommandHaltReason["MissingArguments"] = 4] = "MissingArguments";
|
|
13
|
+
CommandHaltReason[CommandHaltReason["MissingMemberPermissions"] = 5] = "MissingMemberPermissions";
|
|
14
|
+
CommandHaltReason[CommandHaltReason["MissingBotPermissions"] = 6] = "MissingBotPermissions";
|
|
15
15
|
})(CommandHaltReason = exports.CommandHaltReason || (exports.CommandHaltReason = {}));
|
|
File without changes
|
|
@@ -3,10 +3,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createLogger = void 0;
|
|
6
|
+
exports.path = exports.createLogger = exports.validateCommandBuilder = exports.deprecationWarning = exports.isClass = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
7
8
|
const fallout_utility_1 = require("fallout-utility");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
8
10
|
const flags_1 = require("./flags");
|
|
9
|
-
const
|
|
11
|
+
const builders_1 = require("./types/builders");
|
|
12
|
+
/**
|
|
13
|
+
* Check if an object is a class
|
|
14
|
+
* @param object Object to identify
|
|
15
|
+
*/
|
|
16
|
+
function isClass(object) {
|
|
17
|
+
const isClassConstructor = object.constructor && object.constructor.toString().substring(0, 5) === 'class';
|
|
18
|
+
if (object.prototype === undefined)
|
|
19
|
+
return isClassConstructor;
|
|
20
|
+
const isPrototypeClassConstructor = object.prototype.constructor && object.prototype.constructor.toString && object.prototype.constructor.toString().substring(0, 5) === 'class';
|
|
21
|
+
return isClassConstructor || isPrototypeClassConstructor;
|
|
22
|
+
}
|
|
23
|
+
exports.isClass = isClass;
|
|
24
|
+
/**
|
|
25
|
+
* Emit process warning about deprecated method/function
|
|
26
|
+
* @param content Warning content
|
|
27
|
+
*/
|
|
28
|
+
function deprecationWarning(content) {
|
|
29
|
+
process.emitWarning(content, 'DeprecationWarning');
|
|
30
|
+
}
|
|
31
|
+
exports.deprecationWarning = deprecationWarning;
|
|
32
|
+
function validateCommandBuilder(command) {
|
|
33
|
+
if (!command.name)
|
|
34
|
+
return false;
|
|
35
|
+
if (command.type === builders_1.CommandType.MessageCommand && command.options.length && command.options.some(o => !o.name))
|
|
36
|
+
return false;
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
exports.validateCommandBuilder = validateCommandBuilder;
|
|
10
40
|
/**
|
|
11
41
|
* Create new logger
|
|
12
42
|
* @param stringifyJSON stringify json objects in console
|
|
@@ -35,3 +65,4 @@ function createLogger(stringifyJSON, debugmode = false, colorizeMessage = true)
|
|
|
35
65
|
});
|
|
36
66
|
}
|
|
37
67
|
exports.createLogger = createLogger;
|
|
68
|
+
exports.path = (0, fallout_utility_1.getOperatingSystem)() === fallout_utility_1.OS.WINDOWS ? path_1.default.win32 : path_1.default.posix;
|
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.isSupportedVersion = exports.parseVersion = exports.isValidVersion = exports.rawVersion = exports.version = void 0;
|
|
7
7
|
const semver_1 = __importDefault(require("semver"));
|
|
8
|
-
// TODO: ESM support
|
|
9
8
|
/**
|
|
10
9
|
* Current reciple version
|
|
11
10
|
*/
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.js';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
export * from './reciple/classes/builders/MessageCommandBuilder';
|
|
2
|
-
export * from './reciple/classes/builders/MessageCommandOptionBuilder';
|
|
3
|
-
export * from './reciple/classes/builders/SlashCommandBuilder';
|
|
4
|
-
export * from './reciple/classes/managers/ApplicationCommandManager';
|
|
5
|
-
export * from './reciple/classes/managers/
|
|
6
|
-
export * from './reciple/classes/managers/
|
|
7
|
-
export * from './reciple/classes/managers/
|
|
8
|
-
export * from './reciple/classes/managers/MessageCommandOptionManager';
|
|
9
|
-
export * from './reciple/classes/RecipleClient';
|
|
10
|
-
export * from './reciple/classes/RecipleConfig';
|
|
11
|
-
export * from './reciple/
|
|
12
|
-
export * from './reciple/types/
|
|
13
|
-
export * from './reciple/types/
|
|
1
|
+
export * from './reciple/classes/builders/MessageCommandBuilder.js';
|
|
2
|
+
export * from './reciple/classes/builders/MessageCommandOptionBuilder.js';
|
|
3
|
+
export * from './reciple/classes/builders/SlashCommandBuilder.js';
|
|
4
|
+
export * from './reciple/classes/managers/ApplicationCommandManager.js';
|
|
5
|
+
export * from './reciple/classes/managers/CommandManager.js';
|
|
6
|
+
export * from './reciple/classes/managers/ModuleManager.js';
|
|
7
|
+
export * from './reciple/classes/managers/CommandCooldownManager.js';
|
|
8
|
+
export * from './reciple/classes/managers/MessageCommandOptionManager.js';
|
|
9
|
+
export * from './reciple/classes/RecipleClient.js';
|
|
10
|
+
export * from './reciple/classes/RecipleConfig.js';
|
|
11
|
+
export * from './reciple/classes/RecipleModule.js';
|
|
12
|
+
export * from './reciple/types/builders.js';
|
|
13
|
+
export * from './reciple/types/commands.js';
|
|
14
|
+
export * from './reciple/types/builders.js';
|
|
15
|
+
export * from './reciple/types/builders.js';
|
|
14
16
|
export * from './reciple/flags';
|
|
15
|
-
export * from './reciple/
|
|
16
|
-
export * from './reciple/
|
|
17
|
-
export * from './reciple/
|
|
18
|
-
export * from './reciple/version';
|
|
17
|
+
export * from './reciple/permissions.js';
|
|
18
|
+
export * from './reciple/util.js';
|
|
19
|
+
export * from './reciple/version.js';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { MessageCommandBuilder, MessageCommandExecuteData, MessageCommandHaltData } from './builders/MessageCommandBuilder';
|
|
2
1
|
import { Awaitable, ChatInputCommandInteraction, Client, ClientEvents, ClientOptions, Interaction, Message } from 'discord.js';
|
|
2
|
+
import { MessageCommandBuilder, MessageCommandExecuteData, MessageCommandHaltData } from './builders/MessageCommandBuilder';
|
|
3
3
|
import { SlashCommandBuilder, SlashCommandExecuteData, SlashCommandHaltData } from './builders/SlashCommandBuilder';
|
|
4
4
|
import { AnyCommandExecuteData, AnyCommandHaltData } from '../types/commands';
|
|
5
5
|
import { CommandCooldownManager } from './managers/CommandCooldownManager';
|
|
6
6
|
import { ApplicationCommandManager } from './managers/ApplicationCommandManager';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { CommandManager } from './managers/CommandManager';
|
|
8
|
+
import { ModuleManager } from './managers/ModuleManager';
|
|
9
9
|
import { Config } from './RecipleConfig';
|
|
10
10
|
import { Logger } from 'fallout-utility';
|
|
11
11
|
/**
|
|
@@ -13,6 +13,7 @@ import { Logger } from 'fallout-utility';
|
|
|
13
13
|
*/
|
|
14
14
|
export interface RecipleClientOptions extends ClientOptions {
|
|
15
15
|
config?: Config;
|
|
16
|
+
cwd?: string;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* Reciple client events
|
|
@@ -41,10 +42,11 @@ export interface RecipleClient<Ready extends boolean = boolean> extends Client<R
|
|
|
41
42
|
}
|
|
42
43
|
export declare class RecipleClient<Ready extends boolean = boolean> extends Client<Ready> {
|
|
43
44
|
readonly config: Config;
|
|
44
|
-
readonly commands:
|
|
45
|
+
readonly commands: CommandManager;
|
|
45
46
|
readonly applicationCommands: ApplicationCommandManager;
|
|
46
47
|
readonly cooldowns: CommandCooldownManager;
|
|
47
|
-
readonly modules:
|
|
48
|
+
readonly modules: ModuleManager;
|
|
49
|
+
readonly cwd: string;
|
|
48
50
|
readonly logger: Logger;
|
|
49
51
|
readonly version: string;
|
|
50
52
|
get isClientLogsSilent(): boolean;
|
|
@@ -22,6 +22,7 @@ export interface Config {
|
|
|
22
22
|
enabled: boolean;
|
|
23
23
|
replyOnError: boolean;
|
|
24
24
|
registerCommands: boolean;
|
|
25
|
+
allowRegisterEmptyCommandList: boolean;
|
|
25
26
|
enableCooldown: boolean;
|
|
26
27
|
setRequiredPermissions: boolean;
|
|
27
28
|
acceptRepliedInteractions: boolean;
|
|
@@ -81,9 +82,9 @@ export declare class RecipleConfig {
|
|
|
81
82
|
getConfig(): Config;
|
|
82
83
|
/**
|
|
83
84
|
* Parse token from config
|
|
84
|
-
* @param
|
|
85
|
+
* @param askIfEmpty Ask for token if the token is undefined
|
|
85
86
|
*/
|
|
86
|
-
parseToken(
|
|
87
|
+
parseToken(askIfEmpty?: boolean): string | null;
|
|
87
88
|
/**
|
|
88
89
|
* Check if the config version is supported
|
|
89
90
|
*/
|