reciple 1.4.2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.d.ts +1 -1
- package/bin/index.js +1 -1
- package/bin/reciple/classes/Client.d.ts +6 -5
- package/bin/reciple/classes/Client.js +45 -37
- package/bin/reciple/classes/Config.d.ts +7 -9
- package/bin/reciple/classes/builders/MessageCommandBuilder.d.ts +5 -2
- package/bin/reciple/classes/builders/MessageCommandBuilder.js +23 -9
- package/bin/reciple/classes/builders/MessageCommandOptionBuilder.d.ts +1 -1
- package/bin/reciple/classes/builders/MessageCommandOptionBuilder.js +2 -2
- package/bin/reciple/hasPermissions.d.ts +4 -0
- package/bin/reciple/{commandPermissions.js → hasPermissions.js} +3 -3
- package/bin/reciple/modules.js +4 -4
- package/bin/reciple/registerInteractionCommands.js +12 -16
- package/bin/reciple/version.d.ts +1 -1
- package/bin/reciple/version.js +6 -6
- package/package.json +39 -39
- package/resource/reciple.yml +1 -0
- package/bin/reciple/commandPermissions.d.ts +0 -4
package/bin/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export * from './reciple/classes/Config';
|
|
|
5
5
|
export * from './reciple/classes/builders/InteractionCommandBuilder';
|
|
6
6
|
export * from './reciple/classes/builders/MessageCommandBuilder';
|
|
7
7
|
export * from './reciple/classes/builders/MessageCommandOptionBuilder';
|
|
8
|
-
export * from './reciple/
|
|
8
|
+
export * from './reciple/hasPermissions';
|
|
9
9
|
export * from './reciple/flags';
|
|
10
10
|
export * from './reciple/isIgnoredChannel';
|
|
11
11
|
export * from './reciple/logger';
|
package/bin/index.js
CHANGED
|
@@ -25,7 +25,7 @@ __exportStar(require("./reciple/classes/Config"), exports);
|
|
|
25
25
|
__exportStar(require("./reciple/classes/builders/InteractionCommandBuilder"), exports);
|
|
26
26
|
__exportStar(require("./reciple/classes/builders/MessageCommandBuilder"), exports);
|
|
27
27
|
__exportStar(require("./reciple/classes/builders/MessageCommandOptionBuilder"), exports);
|
|
28
|
-
__exportStar(require("./reciple/
|
|
28
|
+
__exportStar(require("./reciple/hasPermissions"), exports);
|
|
29
29
|
__exportStar(require("./reciple/flags"), exports);
|
|
30
30
|
__exportStar(require("./reciple/isIgnoredChannel"), exports);
|
|
31
31
|
__exportStar(require("./reciple/logger"), exports);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { InteractionCommandBuilder, RecipleInteractionCommandExecute } from './builders/InteractionCommandBuilder';
|
|
2
2
|
import { interactionCommandBuilders } from '../registerInteractionCommands';
|
|
3
3
|
import { MessageCommandBuilder, RecipleMessageCommandExecute } from './builders/MessageCommandBuilder';
|
|
4
|
-
import { Logger as
|
|
4
|
+
import { Logger as ILogger } from 'fallout-utility';
|
|
5
5
|
import { Config } from './Config';
|
|
6
6
|
import { ApplicationCommandDataResolvable, Awaitable, Client, ClientEvents, ClientOptions, Interaction, Message } from 'discord.js';
|
|
7
7
|
import { recipleCommandBuilders, RecipleScript } from '../modules';
|
|
@@ -33,11 +33,11 @@ export interface RecipleClient extends Client {
|
|
|
33
33
|
removeAllListeners(event?: string | symbol): this;
|
|
34
34
|
}
|
|
35
35
|
export declare class RecipleClient extends Client {
|
|
36
|
-
config
|
|
36
|
+
config: Config;
|
|
37
37
|
commands: RecipleClientCommands;
|
|
38
38
|
otherApplicationCommandData: (interactionCommandBuilders | ApplicationCommandDataResolvable)[];
|
|
39
39
|
modules: RecipleScript[];
|
|
40
|
-
logger:
|
|
40
|
+
logger: ILogger;
|
|
41
41
|
version: string;
|
|
42
42
|
constructor(options: RecipleClientOptions);
|
|
43
43
|
startModules(): Promise<RecipleClient>;
|
|
@@ -45,7 +45,8 @@ export declare class RecipleClient extends Client {
|
|
|
45
45
|
addModule(script: RecipleScript, registerCommands?: boolean): Promise<void>;
|
|
46
46
|
addCommand(command: recipleCommandBuilders): RecipleClient;
|
|
47
47
|
addCommandListeners(): RecipleClient;
|
|
48
|
-
messageCommandExecute(message: Message): Promise<
|
|
49
|
-
interactionCommandExecute(interaction: Interaction): Promise<
|
|
48
|
+
messageCommandExecute(message: Message): Promise<void>;
|
|
49
|
+
interactionCommandExecute(interaction: Interaction): Promise<void>;
|
|
50
|
+
getMessage<T = any>(messageKey: string, defaultMessage?: T): T;
|
|
50
51
|
private _commandExecuteError;
|
|
51
52
|
}
|
|
@@ -18,8 +18,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.RecipleClient = void 0;
|
|
19
19
|
const registerInteractionCommands_1 = require("../registerInteractionCommands");
|
|
20
20
|
const fallout_utility_1 = require("fallout-utility");
|
|
21
|
-
const commandPermissions_1 = require("../commandPermissions");
|
|
22
21
|
const isIgnoredChannel_1 = require("../isIgnoredChannel");
|
|
22
|
+
const hasPermissions_1 = require("../hasPermissions");
|
|
23
23
|
const version_1 = require("../version");
|
|
24
24
|
const logger_1 = require("../logger");
|
|
25
25
|
const discord_js_1 = require("discord.js");
|
|
@@ -57,21 +57,20 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
59
|
loadModules() {
|
|
60
|
-
var _a;
|
|
61
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
62
61
|
for (const module_ of this.modules) {
|
|
63
62
|
if (typeof (module_ === null || module_ === void 0 ? void 0 : module_.onLoad) === 'function')
|
|
64
63
|
yield Promise.resolve(module_.onLoad(this));
|
|
65
64
|
}
|
|
66
65
|
this.logger.info(`${this.modules.length} modules loaded.`);
|
|
67
|
-
if (!
|
|
66
|
+
if (!this.config.commands.interactionCommand.registerCommands)
|
|
68
67
|
return this;
|
|
69
68
|
yield (0, registerInteractionCommands_1.registerInteractionCommands)(this, [...Object.values(this.commands.INTERACTION_COMMANDS), ...this.otherApplicationCommandData]);
|
|
70
69
|
return this;
|
|
71
70
|
});
|
|
72
71
|
}
|
|
73
72
|
addModule(script, registerCommands = true) {
|
|
74
|
-
var _a
|
|
73
|
+
var _a;
|
|
75
74
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
75
|
this.modules.push(script);
|
|
77
76
|
if (typeof (script === null || script === void 0 ? void 0 : script.onLoad) === 'function')
|
|
@@ -82,7 +81,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
82
81
|
continue;
|
|
83
82
|
this.addCommand(command);
|
|
84
83
|
}
|
|
85
|
-
if (!registerCommands || !
|
|
84
|
+
if (!registerCommands || !this.config.commands.interactionCommand.registerCommands)
|
|
86
85
|
return;
|
|
87
86
|
yield (0, registerInteractionCommands_1.registerInteractionCommands)(this, [...Object.values(this.commands.INTERACTION_COMMANDS), ...this.otherApplicationCommandData]);
|
|
88
87
|
});
|
|
@@ -101,33 +100,41 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
101
100
|
return this;
|
|
102
101
|
}
|
|
103
102
|
addCommandListeners() {
|
|
104
|
-
|
|
105
|
-
if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.commands.messageCommand.enabled)
|
|
103
|
+
if (this.config.commands.messageCommand.enabled)
|
|
106
104
|
this.on('messageCreate', (message) => { this.messageCommandExecute(message); });
|
|
107
|
-
if (
|
|
105
|
+
if (this.config.commands.interactionCommand.enabled)
|
|
108
106
|
this.on('interactionCreate', (interaction) => { this.interactionCommandExecute(interaction); });
|
|
109
107
|
return this;
|
|
110
108
|
}
|
|
111
109
|
messageCommandExecute(message) {
|
|
112
|
-
var _a
|
|
110
|
+
var _a;
|
|
113
111
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
if (!message.content || !
|
|
115
|
-
return
|
|
116
|
-
const parseCommand = (0, fallout_utility_1.getCommand)(message.content,
|
|
112
|
+
if (!message.content || !this.config.commands.messageCommand.enabled)
|
|
113
|
+
return;
|
|
114
|
+
const parseCommand = (0, fallout_utility_1.getCommand)(message.content, this.config.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
|
|
117
115
|
if (!(parseCommand === null || parseCommand === void 0 ? void 0 : parseCommand.command) || !parseCommand)
|
|
118
|
-
return
|
|
116
|
+
return;
|
|
119
117
|
const command = this.commands.MESSAGE_COMMANDS[parseCommand.command.toLowerCase()];
|
|
120
118
|
if (!command)
|
|
121
|
-
return
|
|
122
|
-
if ((0,
|
|
123
|
-
if (!command.allowExecuteInDM && message.channel.type === 'DM'
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return
|
|
119
|
+
return;
|
|
120
|
+
if ((0, hasPermissions_1.hasPermissions)(command.name, (_a = message.member) === null || _a === void 0 ? void 0 : _a.permissions, this.config.permissions.messageCommands, command)) {
|
|
121
|
+
if (!command.allowExecuteInDM && message.channel.type === 'DM'
|
|
122
|
+
|| !command.allowExecuteByBots
|
|
123
|
+
&& (message.author.bot || message.author.system)
|
|
124
|
+
|| (0, isIgnoredChannel_1.isIgnoredChannel)(message.channelId, this.config.ignoredChannels))
|
|
125
|
+
return;
|
|
126
|
+
const commandOptions = command.getCommandOptionValues(parseCommand);
|
|
127
|
+
if (commandOptions.some(o => o.invalid)) {
|
|
128
|
+
yield message.reply(this.getMessage('invalidArguments', 'Invalid argument(s) given.'));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (commandOptions.some(o => o.missing)) {
|
|
132
|
+
yield message.reply(this.getMessage('notEnoughArguments', 'Not enough arguments.'));
|
|
133
|
+
return;
|
|
128
134
|
}
|
|
129
135
|
const options = {
|
|
130
136
|
message: message,
|
|
137
|
+
options: commandOptions,
|
|
131
138
|
command: parseCommand,
|
|
132
139
|
builder: command,
|
|
133
140
|
client: this
|
|
@@ -136,24 +143,23 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
136
143
|
this.emit('recipleMessageCommandCreate', options);
|
|
137
144
|
}
|
|
138
145
|
else {
|
|
139
|
-
yield message.reply(
|
|
146
|
+
yield message.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch((err) => this.logger.error(err));
|
|
140
147
|
}
|
|
141
|
-
return this;
|
|
142
148
|
});
|
|
143
149
|
}
|
|
144
150
|
interactionCommandExecute(interaction) {
|
|
145
|
-
var _a
|
|
151
|
+
var _a;
|
|
146
152
|
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
if (!interaction || !interaction.isCommand() || !
|
|
148
|
-
return
|
|
153
|
+
if (!interaction || !interaction.isCommand() || !this.config.commands.interactionCommand.enabled)
|
|
154
|
+
return;
|
|
149
155
|
const command = this.commands.INTERACTION_COMMANDS[interaction.commandName];
|
|
150
156
|
if (!command)
|
|
151
|
-
return
|
|
152
|
-
if ((0,
|
|
153
|
-
if (!command.allowExecuteInDM && interaction.
|
|
154
|
-
return
|
|
157
|
+
return;
|
|
158
|
+
if ((0, hasPermissions_1.hasPermissions)(command.name, (_a = interaction.memberPermissions) !== null && _a !== void 0 ? _a : undefined, this.config.permissions.interactionCommands, command)) {
|
|
159
|
+
if (!command.allowExecuteInDM && !interaction.inCachedGuild() || (0, isIgnoredChannel_1.isIgnoredChannel)(interaction.channelId, this.config.ignoredChannels))
|
|
160
|
+
return;
|
|
155
161
|
if (!command)
|
|
156
|
-
return
|
|
162
|
+
return;
|
|
157
163
|
const options = {
|
|
158
164
|
interaction: interaction,
|
|
159
165
|
command: command,
|
|
@@ -164,27 +170,29 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
164
170
|
this.emit('recipleInteractionCommandCreate', options);
|
|
165
171
|
}
|
|
166
172
|
else {
|
|
167
|
-
yield interaction.reply(
|
|
173
|
+
yield interaction.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch((err) => this.logger.error(err));
|
|
168
174
|
}
|
|
169
|
-
return this;
|
|
170
175
|
});
|
|
171
176
|
}
|
|
177
|
+
getMessage(messageKey, defaultMessage) {
|
|
178
|
+
var _a, _b;
|
|
179
|
+
return (_b = (_a = this.config.messages[messageKey]) !== null && _a !== void 0 ? _a : defaultMessage) !== null && _b !== void 0 ? _b : messageKey;
|
|
180
|
+
}
|
|
172
181
|
_commandExecuteError(err, command) {
|
|
173
|
-
var _a, _b, _c, _d;
|
|
174
182
|
return __awaiter(this, void 0, void 0, function* () {
|
|
175
183
|
this.logger.error(`An error occured executing ${command.builder.builder == 'MESSAGE_COMMAND' ? 'message' : 'interaction'} command "${command.builder.name}"`);
|
|
176
184
|
this.logger.error(err);
|
|
177
185
|
if (!err || !command)
|
|
178
186
|
return;
|
|
179
187
|
if (command === null || command === void 0 ? void 0 : command.message) {
|
|
180
|
-
if (!
|
|
188
|
+
if (!this.config.commands.messageCommand.replyOnError)
|
|
181
189
|
return;
|
|
182
|
-
yield command.message.reply(
|
|
190
|
+
yield command.message.reply(this.getMessage('error', 'An error occurred.')).catch((e) => this.logger.error(e));
|
|
183
191
|
}
|
|
184
192
|
else if (command === null || command === void 0 ? void 0 : command.interaction) {
|
|
185
|
-
if (!
|
|
193
|
+
if (!this.config.commands.interactionCommand.replyOnError)
|
|
186
194
|
return;
|
|
187
|
-
yield command.interaction.followUp(
|
|
195
|
+
yield command.interaction.followUp(this.getMessage('error', 'An error occurred.')).catch((e) => this.logger.error(e));
|
|
188
196
|
}
|
|
189
197
|
});
|
|
190
198
|
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { ClientOptions, PermissionFlags, PermissionString } from 'discord.js';
|
|
2
|
+
export interface ConfigCommandPermissions {
|
|
3
|
+
command: string;
|
|
4
|
+
permissions: (PermissionFlags | PermissionString)[];
|
|
5
|
+
}
|
|
2
6
|
export interface Config {
|
|
3
7
|
token: string;
|
|
4
8
|
prefix: string;
|
|
@@ -19,17 +23,11 @@ export interface Config {
|
|
|
19
23
|
permissions: {
|
|
20
24
|
messageCommands: {
|
|
21
25
|
enabled: boolean;
|
|
22
|
-
commands:
|
|
23
|
-
command: string;
|
|
24
|
-
permissions: (PermissionFlags | PermissionString)[];
|
|
25
|
-
}[];
|
|
26
|
+
commands: ConfigCommandPermissions[];
|
|
26
27
|
};
|
|
27
28
|
interactionCommands: {
|
|
28
29
|
enabled: boolean;
|
|
29
|
-
commands:
|
|
30
|
-
command: string;
|
|
31
|
-
permissions: (PermissionFlags | PermissionString)[];
|
|
32
|
-
}[];
|
|
30
|
+
commands: ConfigCommandPermissions[];
|
|
33
31
|
};
|
|
34
32
|
};
|
|
35
33
|
ignoredChannels: {
|
|
@@ -45,7 +43,7 @@ export interface Config {
|
|
|
45
43
|
};
|
|
46
44
|
client: ClientOptions;
|
|
47
45
|
messages: {
|
|
48
|
-
[
|
|
46
|
+
[messageKey: string]: any;
|
|
49
47
|
};
|
|
50
48
|
ignoredFiles: string[];
|
|
51
49
|
modulesFolder: string;
|
|
@@ -5,14 +5,17 @@ import { RecipleClient } from '../Client';
|
|
|
5
5
|
export declare type CommandMessage = Command;
|
|
6
6
|
export interface RecipleMessageCommandExecute {
|
|
7
7
|
message: Message;
|
|
8
|
+
options: MessageCommandValidatedOption[];
|
|
8
9
|
command: CommandMessage;
|
|
9
10
|
builder: MessageCommandBuilder;
|
|
10
11
|
client: RecipleClient;
|
|
11
12
|
}
|
|
12
13
|
export interface MessageCommandValidatedOption {
|
|
13
14
|
name: string;
|
|
14
|
-
value: string;
|
|
15
|
+
value: string | undefined;
|
|
15
16
|
required: boolean;
|
|
17
|
+
invalid: boolean;
|
|
18
|
+
missing: boolean;
|
|
16
19
|
}
|
|
17
20
|
export declare class MessageCommandBuilder {
|
|
18
21
|
readonly builder: string;
|
|
@@ -32,5 +35,5 @@ export declare class MessageCommandBuilder {
|
|
|
32
35
|
setExecute(execute: (options: RecipleMessageCommandExecute) => void): MessageCommandBuilder;
|
|
33
36
|
addOption(option: MessageCommandOptionBuilder | ((constructor: MessageCommandOptionBuilder) => MessageCommandOptionBuilder)): MessageCommandBuilder;
|
|
34
37
|
setValidateOptions(validateOptions: boolean): MessageCommandBuilder;
|
|
35
|
-
getCommandOptionValues(options: CommandMessage):
|
|
38
|
+
getCommandOptionValues(options: CommandMessage): MessageCommandValidatedOption[];
|
|
36
39
|
}
|
|
@@ -71,17 +71,31 @@ class MessageCommandBuilder {
|
|
|
71
71
|
const args = options.args || [];
|
|
72
72
|
const required = this.options.filter(o => o.required);
|
|
73
73
|
const optional = this.options.filter(o => !o.required);
|
|
74
|
-
|
|
75
|
-
return;
|
|
76
|
-
let i = 0;
|
|
74
|
+
const allOptions = [...required, ...optional];
|
|
77
75
|
let result = [];
|
|
78
|
-
|
|
76
|
+
let i = 0;
|
|
77
|
+
for (const option of allOptions) {
|
|
79
78
|
const arg = args[i];
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
const value = {
|
|
80
|
+
name: option.name,
|
|
81
|
+
value: arg !== null && arg !== void 0 ? arg : undefined,
|
|
82
|
+
required: option.required,
|
|
83
|
+
invalid: false,
|
|
84
|
+
missing: false
|
|
85
|
+
};
|
|
86
|
+
if (arg == undefined && option.required) {
|
|
87
|
+
value.missing = true;
|
|
88
|
+
result.push(value);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (arg == undefined && !option.required) {
|
|
92
|
+
result.push(value);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const validate = option.validator ? option.validator(arg) : true;
|
|
96
|
+
if (!validate)
|
|
97
|
+
value.invalid = true;
|
|
98
|
+
result.push(value);
|
|
85
99
|
i++;
|
|
86
100
|
}
|
|
87
101
|
return result;
|
|
@@ -2,7 +2,7 @@ export declare class MessageCommandOptionBuilder {
|
|
|
2
2
|
name: string;
|
|
3
3
|
description: string;
|
|
4
4
|
required: boolean;
|
|
5
|
-
|
|
5
|
+
validator: (value: string) => boolean;
|
|
6
6
|
setName(name: string): MessageCommandOptionBuilder;
|
|
7
7
|
setDescription(description: string): MessageCommandOptionBuilder;
|
|
8
8
|
setRequired(required: boolean): MessageCommandOptionBuilder;
|
|
@@ -6,7 +6,7 @@ class MessageCommandOptionBuilder {
|
|
|
6
6
|
this.name = '';
|
|
7
7
|
this.description = '';
|
|
8
8
|
this.required = true;
|
|
9
|
-
this.
|
|
9
|
+
this.validator = () => true;
|
|
10
10
|
}
|
|
11
11
|
setName(name) {
|
|
12
12
|
if (typeof name !== 'string' || !name.match(/^[\w-]{1,32}$/))
|
|
@@ -29,7 +29,7 @@ class MessageCommandOptionBuilder {
|
|
|
29
29
|
setValidator(validator) {
|
|
30
30
|
if (!validator || typeof validator !== 'function')
|
|
31
31
|
throw new TypeError('validator must be a function.');
|
|
32
|
-
this.
|
|
32
|
+
this.validator = validator;
|
|
33
33
|
return this;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Permissions } from 'discord.js';
|
|
2
|
+
import { recipleCommandBuilders } from './modules';
|
|
3
|
+
import { Config } from './classes/Config';
|
|
4
|
+
export declare function hasPermissions(commandName: string, memberPermissions?: Permissions, configConmmandPermissions?: Config['permissions']['messageCommands'] | Config['permissions']['interactionCommands'], builder?: recipleCommandBuilders): boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
function
|
|
3
|
+
exports.hasPermissions = void 0;
|
|
4
|
+
function hasPermissions(commandName, memberPermissions, configConmmandPermissions, builder) {
|
|
5
5
|
var _a, _b;
|
|
6
6
|
if (!(configConmmandPermissions === null || configConmmandPermissions === void 0 ? void 0 : configConmmandPermissions.enabled))
|
|
7
7
|
return true;
|
|
@@ -10,4 +10,4 @@ function commandPermissions(commandName, memberPermissions, configConmmandPermis
|
|
|
10
10
|
return true;
|
|
11
11
|
return memberPermissions ? memberPermissions.has(command.permissions) : false;
|
|
12
12
|
}
|
|
13
|
-
exports.
|
|
13
|
+
exports.hasPermissions = hasPermissions;
|
package/bin/reciple/modules.js
CHANGED
|
@@ -18,14 +18,14 @@ const version_1 = require("./version");
|
|
|
18
18
|
const wildcard_match_1 = __importDefault(require("wildcard-match"));
|
|
19
19
|
const path_1 = __importDefault(require("path"));
|
|
20
20
|
function loadModules(client) {
|
|
21
|
-
var _a
|
|
21
|
+
var _a;
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
23
|
const response = { commands: [], modules: [] };
|
|
24
|
-
const modulesDir =
|
|
24
|
+
const modulesDir = client.config.modulesFolder || './modules';
|
|
25
25
|
const logger = client.logger;
|
|
26
26
|
if (!(0, fs_1.existsSync)(modulesDir))
|
|
27
27
|
(0, fs_1.mkdirSync)(modulesDir, { recursive: true });
|
|
28
|
-
const ignoredFiles = (
|
|
28
|
+
const ignoredFiles = (client.config.ignoredFiles || []).map(file => file.endsWith('.js') ? file : `${file}.js`);
|
|
29
29
|
const scripts = (0, fs_1.readdirSync)(modulesDir).filter(file => {
|
|
30
30
|
return file.endsWith('.js') && (!file.startsWith('_') && !file.startsWith('.')) && !ignoredFiles.some(f => (0, wildcard_match_1.default)(f)(file));
|
|
31
31
|
});
|
|
@@ -36,7 +36,7 @@ function loadModules(client) {
|
|
|
36
36
|
try {
|
|
37
37
|
const reqMod = require(modulePath);
|
|
38
38
|
module_ = !!(reqMod === null || reqMod === void 0 ? void 0 : reqMod.default) ? reqMod.default : reqMod;
|
|
39
|
-
if (!((
|
|
39
|
+
if (!((_a = module_.versions) === null || _a === void 0 ? void 0 : _a.length))
|
|
40
40
|
throw new Error('Module does not have supported versions.');
|
|
41
41
|
const versions = typeof module_.versions === 'object' ? module_.versions : [module_.versions];
|
|
42
42
|
if (!versions.some(v => (0, version_1.isSupportedVersion)(v, version_1.version)))
|
|
@@ -11,17 +11,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.registerInteractionCommands = void 0;
|
|
13
13
|
function registerInteractionCommands(client, cmds, overwriteGuilds) {
|
|
14
|
-
var _a, _b, _c
|
|
14
|
+
var _a, _b, _c;
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
|
|
17
|
-
var _a, _b, _c, _d
|
|
16
|
+
const commands = (_a = Object.values(cmds !== null && cmds !== void 0 ? cmds : client.commands.INTERACTION_COMMANDS).map(c => {
|
|
17
|
+
var _a, _b, _c, _d;
|
|
18
18
|
if (typeof c.toJSON == 'undefined')
|
|
19
19
|
return c;
|
|
20
20
|
const cmd = c;
|
|
21
|
-
if ((cmd === null || cmd === void 0 ? void 0 : cmd.builder) === 'INTERACTION_COMMAND' &&
|
|
22
|
-
const permissions = (
|
|
23
|
-
(
|
|
24
|
-
undefined)) !== null &&
|
|
21
|
+
if ((cmd === null || cmd === void 0 ? void 0 : cmd.builder) === 'INTERACTION_COMMAND' && client.config.commands.interactionCommand.setRequiredPermissions) {
|
|
22
|
+
const permissions = (_d = (((_a = client.config.permissions) === null || _a === void 0 ? void 0 : _a.interactionCommands.enabled) ?
|
|
23
|
+
(_c = (_b = client.config.permissions) === null || _b === void 0 ? void 0 : _b.interactionCommands.commands.find(cmd_ => cmd_.command.toLowerCase() === cmd.name.toLowerCase())) === null || _c === void 0 ? void 0 : _c.permissions :
|
|
24
|
+
undefined)) !== null && _d !== void 0 ? _d : cmd.requiredPermissions;
|
|
25
25
|
cmd.setRequiredPermissions(permissions);
|
|
26
26
|
client.commands.INTERACTION_COMMANDS[cmd.name] = cmd;
|
|
27
27
|
client.logger.debug(`Set required permissions for ${cmd.name} to ${permissions.join(', ')}`);
|
|
@@ -29,24 +29,20 @@ function registerInteractionCommands(client, cmds, overwriteGuilds) {
|
|
|
29
29
|
}
|
|
30
30
|
return c.toJSON();
|
|
31
31
|
})) !== null && _a !== void 0 ? _a : [];
|
|
32
|
-
|
|
33
|
-
client.logger.warn('No interaction commands found.');
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const configGuilds = overwriteGuilds !== null && overwriteGuilds !== void 0 ? overwriteGuilds : (_b = client.config) === null || _b === void 0 ? void 0 : _b.commands.interactionCommand.guilds;
|
|
32
|
+
const configGuilds = overwriteGuilds !== null && overwriteGuilds !== void 0 ? overwriteGuilds : client.config.commands.interactionCommand.guilds;
|
|
37
33
|
const guilds = typeof configGuilds === 'object' ? configGuilds : [configGuilds];
|
|
38
34
|
if (!guilds || !(guilds === null || guilds === void 0 ? void 0 : guilds.length)) {
|
|
39
|
-
(
|
|
35
|
+
(_b = client.application) === null || _b === void 0 ? void 0 : _b.commands.set(commands).then(() => {
|
|
40
36
|
client.logger.warn('No guilds were specified for interaction commands. Registered commands for all guilds.');
|
|
41
37
|
}).catch(e => client.logger.error(e));
|
|
42
38
|
}
|
|
43
39
|
else {
|
|
44
|
-
client.logger.warn(`Registering ${commands.length} interaction commands
|
|
40
|
+
client.logger.warn(`Registering ${commands.length} interaction commands to ${guilds.length} guild(s).`);
|
|
45
41
|
for (const guild of guilds) {
|
|
46
42
|
if (!guild)
|
|
47
43
|
continue;
|
|
48
|
-
(
|
|
49
|
-
client.logger.warn(`Registered ${commands.length} interaction
|
|
44
|
+
(_c = client.application) === null || _c === void 0 ? void 0 : _c.commands.set(commands, guild).then(() => {
|
|
45
|
+
client.logger.warn(`Registered ${commands.length} interaction command(s) for ${guild}.`);
|
|
50
46
|
}).catch(e => client.logger.error(e));
|
|
51
47
|
}
|
|
52
48
|
}
|
package/bin/reciple/version.d.ts
CHANGED
package/bin/reciple/version.js
CHANGED
|
@@ -3,16 +3,16 @@ 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.isSupportedVersion = exports.parseVersion = exports.
|
|
6
|
+
exports.isSupportedVersion = exports.parseVersion = exports.isValidVersion = exports.version = void 0;
|
|
7
7
|
const semver_1 = __importDefault(require("semver"));
|
|
8
8
|
exports.version = require('../../package.json').version;
|
|
9
|
-
function
|
|
9
|
+
function isValidVersion(ver) {
|
|
10
10
|
return semver_1.default.valid(semver_1.default.coerce(ver)) !== null;
|
|
11
11
|
}
|
|
12
|
-
exports.
|
|
12
|
+
exports.isValidVersion = isValidVersion;
|
|
13
13
|
function parseVersion(ver) {
|
|
14
14
|
var _a, _b;
|
|
15
|
-
if (!
|
|
15
|
+
if (!isValidVersion(ver))
|
|
16
16
|
throw new TypeError(`Invalid version: ${ver}`);
|
|
17
17
|
const [major, minor, patch] = (_b = (_a = `${semver_1.default.coerce(ver)}`) === null || _a === void 0 ? void 0 : _a.split('.')) !== null && _b !== void 0 ? _b : [];
|
|
18
18
|
return { major: parseInt(major), minor: parseInt(minor), patch: parseInt(patch) };
|
|
@@ -20,9 +20,9 @@ function parseVersion(ver) {
|
|
|
20
20
|
exports.parseVersion = parseVersion;
|
|
21
21
|
function isSupportedVersion(versionRange, supportedVersion) {
|
|
22
22
|
supportedVersion = supportedVersion || exports.version;
|
|
23
|
-
if (!
|
|
23
|
+
if (!isValidVersion(versionRange))
|
|
24
24
|
throw new TypeError(`Invalid version: ${versionRange}`);
|
|
25
|
-
if (!
|
|
25
|
+
if (!isValidVersion(supportedVersion))
|
|
26
26
|
throw new TypeError(`Invalid supported version: ${supportedVersion}`);
|
|
27
27
|
return semver_1.default.satisfies(supportedVersion, versionRange);
|
|
28
28
|
}
|
package/package.json
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
2
|
+
"name": "reciple",
|
|
3
|
+
"version": "1.5.0",
|
|
4
|
+
"description": "A Discord.js bot",
|
|
5
|
+
"author": "FalloutStudios",
|
|
6
|
+
"license": "GPL-3.0",
|
|
7
|
+
"main": "bin/index.js",
|
|
8
|
+
"bin": {
|
|
9
|
+
"reciple": "bin/bin.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"bin",
|
|
13
|
+
"resource",
|
|
14
|
+
"package.json",
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"clean": "rimraf bin",
|
|
20
|
+
"compile": "yarn clean && npx tsc",
|
|
21
|
+
"build": "yarn compile && npm un reciple -g && npm i ./ -g",
|
|
22
|
+
"build:publish": "yarn run build && yarn run changelog && yarn publish",
|
|
23
|
+
"test": "cd test && npx reciple",
|
|
24
|
+
"test:build": "yarn run build && yarn test:run"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"commander": "^9.3.0",
|
|
28
|
+
"discord.js": "^13.8.1",
|
|
29
|
+
"dotenv": "^16.0.1",
|
|
30
|
+
"fallout-utility": "^1.3.14",
|
|
31
|
+
"semver": "^7.3.7",
|
|
32
|
+
"wildcard-match": "^5.1.2",
|
|
33
|
+
"yaml": "^2.1.1"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "^18.0.0",
|
|
37
|
+
"@types/semver": "^7.3.10",
|
|
38
|
+
"typescript": "^4.7.4"
|
|
39
|
+
}
|
|
40
|
+
}
|
package/resource/reciple.yml
CHANGED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Permissions } from 'discord.js';
|
|
2
|
-
import { recipleCommandBuilders } from './modules';
|
|
3
|
-
import { Config } from './classes/Config';
|
|
4
|
-
export declare function commandPermissions(commandName: string, memberPermissions?: Permissions, configConmmandPermissions?: Config['permissions']['messageCommands'] | Config['permissions']['interactionCommands'], builder?: recipleCommandBuilders): boolean;
|