reciple 6.0.0-dev.1 → 6.0.0-dev.12
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 +53 -0
- package/dist/lib/esm.mjs +1 -0
- package/dist/{cjs → lib}/index.js +18 -18
- package/dist/{cjs → lib}/reciple/classes/RecipleClient.js +88 -47
- package/dist/{cjs → lib}/reciple/classes/RecipleConfig.js +13 -6
- package/dist/lib/reciple/classes/RecipleModule.js +94 -0
- package/dist/{cjs → lib}/reciple/classes/builders/MessageCommandBuilder.js +6 -4
- package/dist/{cjs → lib}/reciple/classes/builders/MessageCommandOptionBuilder.js +0 -0
- package/dist/{cjs → lib}/reciple/classes/builders/SlashCommandBuilder.js +12 -23
- package/dist/{cjs → lib}/reciple/classes/managers/ApplicationCommandManager.js +32 -33
- package/dist/{cjs → lib}/reciple/classes/managers/ClientCommandManager.js +14 -14
- package/dist/lib/reciple/classes/managers/ClientModuleManager.js +144 -0
- package/dist/{cjs → lib}/reciple/classes/managers/CommandCooldownManager.js +7 -1
- package/dist/{cjs → lib}/reciple/classes/managers/MessageCommandOptionManager.js +0 -0
- package/dist/{cjs → lib}/reciple/flags.js +2 -2
- package/dist/{cjs → lib}/reciple/permissions.js +3 -4
- package/dist/lib/reciple/types/builders.js +11 -0
- package/dist/{cjs → lib}/reciple/types/commands.js +0 -0
- package/dist/{cjs → lib}/reciple/types/paramOptions.js +0 -0
- package/dist/lib/reciple/util.js +66 -0
- 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 -18
- package/dist/types/reciple/classes/RecipleClient.d.ts +3 -6
- package/dist/types/reciple/classes/RecipleModule.d.ts +56 -0
- package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +6 -6
- package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +17 -17
- package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +6 -11
- package/dist/types/reciple/classes/managers/ClientCommandManager.d.ts +3 -3
- package/dist/types/reciple/classes/managers/ClientModuleManager.d.ts +11 -71
- package/dist/types/reciple/classes/managers/CommandCooldownManager.d.ts +2 -2
- package/dist/types/reciple/types/builders.d.ts +19 -19
- package/dist/types/reciple/types/commands.d.ts +10 -10
- package/dist/types/reciple/types/paramOptions.d.ts +7 -17
- package/dist/types/reciple/util.d.ts +8 -0
- package/package.json +28 -18
- package/dist/cjs/bin.js +0 -50
- package/dist/cjs/reciple/classes/managers/ClientModuleManager.js +0 -189
- package/dist/cjs/reciple/logger.js +0 -35
- package/dist/cjs/reciple/modules.js +0 -113
- package/dist/cjs/reciple/types/builders.js +0 -11
- package/dist/cjs/reciple/util.js +0 -32
- package/dist/types/reciple/logger.d.ts +0 -8
- package/dist/types/reciple/modules.d.ts +0 -64
- package/docs/README.md +0 -1
|
@@ -10,11 +10,13 @@ const discord_js_1 = require("discord.js");
|
|
|
10
10
|
class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
11
11
|
constructor(data) {
|
|
12
12
|
super();
|
|
13
|
-
this.type = builders_1.
|
|
13
|
+
this.type = builders_1.CommandType.SlashCommand;
|
|
14
14
|
this.cooldown = 0;
|
|
15
15
|
this.requiredBotPermissions = [];
|
|
16
16
|
this.requiredMemberPermissions = [];
|
|
17
|
-
this.execute = () => {
|
|
17
|
+
this.execute = () => {
|
|
18
|
+
/* Execute */
|
|
19
|
+
};
|
|
18
20
|
// TODO: WTH
|
|
19
21
|
if (data?.name !== undefined)
|
|
20
22
|
this.setName(data.name);
|
|
@@ -58,9 +60,7 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
|
58
60
|
}
|
|
59
61
|
setRequiredMemberPermissions(...permissions) {
|
|
60
62
|
this.requiredMemberPermissions = (0, discord_js_1.normalizeArray)(permissions);
|
|
61
|
-
this.setDefaultMemberPermissions(this.requiredMemberPermissions.length
|
|
62
|
-
? new discord_js_1.PermissionsBitField(this.requiredMemberPermissions).bitfield
|
|
63
|
-
: undefined);
|
|
63
|
+
this.setDefaultMemberPermissions(this.requiredMemberPermissions.length ? new discord_js_1.PermissionsBitField(this.requiredMemberPermissions).bitfield : undefined);
|
|
64
64
|
return this;
|
|
65
65
|
}
|
|
66
66
|
setHalt(halt) {
|
|
@@ -135,13 +135,10 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
|
135
135
|
builder = new discord_js_1.SlashCommandBooleanOption();
|
|
136
136
|
break;
|
|
137
137
|
case discord_js_1.ApplicationCommandOptionType.Channel:
|
|
138
|
-
builder = new discord_js_1.SlashCommandChannelOption()
|
|
139
|
-
.addChannelTypes(...(option.channelTypes ?? []));
|
|
138
|
+
builder = new discord_js_1.SlashCommandChannelOption().addChannelTypes(...(option.channelTypes ?? []));
|
|
140
139
|
break;
|
|
141
140
|
case discord_js_1.ApplicationCommandOptionType.Integer:
|
|
142
|
-
builder = new discord_js_1.SlashCommandIntegerOption()
|
|
143
|
-
.addChoices(...(option.choices ?? []))
|
|
144
|
-
.setAutocomplete(!!option.autocomplete);
|
|
141
|
+
builder = new discord_js_1.SlashCommandIntegerOption().addChoices(...(option.choices ?? [])).setAutocomplete(!!option.autocomplete);
|
|
145
142
|
if (option.maxValue)
|
|
146
143
|
builder.setMaxValue(option.maxValue);
|
|
147
144
|
if (option.minValue)
|
|
@@ -151,9 +148,7 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
|
151
148
|
builder = new discord_js_1.SlashCommandMentionableOption();
|
|
152
149
|
break;
|
|
153
150
|
case discord_js_1.ApplicationCommandOptionType.Number:
|
|
154
|
-
builder = new discord_js_1.SlashCommandNumberOption()
|
|
155
|
-
.addChoices(...(option.choices ?? []))
|
|
156
|
-
.setAutocomplete(!!option.autocomplete);
|
|
151
|
+
builder = new discord_js_1.SlashCommandNumberOption().addChoices(...(option.choices ?? [])).setAutocomplete(!!option.autocomplete);
|
|
157
152
|
if (option.maxValue)
|
|
158
153
|
builder.setMaxValue(option.maxValue);
|
|
159
154
|
if (option.minValue)
|
|
@@ -163,9 +158,7 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
|
163
158
|
builder = new discord_js_1.SlashCommandRoleOption();
|
|
164
159
|
break;
|
|
165
160
|
case discord_js_1.ApplicationCommandOptionType.String:
|
|
166
|
-
builder = new discord_js_1.SlashCommandStringOption()
|
|
167
|
-
.addChoices(...(option.choices ?? []))
|
|
168
|
-
.setAutocomplete(!!option.autocomplete);
|
|
161
|
+
builder = new discord_js_1.SlashCommandStringOption().addChoices(...(option.choices ?? [])).setAutocomplete(!!option.autocomplete);
|
|
169
162
|
if (option.maxLength)
|
|
170
163
|
builder.setMaxLength(option.maxLength);
|
|
171
164
|
if (option.minLength)
|
|
@@ -183,17 +176,13 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
|
183
176
|
case discord_js_1.ApplicationCommandOptionType.SubcommandGroup:
|
|
184
177
|
builder = new discord_js_1.SlashCommandSubcommandGroupBuilder();
|
|
185
178
|
for (const subCommandData of option.options) {
|
|
186
|
-
builder.addSubcommand(subCommandData instanceof discord_js_1.SlashCommandSubcommandBuilder
|
|
187
|
-
? subCommandData
|
|
188
|
-
: this.resolveOption(subCommandData));
|
|
179
|
+
builder.addSubcommand(subCommandData instanceof discord_js_1.SlashCommandSubcommandBuilder ? subCommandData : this.resolveOption(subCommandData));
|
|
189
180
|
}
|
|
190
181
|
break;
|
|
191
182
|
default:
|
|
192
|
-
throw new TypeError(
|
|
183
|
+
throw new TypeError('Unknown option data');
|
|
193
184
|
}
|
|
194
|
-
if (!(builder instanceof discord_js_1.SlashCommandSubcommandBuilder) && !(builder instanceof discord_js_1.SlashCommandSubcommandGroupBuilder)
|
|
195
|
-
&&
|
|
196
|
-
option.type !== discord_js_1.ApplicationCommandOptionType.Subcommand && option.type !== discord_js_1.ApplicationCommandOptionType.SubcommandGroup) {
|
|
185
|
+
if (!(builder instanceof discord_js_1.SlashCommandSubcommandBuilder) && !(builder instanceof discord_js_1.SlashCommandSubcommandGroupBuilder) && option.type !== discord_js_1.ApplicationCommandOptionType.Subcommand && option.type !== discord_js_1.ApplicationCommandOptionType.SubcommandGroup) {
|
|
197
186
|
builder.setRequired(option.required ?? false);
|
|
198
187
|
}
|
|
199
188
|
return builder
|
|
@@ -7,98 +7,101 @@ class ApplicationCommandManager {
|
|
|
7
7
|
constructor(client) {
|
|
8
8
|
this.client = client;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
async set(commands, ...guilds) {
|
|
11
|
+
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
12
12
|
if (!this.client.isReady())
|
|
13
13
|
throw new Error('Client is not ready');
|
|
14
14
|
if (guilds && guilds.length > 1) {
|
|
15
15
|
for (const guild of guilds) {
|
|
16
|
-
await this.set(commands,
|
|
16
|
+
await this.set(commands, guild);
|
|
17
17
|
}
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
20
|
let guild = guilds?.shift();
|
|
21
21
|
guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
|
|
22
22
|
if (!guild) {
|
|
23
|
-
this.client.application.commands.set(commands);
|
|
24
|
-
if (this.client.
|
|
23
|
+
await this.client.application.commands.set(commands);
|
|
24
|
+
if (!this.client.isClientLogsSilent)
|
|
25
25
|
this.client.logger.log(`Registered ${this.client.commands.applicationCommandsSize} application command(s) globally...`);
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
-
this.client.application.commands.set(commands, guild);
|
|
29
|
-
if (this.client.
|
|
28
|
+
await this.client.application.commands.set(commands, guild);
|
|
29
|
+
if (!this.client.isClientLogsSilent)
|
|
30
30
|
this.client.logger.log(`Registered ${this.client.commands.applicationCommandsSize} application command(s) to guild ${guild}...`);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
async add(command, guilds) {
|
|
33
|
+
async add(command, ...guilds) {
|
|
34
|
+
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
34
35
|
if (!this.client.isReady())
|
|
35
36
|
throw new Error('Client is not ready');
|
|
36
37
|
if (!command)
|
|
37
38
|
throw new Error('Command is undefined');
|
|
38
39
|
if (guilds && guilds.length > 1) {
|
|
39
40
|
for (const guild of guilds) {
|
|
40
|
-
await this.add(command,
|
|
41
|
+
await this.add(command, guild);
|
|
41
42
|
}
|
|
42
43
|
return;
|
|
43
44
|
}
|
|
44
45
|
let guild = guilds?.shift();
|
|
45
46
|
guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
|
|
46
47
|
if (!guild) {
|
|
47
|
-
this.client.application.commands.create(command);
|
|
48
|
-
if (this.client.
|
|
48
|
+
await this.client.application.commands.create(command);
|
|
49
|
+
if (!this.client.isClientLogsSilent)
|
|
49
50
|
this.client.logger.log(`Created application command '${command.name}' globally`);
|
|
50
51
|
}
|
|
51
52
|
else {
|
|
52
|
-
this.client.application.commands.create(command, guild);
|
|
53
|
-
if (this.client.
|
|
53
|
+
await this.client.application.commands.create(command, guild);
|
|
54
|
+
if (!this.client.isClientLogsSilent)
|
|
54
55
|
this.client.logger.log(`Created application command '${command.name}' to guild ${guild}`);
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
|
-
async remove(command, guilds) {
|
|
58
|
+
async remove(command, ...guilds) {
|
|
59
|
+
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
58
60
|
if (!this.client.isReady())
|
|
59
61
|
throw new Error('Client is not ready');
|
|
60
62
|
if (!command)
|
|
61
63
|
throw new Error('Command is undefined');
|
|
62
64
|
if (guilds && guilds.length > 1) {
|
|
63
65
|
for (const guild of guilds) {
|
|
64
|
-
await this.remove(command,
|
|
66
|
+
await this.remove(command, guild);
|
|
65
67
|
}
|
|
66
68
|
return;
|
|
67
69
|
}
|
|
68
70
|
let guild = guilds?.shift();
|
|
69
71
|
guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
|
|
70
72
|
if (!guild) {
|
|
71
|
-
this.client.application.commands.delete(command);
|
|
72
|
-
if (this.client.
|
|
73
|
+
await this.client.application.commands.delete(command);
|
|
74
|
+
if (!this.client.isClientLogsSilent)
|
|
73
75
|
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' globally`);
|
|
74
76
|
}
|
|
75
77
|
else {
|
|
76
|
-
this.client.application.commands.delete(command, guild);
|
|
77
|
-
if (this.client.
|
|
78
|
+
await this.client.application.commands.delete(command, guild);
|
|
79
|
+
if (!this.client.isClientLogsSilent)
|
|
78
80
|
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' from guild ${guild}`);
|
|
79
81
|
}
|
|
80
82
|
}
|
|
81
|
-
async edit(command, newCommand, guilds) {
|
|
83
|
+
async edit(command, newCommand, ...guilds) {
|
|
84
|
+
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
82
85
|
if (!this.client.isReady())
|
|
83
86
|
throw new Error('Client is not ready');
|
|
84
87
|
if (!command)
|
|
85
88
|
throw new Error('Command is undefined');
|
|
86
89
|
if (guilds && guilds.length > 1) {
|
|
87
90
|
for (const guild of guilds) {
|
|
88
|
-
await this.edit(command, newCommand,
|
|
91
|
+
await this.edit(command, newCommand, guild);
|
|
89
92
|
}
|
|
90
93
|
return;
|
|
91
94
|
}
|
|
92
95
|
let guild = guilds?.shift();
|
|
93
96
|
guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
|
|
94
97
|
if (!guild) {
|
|
95
|
-
this.client.application.commands.edit(command, newCommand);
|
|
96
|
-
if (this.client.
|
|
98
|
+
await this.client.application.commands.edit(command, newCommand);
|
|
99
|
+
if (!this.client.isClientLogsSilent)
|
|
97
100
|
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' globally`);
|
|
98
101
|
}
|
|
99
102
|
else {
|
|
100
|
-
this.client.application.commands.edit(command, newCommand, guild);
|
|
101
|
-
if (this.client.
|
|
103
|
+
await this.client.application.commands.edit(command, newCommand, guild);
|
|
104
|
+
if (!this.client.isClientLogsSilent)
|
|
102
105
|
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' from guild ${guild}`);
|
|
103
106
|
}
|
|
104
107
|
}
|
|
@@ -106,9 +109,7 @@ class ApplicationCommandManager {
|
|
|
106
109
|
const commands = guild ? this.client.guilds.resolve(guild)?.commands.cache : this.client.application?.commands.cache;
|
|
107
110
|
if (!commands)
|
|
108
111
|
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
|
+
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
113
|
}
|
|
113
114
|
async fetch(commandId, guild) {
|
|
114
115
|
const manager = guild ? this.client.guilds.resolve(guild)?.commands : this.client.application?.commands;
|
|
@@ -119,14 +120,12 @@ class ApplicationCommandManager {
|
|
|
119
120
|
parseCommands(commands, setPermissions = true) {
|
|
120
121
|
return commands.map(cmd => {
|
|
121
122
|
if (cmd?.toJSON === undefined)
|
|
122
|
-
return
|
|
123
|
+
return cmd;
|
|
123
124
|
if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandBuilder(cmd) && this.client.config.commands.slashCommand.setRequiredPermissions) {
|
|
124
|
-
const permissions =
|
|
125
|
-
? this.client.config.commands.slashCommand.permissions.commands.find(cmd_ => cmd_.command.toLowerCase() === cmd.name.toLowerCase())?.permissions
|
|
126
|
-
: undefined;
|
|
125
|
+
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
126
|
if (permissions) {
|
|
128
127
|
cmd.setRequiredMemberPermissions(...permissions);
|
|
129
|
-
if (this.client.
|
|
128
|
+
if (!this.client.isClientLogsSilent)
|
|
130
129
|
this.client.logger.debug(`Set required permissions for ${cmd.name}`);
|
|
131
130
|
}
|
|
132
131
|
}
|
|
@@ -14,31 +14,33 @@ 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() {
|
|
17
|
+
get applicationCommandsSize() {
|
|
18
|
+
return this.client.commands.slashCommands.size + this.client.commands.additionalApplicationCommands.length;
|
|
19
|
+
}
|
|
18
20
|
/**
|
|
19
21
|
* Add command to command manager
|
|
20
22
|
* @param commands Any command data or builder
|
|
21
23
|
*/
|
|
22
24
|
add(...commands) {
|
|
23
25
|
for (const command of (0, discord_js_1.normalizeArray)(commands)) {
|
|
24
|
-
if (command.type === builders_1.
|
|
26
|
+
if (command.type === builders_1.CommandType.SlashCommand) {
|
|
25
27
|
this.slashCommands.set(command.name, SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command));
|
|
26
28
|
}
|
|
27
|
-
else if (command.type === builders_1.
|
|
29
|
+
else if (command.type === builders_1.CommandType.MessageCommand) {
|
|
28
30
|
this.messageCommands.set(command.name, MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command));
|
|
29
31
|
}
|
|
32
|
+
else {
|
|
33
|
+
throw new Error(`Unknown reciple command type`);
|
|
34
|
+
}
|
|
30
35
|
}
|
|
31
36
|
return this;
|
|
32
37
|
}
|
|
33
38
|
get(command, type) {
|
|
34
39
|
switch (type) {
|
|
35
|
-
case builders_1.
|
|
40
|
+
case builders_1.CommandType.SlashCommand:
|
|
36
41
|
return this.slashCommands.get(command);
|
|
37
|
-
case builders_1.
|
|
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
|
+
case builders_1.CommandType.MessageCommand:
|
|
43
|
+
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
44
|
default:
|
|
43
45
|
throw new TypeError('Unknown command type');
|
|
44
46
|
}
|
|
@@ -49,13 +51,11 @@ class ClientCommandManager {
|
|
|
49
51
|
*/
|
|
50
52
|
async registerApplicationCommands(...guilds) {
|
|
51
53
|
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
52
|
-
guilds = guilds.length
|
|
53
|
-
|
|
54
|
-
: (0, discord_js_1.normalizeArray)([this.client.config.commands.slashCommand.guilds]);
|
|
55
|
-
if (this.client.isClientLogsEnabled())
|
|
54
|
+
guilds = guilds.length ? guilds : (0, discord_js_1.normalizeArray)([this.client.config.commands.slashCommand.guilds]);
|
|
55
|
+
if (!this.client.isClientLogsSilent)
|
|
56
56
|
this.client.logger.log(`Regestering ${this.applicationCommandsSize} application command(s) ${!guilds.length ? 'globaly' : 'to ' + guilds.length + ' guilds'}...`);
|
|
57
57
|
await this.client.applicationCommands.set([...this.slashCommands.toJSON(), ...this.additionalApplicationCommands], guilds);
|
|
58
|
-
this.client.emit('
|
|
58
|
+
this.client.emit('recipleRegisterApplicationCommands');
|
|
59
59
|
return this;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -0,0 +1,144 @@
|
|
|
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.ClientModuleManager = void 0;
|
|
7
|
+
const discord_js_1 = require("discord.js");
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const util_1 = require("util");
|
|
11
|
+
const wildcard_match_1 = __importDefault(require("wildcard-match"));
|
|
12
|
+
const flags_1 = require("../../flags");
|
|
13
|
+
const RecipleModule_1 = require("../RecipleModule");
|
|
14
|
+
class ClientModuleManager {
|
|
15
|
+
constructor(options) {
|
|
16
|
+
this.modules = new discord_js_1.Collection();
|
|
17
|
+
this.client = options.client;
|
|
18
|
+
options.modules?.forEach(m => (m instanceof RecipleModule_1.RecipleModule ? m : new RecipleModule_1.RecipleModule({ client: this.client, script: m })));
|
|
19
|
+
}
|
|
20
|
+
async startModules(modules, ignoreErrors = true) {
|
|
21
|
+
for (const module_ of modules) {
|
|
22
|
+
if (!this.client.isClientLogsSilent)
|
|
23
|
+
this.client.logger.log(`Starting module '${module_}'`);
|
|
24
|
+
try {
|
|
25
|
+
let error;
|
|
26
|
+
const start = await module_.start().catch(err => {
|
|
27
|
+
error = err;
|
|
28
|
+
return false;
|
|
29
|
+
});
|
|
30
|
+
if (error)
|
|
31
|
+
throw new Error(`An error occured while loading module '${module_}': \n${(0, util_1.inspect)(error)}`);
|
|
32
|
+
if (!start) {
|
|
33
|
+
if (!this.client.isClientLogsSilent)
|
|
34
|
+
this.client.logger.error(`Module '${module_}' returned false onStart`);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
this.modules.set(module_.id, module_);
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
if (!ignoreErrors)
|
|
41
|
+
throw err;
|
|
42
|
+
if (!this.client.isClientLogsSilent)
|
|
43
|
+
this.client.logger.error(`Failed to start module '${module_}': `, err);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return modules;
|
|
47
|
+
}
|
|
48
|
+
async loadModules(modules, addModuleCommandsToClient = true, ignoreErrors = true) {
|
|
49
|
+
for (const module_ of this.modules.toJSON()) {
|
|
50
|
+
try {
|
|
51
|
+
await module_.load().catch(err => {
|
|
52
|
+
throw err;
|
|
53
|
+
});
|
|
54
|
+
if (!this.client.isClientLogsSilent)
|
|
55
|
+
this.client.logger.log(`Loaded module '${module_}'`);
|
|
56
|
+
if (addModuleCommandsToClient) {
|
|
57
|
+
this.client.commands.add(module_.commands);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
if (!ignoreErrors)
|
|
62
|
+
throw err;
|
|
63
|
+
if (!this.client.isClientLogsSilent)
|
|
64
|
+
this.client.logger.error(`Failed to load module '${module_}': `, err);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return modules;
|
|
68
|
+
}
|
|
69
|
+
async unLoadModules(modules, removeUnloadedModules = true, ignoreErrors = true) {
|
|
70
|
+
for (const module_ of this.modules.toJSON()) {
|
|
71
|
+
try {
|
|
72
|
+
await module_.unLoad().catch(err => {
|
|
73
|
+
throw err;
|
|
74
|
+
});
|
|
75
|
+
if (removeUnloadedModules)
|
|
76
|
+
this.modules.delete(module_.id);
|
|
77
|
+
if (!this.client.isClientLogsSilent)
|
|
78
|
+
this.client.logger.log(`Unloaded module '${module_}'`);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
if (!ignoreErrors)
|
|
82
|
+
throw err;
|
|
83
|
+
if (!this.client.isClientLogsSilent)
|
|
84
|
+
this.client.logger.error(`Failed to unLoad module '${module_}': `, err);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return modules;
|
|
88
|
+
}
|
|
89
|
+
async getModulesFromFiles(options) {
|
|
90
|
+
const modules = [];
|
|
91
|
+
for (const file of options.files) {
|
|
92
|
+
try {
|
|
93
|
+
const resolveFile = await import(file);
|
|
94
|
+
let script = resolveFile?.default ?? resolveFile;
|
|
95
|
+
if (script instanceof RecipleModule_1.RecipleModule) {
|
|
96
|
+
modules.push(script);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (!ClientModuleManager.validateScript(script))
|
|
100
|
+
throw new Error(`Invalid module script: ${file}`);
|
|
101
|
+
modules.push(new RecipleModule_1.RecipleModule({
|
|
102
|
+
client: this.client,
|
|
103
|
+
script,
|
|
104
|
+
filePath: file,
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
if (options.dontSkipError)
|
|
109
|
+
throw err;
|
|
110
|
+
if (!this.client.isClientLogsSilent)
|
|
111
|
+
this.client.logger.error(`Can't resolve module from: ${file}`, err);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return modules;
|
|
115
|
+
}
|
|
116
|
+
static validateScript(script) {
|
|
117
|
+
const s = script;
|
|
118
|
+
if (typeof s !== 'object')
|
|
119
|
+
return false;
|
|
120
|
+
if (typeof s.versions !== 'string' && !Array.isArray(s.versions))
|
|
121
|
+
return false;
|
|
122
|
+
if (typeof s.onStart !== 'function')
|
|
123
|
+
return false;
|
|
124
|
+
if (s.onLoad && typeof s.onLoad !== 'function')
|
|
125
|
+
return false;
|
|
126
|
+
if (s.onUnLoad && typeof s.onUnLoad !== 'function')
|
|
127
|
+
return false;
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
async getModulePaths(options) {
|
|
131
|
+
const modules = [];
|
|
132
|
+
for (const dir of options?.folders ?? (0, discord_js_1.normalizeArray)([this.client.config.modulesFolder])) {
|
|
133
|
+
if (!(0, fs_1.existsSync)(dir))
|
|
134
|
+
(0, fs_1.mkdirSync)(dir, { recursive: true });
|
|
135
|
+
if (!(0, fs_1.lstatSync)(dir).isDirectory())
|
|
136
|
+
continue;
|
|
137
|
+
modules.push(...(0, fs_1.readdirSync)(dir)
|
|
138
|
+
.map(file => path_1.default.join(flags_1.cwd, dir, file))
|
|
139
|
+
.filter(file => (options?.filter ? options.filter(file) : file.endsWith('.js'))));
|
|
140
|
+
}
|
|
141
|
+
return modules.filter(file => !(options?.ignoredFiles ?? this.client.config.ignoredFiles).some(ignored => (0, wildcard_match_1.default)(ignored)(path_1.default.basename(file))));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.ClientModuleManager = ClientModuleManager;
|
|
@@ -47,7 +47,13 @@ class CommandCooldownManager extends Array {
|
|
|
47
47
|
const data = this.get(options);
|
|
48
48
|
if (!data)
|
|
49
49
|
return false;
|
|
50
|
-
this.remove({
|
|
50
|
+
this.remove({
|
|
51
|
+
...data,
|
|
52
|
+
channel: undefined,
|
|
53
|
+
guild: undefined,
|
|
54
|
+
type: undefined,
|
|
55
|
+
command: undefined,
|
|
56
|
+
});
|
|
51
57
|
if (data.expireTime < Date.now())
|
|
52
58
|
return false;
|
|
53
59
|
return true;
|
|
File without changes
|
|
@@ -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')
|
|
@@ -7,10 +7,9 @@ const discord_js_1 = require("discord.js");
|
|
|
7
7
|
* @param options options
|
|
8
8
|
*/
|
|
9
9
|
function userHasCommandPermissions(options) {
|
|
10
|
-
const command = (options.commandPermissions?.enabled
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
?? { permissions: options.builder.requiredMemberPermissions };
|
|
10
|
+
const command = (options.commandPermissions?.enabled ? options.commandPermissions?.commands.find(c => c.command.toLowerCase() === options.builder.name.toLowerCase()) : null) ?? {
|
|
11
|
+
permissions: options.builder.requiredMemberPermissions,
|
|
12
|
+
};
|
|
14
13
|
if (!command.permissions.length)
|
|
15
14
|
return true;
|
|
16
15
|
return options.memberPermissions ? options.memberPermissions.has(command.permissions) : false;
|
|
@@ -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["MessageCommand"] = 0] = "MessageCommand";
|
|
10
|
+
CommandType[CommandType["SlashCommand"] = 1] = "SlashCommand";
|
|
11
|
+
})(CommandType = exports.CommandType || (exports.CommandType = {}));
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,66 @@
|
|
|
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.createLogger = exports.validateCommandBuilder = exports.deprecationWarning = exports.isClass = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const fallout_utility_1 = require("fallout-utility");
|
|
9
|
+
const flags_1 = require("./flags");
|
|
10
|
+
const builders_1 = require("./types/builders");
|
|
11
|
+
/**
|
|
12
|
+
* Check if an object is a class
|
|
13
|
+
* @param object Object to identify
|
|
14
|
+
*/
|
|
15
|
+
function isClass(object) {
|
|
16
|
+
const isClassConstructor = object.constructor && object.constructor.toString().substring(0, 5) === 'class';
|
|
17
|
+
if (object.prototype === undefined)
|
|
18
|
+
return isClassConstructor;
|
|
19
|
+
const isPrototypeClassConstructor = object.prototype.constructor && object.prototype.constructor.toString && object.prototype.constructor.toString().substring(0, 5) === 'class';
|
|
20
|
+
return isClassConstructor || isPrototypeClassConstructor;
|
|
21
|
+
}
|
|
22
|
+
exports.isClass = isClass;
|
|
23
|
+
/**
|
|
24
|
+
* Emit process warning about deprecated method/function
|
|
25
|
+
* @param content Warning content
|
|
26
|
+
*/
|
|
27
|
+
function deprecationWarning(content) {
|
|
28
|
+
process.emitWarning(content, 'DeprecationWarning');
|
|
29
|
+
}
|
|
30
|
+
exports.deprecationWarning = deprecationWarning;
|
|
31
|
+
function validateCommandBuilder(command) {
|
|
32
|
+
if (!command.name)
|
|
33
|
+
return false;
|
|
34
|
+
if (command.type === builders_1.CommandType.MessageCommand && command.options.length && command.options.some(o => !o.name))
|
|
35
|
+
return false;
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
exports.validateCommandBuilder = validateCommandBuilder;
|
|
39
|
+
/**
|
|
40
|
+
* Create new logger
|
|
41
|
+
* @param stringifyJSON stringify json objects in console
|
|
42
|
+
* @param debugmode display debug messages
|
|
43
|
+
* @param colorizeMessage add logger colours to messages
|
|
44
|
+
*/
|
|
45
|
+
function createLogger(stringifyJSON, debugmode = false, colorizeMessage = true) {
|
|
46
|
+
return new fallout_utility_1.Logger({
|
|
47
|
+
stringifyJSON: stringifyJSON,
|
|
48
|
+
enableDebugMode: flags_1.flags.debugmode ?? debugmode,
|
|
49
|
+
loggerName: 'Main',
|
|
50
|
+
prefixes: {
|
|
51
|
+
[fallout_utility_1.LogLevels.INFO]: (name) => `[${new Date().toLocaleTimeString(undefined, {
|
|
52
|
+
hour12: false,
|
|
53
|
+
})}][${(name ? name + '/' : '') + 'INFO'}]`,
|
|
54
|
+
[fallout_utility_1.LogLevels.WARN]: (name) => `[${chalk_1.default.yellow(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.yellow((name ? name + '/' : '') + 'WARN')}]`,
|
|
55
|
+
[fallout_utility_1.LogLevels.ERROR]: (name) => `[${chalk_1.default.red(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.red((name ? name + '/' : '') + 'ERROR')}]`,
|
|
56
|
+
[fallout_utility_1.LogLevels.DEBUG]: (name) => `[${chalk_1.default.blue(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.blue((name ? name + '/' : '') + 'DEBUG')}]`,
|
|
57
|
+
},
|
|
58
|
+
colorMessages: {
|
|
59
|
+
[fallout_utility_1.LogLevels.INFO]: (message) => message,
|
|
60
|
+
[fallout_utility_1.LogLevels.WARN]: (message) => (!colorizeMessage ? message : chalk_1.default.yellow(message)),
|
|
61
|
+
[fallout_utility_1.LogLevels.ERROR]: (message) => (!colorizeMessage ? message : chalk_1.default.red(message)),
|
|
62
|
+
[fallout_utility_1.LogLevels.DEBUG]: (message) => (!colorizeMessage ? message : chalk_1.default.blue(message)),
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
exports.createLogger = createLogger;
|
|
@@ -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,18 @@
|
|
|
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/
|
|
9
|
-
export * from './reciple/classes/
|
|
10
|
-
export * from './reciple/
|
|
11
|
-
export * from './reciple/
|
|
12
|
-
export * from './reciple/types/
|
|
13
|
-
export * from './reciple/
|
|
14
|
-
export * from './reciple/
|
|
15
|
-
export * from './reciple/
|
|
16
|
-
export * from './reciple/permissions';
|
|
17
|
-
export * from './reciple/util';
|
|
18
|
-
export * from './reciple/version';
|
|
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/ClientCommandManager.js';
|
|
6
|
+
export * from './reciple/classes/managers/ClientModuleManager.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';
|
|
16
|
+
export * from './reciple/permissions.js';
|
|
17
|
+
export * from './reciple/util.js';
|
|
18
|
+
export * from './reciple/version.js';
|