reciple 1.0.2 → 1.0.5
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/README.md +4 -1
- package/bin/reciple/classes/Client.d.ts +1 -0
- package/bin/reciple/classes/Client.js +37 -12
- package/bin/reciple/classes/Config.d.ts +4 -0
- package/bin/reciple/classes/Config.js +9 -1
- package/bin/reciple/commandPermissions.d.ts +1 -1
- package/bin/reciple/commandPermissions.js +4 -4
- package/bin/reciple/flags.d.ts +1 -0
- package/bin/reciple/flags.js +3 -3
- package/bin/reciple/isIgnoredChannel.d.ts +2 -0
- package/bin/reciple/isIgnoredChannel.js +13 -0
- package/bin/reciple/modules.d.ts +2 -2
- package/package.json +1 -1
- package/resource/reciple.yml +5 -1
package/README.md
CHANGED
|
@@ -31,4 +31,5 @@ export declare class RecipleClient extends Client {
|
|
|
31
31
|
addCommandListeners(): RecipleClient;
|
|
32
32
|
messageCommandExecute(message: Message): Promise<RecipleClient>;
|
|
33
33
|
interactionCommandExecute(interaction: Interaction): Promise<RecipleClient>;
|
|
34
|
+
private _commandExecuteError;
|
|
34
35
|
}
|
|
@@ -17,6 +17,7 @@ const logger_1 = require("../logger");
|
|
|
17
17
|
const modules_1 = require("../modules");
|
|
18
18
|
const version_1 = require("../version");
|
|
19
19
|
const commandPermissions_1 = require("../commandPermissions");
|
|
20
|
+
const isIgnoredChannel_1 = require("../isIgnoredChannel");
|
|
20
21
|
class RecipleClient extends discord_js_1.Client {
|
|
21
22
|
constructor(options) {
|
|
22
23
|
super(options);
|
|
@@ -75,18 +76,18 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
75
76
|
return this;
|
|
76
77
|
}
|
|
77
78
|
messageCommandExecute(message) {
|
|
78
|
-
var _a, _b, _c, _d, _e;
|
|
79
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
79
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
if (!message.content)
|
|
81
|
+
if (!message.content || !((_a = this.config) === null || _a === void 0 ? void 0 : _a.commands.messageCommand.enabled))
|
|
81
82
|
return this;
|
|
82
|
-
const parseCommand = (0, fallout_utility_1.getCommand)(message.content, ((
|
|
83
|
+
const parseCommand = (0, fallout_utility_1.getCommand)(message.content, ((_b = this.config) === null || _b === void 0 ? void 0 : _b.prefix) || '!', ((_c = this.config) === null || _c === void 0 ? void 0 : _c.commands.messageCommand.commandArgumentSeparator) || ' ');
|
|
83
84
|
if (parseCommand && parseCommand.command) {
|
|
84
85
|
const command = this.commands.MESSAGE_COMMANDS[parseCommand.command];
|
|
85
|
-
if (command && (0, commandPermissions_1.commandPermissions)(command.name, ((
|
|
86
|
-
if (!command.allowExecuteInDM && message.channel.type === 'DM' || !command.allowExecuteByBots && (message.author.bot || message.author.system))
|
|
86
|
+
if (command && (0, commandPermissions_1.commandPermissions)(command.name, ((_d = message.member) === null || _d === void 0 ? void 0 : _d.permissions) || null, (_e = this.config) === null || _e === void 0 ? void 0 : _e.permissions.messageCommands)) {
|
|
87
|
+
if (!command.allowExecuteInDM && message.channel.type === 'DM' || !command.allowExecuteByBots && (message.author.bot || message.author.system) || (0, isIgnoredChannel_1.isIgnoredChannel)(message.channelId, (_f = this.config) === null || _f === void 0 ? void 0 : _f.ignoredChannels))
|
|
87
88
|
return this;
|
|
88
89
|
if (command.validateOptions && !command.getCommandOptionValues(parseCommand)) {
|
|
89
|
-
yield message.reply(((
|
|
90
|
+
yield message.reply(((_g = this.config) === null || _g === void 0 ? void 0 : _g.messages.notEnoughArguments) || 'Not enough arguments.').catch((err) => this.logger.error(err));
|
|
90
91
|
return this;
|
|
91
92
|
}
|
|
92
93
|
const options = {
|
|
@@ -95,7 +96,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
95
96
|
builder: command,
|
|
96
97
|
client: this
|
|
97
98
|
};
|
|
98
|
-
yield Promise.resolve(command.execute(options));
|
|
99
|
+
yield Promise.resolve(command.execute(options)).catch(err => this._commandExecuteError(err, options));
|
|
99
100
|
this.emit('recipleMessageCommandCreate', options);
|
|
100
101
|
}
|
|
101
102
|
}
|
|
@@ -103,13 +104,13 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
103
104
|
});
|
|
104
105
|
}
|
|
105
106
|
interactionCommandExecute(interaction) {
|
|
106
|
-
var _a;
|
|
107
|
+
var _a, _b, _c;
|
|
107
108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
-
if (!interaction || !interaction.isCommand())
|
|
109
|
+
if (!interaction || !interaction.isCommand() || !((_a = this.config) === null || _a === void 0 ? void 0 : _a.commands.interactionCommand.enabled))
|
|
109
110
|
return this;
|
|
110
111
|
const command = this.commands.INTERACTION_COMMANDS[interaction.commandName];
|
|
111
|
-
if (command && (0, commandPermissions_1.commandPermissions)(command.name, interaction.memberPermissions, (
|
|
112
|
-
if (!command.allowExecuteInDM && interaction.member === null)
|
|
112
|
+
if (command && (0, commandPermissions_1.commandPermissions)(command.name, interaction.memberPermissions, (_b = this.config) === null || _b === void 0 ? void 0 : _b.permissions.interactionCommands)) {
|
|
113
|
+
if (!command.allowExecuteInDM && interaction.member === null || (0, isIgnoredChannel_1.isIgnoredChannel)(interaction.channelId, (_c = this.config) === null || _c === void 0 ? void 0 : _c.ignoredChannels))
|
|
113
114
|
return this;
|
|
114
115
|
const options = {
|
|
115
116
|
interaction: interaction,
|
|
@@ -117,11 +118,35 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
117
118
|
builder: command,
|
|
118
119
|
client: this
|
|
119
120
|
};
|
|
120
|
-
yield Promise.resolve(command.execute(options));
|
|
121
|
+
yield Promise.resolve(command.execute(options)).catch(err => this._commandExecuteError(err, options));
|
|
121
122
|
this.emit('recipleInteractionCommandCreate', options);
|
|
122
123
|
}
|
|
123
124
|
return this;
|
|
124
125
|
});
|
|
125
126
|
}
|
|
127
|
+
_commandExecuteError(err, command) {
|
|
128
|
+
var _a, _b, _c, _d, _e;
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
this.logger.error(`An error occured executing ${command.builder.type == 'MESSAGE_COMMAND' ? 'message' : 'interaction'} command "${command.builder.name}"`);
|
|
131
|
+
this.logger.error(err);
|
|
132
|
+
if (!err || !command)
|
|
133
|
+
return;
|
|
134
|
+
if (command === null || command === void 0 ? void 0 : command.message) {
|
|
135
|
+
if (!((_a = this.config) === null || _a === void 0 ? void 0 : _a.commands.messageCommand.replyOnError))
|
|
136
|
+
return;
|
|
137
|
+
yield command.message.reply(((_b = this.config) === null || _b === void 0 ? void 0 : _b.messages.error) || 'An error occured.').catch((e) => this.logger.error(e));
|
|
138
|
+
}
|
|
139
|
+
else if (command === null || command === void 0 ? void 0 : command.interaction) {
|
|
140
|
+
if (!((_c = this.config) === null || _c === void 0 ? void 0 : _c.commands.interactionCommand.replyOnError))
|
|
141
|
+
return;
|
|
142
|
+
if (!(command === null || command === void 0 ? void 0 : command.interaction.deferred)) {
|
|
143
|
+
yield command.interaction.reply(((_d = this.config) === null || _d === void 0 ? void 0 : _d.messages.error) || 'An error occured.').catch((e) => this.logger.error(e));
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
yield command.interaction.editReply(((_e = this.config) === null || _e === void 0 ? void 0 : _e.messages.error) || 'An error occured.').catch((e) => this.logger.error(e));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
126
151
|
}
|
|
127
152
|
exports.RecipleClient = RecipleClient;
|
|
@@ -5,10 +5,12 @@ export interface Config {
|
|
|
5
5
|
commands: {
|
|
6
6
|
messageCommand: {
|
|
7
7
|
enabled: boolean;
|
|
8
|
+
replyOnError: boolean;
|
|
8
9
|
commandArgumentSeparator: string;
|
|
9
10
|
};
|
|
10
11
|
interactionCommand: {
|
|
11
12
|
enabled: boolean;
|
|
13
|
+
replyOnError: boolean;
|
|
12
14
|
registerCommands: boolean;
|
|
13
15
|
guilds: string[] | string;
|
|
14
16
|
};
|
|
@@ -43,6 +45,7 @@ export interface Config {
|
|
|
43
45
|
[key: string]: MessageOptions | string;
|
|
44
46
|
};
|
|
45
47
|
modulesFolder: string;
|
|
48
|
+
version?: string;
|
|
46
49
|
}
|
|
47
50
|
export declare class RecipleConfig {
|
|
48
51
|
config?: Config;
|
|
@@ -51,5 +54,6 @@ export declare class RecipleConfig {
|
|
|
51
54
|
parseConfig(): RecipleConfig;
|
|
52
55
|
getConfig(): Config;
|
|
53
56
|
parseToken(askIfNull?: boolean): string | null;
|
|
57
|
+
private isSupportedConfig;
|
|
54
58
|
private askToken;
|
|
55
59
|
}
|
|
@@ -9,6 +9,7 @@ const fs_1 = require("fs");
|
|
|
9
9
|
const flags_1 = require("../flags");
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
11
|
const yaml_1 = __importDefault(require("yaml"));
|
|
12
|
+
const version_1 = require("../version");
|
|
12
13
|
class RecipleConfig {
|
|
13
14
|
constructor(configPath) {
|
|
14
15
|
this.configPath = './reciple.yml';
|
|
@@ -17,11 +18,12 @@ class RecipleConfig {
|
|
|
17
18
|
this.configPath = configPath;
|
|
18
19
|
}
|
|
19
20
|
parseConfig() {
|
|
21
|
+
var _a;
|
|
20
22
|
if (!(0, fs_1.existsSync)(this.configPath)) {
|
|
21
23
|
const defaultConfigPath = path_1.default.join(__dirname, '../../../resource/reciple.yml');
|
|
22
24
|
if (!(0, fs_1.existsSync)(defaultConfigPath))
|
|
23
25
|
throw new Error('Default Config file not found. Please reinstall Reciple.');
|
|
24
|
-
const defaultConfig = (0, fs_1.readFileSync)(defaultConfigPath, 'utf-8');
|
|
26
|
+
const defaultConfig = (0, fallout_utility_1.replaceAll)((0, fs_1.readFileSync)(defaultConfigPath, 'utf-8'), 'VERSION', version_1.version);
|
|
25
27
|
(0, fs_1.writeFileSync)(this.configPath, defaultConfig, 'utf-8');
|
|
26
28
|
if (!(0, fs_1.existsSync)(this.configPath))
|
|
27
29
|
throw new Error('Failed to create config file.');
|
|
@@ -36,6 +38,8 @@ class RecipleConfig {
|
|
|
36
38
|
throw new Error('Failed to read config file.');
|
|
37
39
|
const config = (0, fs_1.readFileSync)(this.configPath, 'utf-8');
|
|
38
40
|
this.config = yaml_1.default.parse(config);
|
|
41
|
+
if (!this.isSupportedConfig())
|
|
42
|
+
throw new Error('Unsupported config version. Your config version: ' + (((_a = this.config) === null || _a === void 0 ? void 0 : _a.version) || 'No version specified.') + ', Reciple version: ' + version_1.version);
|
|
39
43
|
return this;
|
|
40
44
|
}
|
|
41
45
|
getConfig() {
|
|
@@ -61,6 +65,10 @@ class RecipleConfig {
|
|
|
61
65
|
}
|
|
62
66
|
return token || (askIfNull ? this.askToken() : null);
|
|
63
67
|
}
|
|
68
|
+
isSupportedConfig() {
|
|
69
|
+
var _a;
|
|
70
|
+
return (((_a = this.config) === null || _a === void 0 ? void 0 : _a.version) && this.config.version != version_1.version) ? false : true;
|
|
71
|
+
}
|
|
64
72
|
askToken() {
|
|
65
73
|
return flags_1.token || (0, fallout_utility_1.input)({ 'text': 'Bot Token >>> ', echo: '*', repeatIfEmpty: true, exitStrings: ['exit', 'quit', ''], sigint: true }) || null;
|
|
66
74
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Permissions } from "discord.js";
|
|
2
2
|
import { Config } from "./classes/Config";
|
|
3
|
-
export declare function commandPermissions(commandName: string,
|
|
3
|
+
export declare function commandPermissions(commandName: string, memberPermissions: Permissions | null, configConmmandPermissions?: Config['permissions']['messageCommands'] | Config['permissions']['interactionCommands']): boolean;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.commandPermissions = void 0;
|
|
4
|
-
function commandPermissions(commandName,
|
|
5
|
-
if (!(
|
|
4
|
+
function commandPermissions(commandName, memberPermissions, configConmmandPermissions) {
|
|
5
|
+
if (!(configConmmandPermissions === null || configConmmandPermissions === void 0 ? void 0 : configConmmandPermissions.enabled))
|
|
6
6
|
return true;
|
|
7
|
-
const command =
|
|
7
|
+
const command = configConmmandPermissions.commands.find(c => c.command.toLowerCase() === commandName.toLowerCase());
|
|
8
8
|
if (!command)
|
|
9
9
|
return true;
|
|
10
10
|
if (!command.permissions.length)
|
|
11
11
|
return true;
|
|
12
|
-
return
|
|
12
|
+
return memberPermissions ? memberPermissions.has(command.permissions) : false;
|
|
13
13
|
}
|
|
14
14
|
exports.commandPermissions = commandPermissions;
|
package/bin/reciple/flags.d.ts
CHANGED
package/bin/reciple/flags.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.token = void 0;
|
|
3
|
+
exports.token = exports.flags = void 0;
|
|
4
4
|
const commander_1 = require("commander");
|
|
5
|
-
|
|
5
|
+
exports.flags = commander_1.program
|
|
6
6
|
.option('-t, --token <token>', 'Replace used bot token')
|
|
7
7
|
.parse().opts();
|
|
8
|
-
exports.token = flags.token;
|
|
8
|
+
exports.token = exports.flags.token;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isIgnoredChannel = void 0;
|
|
4
|
+
function isIgnoredChannel(channelId, ignoredChannelsConfig) {
|
|
5
|
+
if (!(ignoredChannelsConfig === null || ignoredChannelsConfig === void 0 ? void 0 : ignoredChannelsConfig.enabled))
|
|
6
|
+
return false;
|
|
7
|
+
if (ignoredChannelsConfig.channels.includes(channelId) && !ignoredChannelsConfig.convertToAllowList)
|
|
8
|
+
return false;
|
|
9
|
+
if (!ignoredChannelsConfig.channels.includes(channelId) && ignoredChannelsConfig.convertToAllowList)
|
|
10
|
+
return false;
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
exports.isIgnoredChannel = isIgnoredChannel;
|
package/bin/reciple/modules.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export declare type loadedModules = {
|
|
|
9
9
|
export interface RecipleScript {
|
|
10
10
|
versions: string | string[];
|
|
11
11
|
commands?: (MessageCommandBuilder | InteractionCommandBuilder)[];
|
|
12
|
-
onLoad?: (reciple: RecipleClient) => void
|
|
13
|
-
onStart: (reciple: RecipleClient) => boolean
|
|
12
|
+
onLoad?: (reciple: RecipleClient) => void | Promise<void>;
|
|
13
|
+
onStart: (reciple: RecipleClient) => boolean | Promise<boolean>;
|
|
14
14
|
}
|
|
15
15
|
export interface RecipleModule {
|
|
16
16
|
script: RecipleScript;
|
package/package.json
CHANGED
package/resource/reciple.yml
CHANGED
|
@@ -4,9 +4,11 @@ prefix: '!'
|
|
|
4
4
|
commands:
|
|
5
5
|
messageCommand:
|
|
6
6
|
enabled: true
|
|
7
|
+
replyOnError: false
|
|
7
8
|
commandArgumentSeparator: ' '
|
|
8
9
|
interactionCommand:
|
|
9
10
|
enabled: true
|
|
11
|
+
replyOnError: false
|
|
10
12
|
registerCommands: true
|
|
11
13
|
guilds: []
|
|
12
14
|
|
|
@@ -45,4 +47,6 @@ messages:
|
|
|
45
47
|
noPermission: 'You do not have permission to use this command.'
|
|
46
48
|
notEnoughArguments: 'Not enough arguments.'
|
|
47
49
|
|
|
48
|
-
modulesFolder: 'modules'
|
|
50
|
+
modulesFolder: 'modules'
|
|
51
|
+
|
|
52
|
+
version: VERSION
|