reciple 5.0.0-pre.5 → 5.0.0-pre.6

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/bin.js CHANGED
@@ -22,15 +22,18 @@ const flags_1 = require("./reciple/flags");
22
22
  const fallout_utility_1 = require("fallout-utility");
23
23
  const chalk_1 = __importDefault(require("chalk"));
24
24
  require("dotenv/config");
25
+ const discord_js_1 = require("discord.js");
26
+ const path_1 = __importDefault(require("path"));
25
27
  const allowedFiles = ['node_modules', 'reciple.yml', 'package.json'];
26
- if ((0, fs_1.readdirSync)('./').filter(f => !f.startsWith('.') && allowedFiles.indexOf(f)).length > 0 && !(0, fs_1.existsSync)((_a = flags_1.flags.config) !== null && _a !== void 0 ? _a : './reciple.yml')) {
28
+ const configPath = path_1.default.join(flags_1.cwd, './reciple.yml');
29
+ if ((0, fs_1.readdirSync)(flags_1.cwd).filter(f => !f.startsWith('.') && allowedFiles.indexOf(f)).length > 0 && !(0, fs_1.existsSync)((_a = flags_1.flags.config) !== null && _a !== void 0 ? _a : configPath)) {
27
30
  const ask = (_c = (_b = (flags_1.flags.yes ? 'y' : null)) !== null && _b !== void 0 ? _b : (0, fallout_utility_1.input)('This directory does not contain reciple.yml. Would you like to init axis here? [y/n] ')) !== null && _c !== void 0 ? _c : '';
28
31
  if (ask.toString().toLowerCase() !== 'y')
29
32
  process.exit(0);
30
33
  }
31
34
  let configParser;
32
35
  try {
33
- configParser = new RecipleConfig_1.RecipleConfig((_d = flags_1.flags.config) !== null && _d !== void 0 ? _d : './reciple.yml').parseConfig();
36
+ configParser = new RecipleConfig_1.RecipleConfig((_d = flags_1.flags.config) !== null && _d !== void 0 ? _d : configPath).parseConfig();
34
37
  }
35
38
  catch (err) {
36
39
  console.error(`${chalk_1.default.bold.red('Config Error')}: ${chalk_1.default.white(err.message)}`);
@@ -41,7 +44,7 @@ const client = new RecipleClient_1.RecipleClient(Object.assign({ config: config
41
44
  if (config.fileLogging.clientLogs)
42
45
  client.logger.info('Reciple Client v' + version_1.rawVersion + ' is starting...');
43
46
  (() => __awaiter(void 0, void 0, void 0, function* () {
44
- yield client.startModules();
47
+ yield client.startModules((0, discord_js_1.normalizeArray)(config.modulesFolder));
45
48
  client.on('ready', () => __awaiter(void 0, void 0, void 0, function* () {
46
49
  var _e;
47
50
  if (client.isClientLogsEnabled())
@@ -8,7 +8,7 @@ import { RecipleClientAddModuleOptions } from '../types/paramOptions';
8
8
  import { Logger as ILogger } from 'fallout-utility';
9
9
  import { Config } from './RecipleConfig';
10
10
  import { RecipleModule } from '../modules';
11
- import { ApplicationCommandData, Awaitable, ChatInputCommandInteraction, Client, ClientEvents, ClientOptions, Interaction, Message } from 'discord.js';
11
+ import { ApplicationCommandData, Awaitable, ChatInputCommandInteraction, Client, ClientEvents, ClientOptions, Interaction, Message, RestOrArray } from 'discord.js';
12
12
  /**
13
13
  * options for Reciple client
14
14
  */
@@ -64,9 +64,9 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
64
64
  constructor(options: RecipleClientOptions);
65
65
  /**
66
66
  * Load modules from modules folder
67
- * @param folder Modules folder
67
+ * @param folders List of folders that contains the modules you want to load
68
68
  */
69
- startModules(folder?: string): Promise<RecipleClient<Ready>>;
69
+ startModules(...folders: RestOrArray<string>): Promise<RecipleClient<Ready>>;
70
70
  /**
71
71
  * Execute `onLoad()` from client modules and register application commands if enabled
72
72
  */
@@ -8,6 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.RecipleClient = void 0;
13
16
  const MessageCommandBuilder_1 = require("./builders/MessageCommandBuilder");
@@ -24,12 +27,14 @@ const modules_1 = require("../modules");
24
27
  const logger_1 = require("../logger");
25
28
  const version_1 = require("../version");
26
29
  const discord_js_1 = require("discord.js");
30
+ const path_1 = __importDefault(require("path"));
31
+ const flags_1 = require("../flags");
27
32
  class RecipleClient extends discord_js_1.Client {
28
33
  /**
29
34
  * @param options Client options
30
35
  */
31
36
  constructor(options) {
32
- var _a, _b, _c;
37
+ var _a, _b, _c, _d;
33
38
  super(options);
34
39
  this.config = RecipleConfig_1.RecipleConfig.getDefaultConfig();
35
40
  this.commands = { slashCommands: {}, messageCommands: {} };
@@ -42,20 +47,26 @@ class RecipleClient extends discord_js_1.Client {
42
47
  throw new Error('Config is not defined.');
43
48
  this.config = Object.assign(Object.assign({}, this.config), ((_c = options.config) !== null && _c !== void 0 ? _c : {}));
44
49
  if (this.config.fileLogging.enabled)
45
- this.logger.logFile(this.config.fileLogging.logFilePath, false);
50
+ this.logger.logFile((_d = this.config.fileLogging.logFilePath) !== null && _d !== void 0 ? _d : path_1.default.join(flags_1.cwd, 'logs/latest.log'), false);
46
51
  }
47
52
  /**
48
53
  * Load modules from modules folder
49
- * @param folder Modules folder
54
+ * @param folders List of folders that contains the modules you want to load
50
55
  */
51
- startModules(folder) {
56
+ startModules(...folders) {
52
57
  return __awaiter(this, void 0, void 0, function* () {
53
- if (this.isClientLogsEnabled())
54
- this.logger.info(`Loading Modules from ${folder !== null && folder !== void 0 ? folder : this.config.modulesFolder}`);
55
- const modules = yield (0, modules_1.loadModules)(this, folder);
56
- if (!modules)
57
- throw new Error('Failed to load modules.');
58
- this.modules = modules.modules;
58
+ folders = (0, discord_js_1.normalizeArray)(folders).map(f => path_1.default.join(flags_1.cwd, f));
59
+ for (const folder of folders) {
60
+ if (this.isClientLogsEnabled())
61
+ this.logger.info(`Loading Modules from ${folder}`);
62
+ const modules = yield (0, modules_1.getModules)(this, folder).catch(() => null);
63
+ if (!modules) {
64
+ if (this.isClientLogsEnabled())
65
+ this.logger.error(`Failed to load modules from ${folder}`);
66
+ continue;
67
+ }
68
+ this.modules = modules.modules;
69
+ }
59
70
  return this;
60
71
  });
61
72
  }
@@ -49,7 +49,7 @@ export interface Config {
49
49
  [messageKey: string]: any;
50
50
  };
51
51
  ignoredFiles: string[];
52
- modulesFolder: string;
52
+ modulesFolder: string | string[];
53
53
  disableVersionCheck: boolean;
54
54
  version: string;
55
55
  }
@@ -19,7 +19,7 @@ class RecipleConfig {
19
19
  */
20
20
  constructor(configPath) {
21
21
  this.config = RecipleConfig.getDefaultConfig();
22
- this.configPath = './reciple.yml';
22
+ this.configPath = path_1.default.join(flags_1.cwd, 'reciple.yml');
23
23
  if (!configPath)
24
24
  throw new Error('Config path is not defined');
25
25
  this.configPath = configPath;
@@ -66,15 +66,10 @@ class RecipleConfig {
66
66
  * @param askIfNull Ask for token if the token is null/undefined
67
67
  */
68
68
  parseToken(askIfNull = true) {
69
- var _a, _b;
70
- let token = flags_1.token || null;
71
- if (!this.config && !token)
72
- return token;
73
- if (this.config && !((_a = this.config) === null || _a === void 0 ? void 0 : _a.token) && !token)
74
- return token || (askIfNull ? this.askToken() : null);
75
- token = token || ((_b = this.config) === null || _b === void 0 ? void 0 : _b.token) || null;
69
+ var _a;
70
+ let token = flags_1.token || ((_a = this.config) === null || _a === void 0 ? void 0 : _a.token) || null;
76
71
  if (!token)
77
- return token;
72
+ return token || (askIfNull ? this.askToken() : null);
78
73
  const envToken = token.toString().split(':');
79
74
  if (envToken.length === 2 && envToken[0].toLocaleLowerCase() === 'env' && envToken[1]) {
80
75
  token = process.env[envToken[1]] || null;
@@ -92,7 +87,7 @@ class RecipleConfig {
92
87
  * Ask for a token
93
88
  */
94
89
  askToken() {
95
- return flags_1.token || (0, fallout_utility_1.input)({ 'text': 'Bot Token >>> ', echo: '*', repeatIfEmpty: true, exitStrings: ['exit', 'quit', ''], sigint: true }) || null;
90
+ return flags_1.token || (0, fallout_utility_1.input)({ text: 'Bot Token >>> ', echo: '*', repeatIfEmpty: true, sigint: true }) || null;
96
91
  }
97
92
  /**
98
93
  * Get default config
@@ -1,3 +1,8 @@
1
+ import { Command } from 'commander';
2
+ /**
3
+ * Commander
4
+ */
5
+ export declare const commander: Command;
1
6
  /**
2
7
  * Used flags
3
8
  */
@@ -6,3 +11,7 @@ export declare const flags: import("commander").OptionValues;
6
11
  * Temporary token flag
7
12
  */
8
13
  export declare const token: string | undefined;
14
+ /**
15
+ * Current working directory
16
+ */
17
+ export declare const cwd: string;
@@ -1,22 +1,35 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.token = exports.flags = void 0;
6
+ exports.cwd = exports.token = exports.flags = exports.commander = void 0;
4
7
  const version_1 = require("./version");
5
8
  const commander_1 = require("commander");
9
+ const path_1 = __importDefault(require("path"));
6
10
  /**
7
- * Used flags
11
+ * Commander
8
12
  */
9
- exports.flags = new commander_1.Command()
13
+ exports.commander = new commander_1.Command()
10
14
  .name('reciple')
11
15
  .description('Reciple.js - Discord.js handler cli')
12
16
  .version(`v${version_1.rawVersion}`, '-v, --version')
17
+ .argument('[current-working-directory]', 'Change the current working directory')
13
18
  .option('-t, --token <token>', 'Replace used bot token')
14
19
  .option('-c, --config <config>', 'Change path to config file')
15
20
  .option('-D, --debugmode', 'Enabled debug mode')
16
21
  .option('-y, --yes', 'Automatically agree to Reciple confirmation prompts')
17
22
  .option('-v, --version', 'Display version')
18
- .parse().opts();
23
+ .parse();
24
+ /**
25
+ * Used flags
26
+ */
27
+ exports.flags = exports.commander.opts();
19
28
  /**
20
29
  * Temporary token flag
21
30
  */
22
31
  exports.token = exports.flags.token;
32
+ /**
33
+ * Current working directory
34
+ */
35
+ exports.cwd = path_1.default.join(process.cwd(), exports.commander.args[0] || '.');
@@ -29,4 +29,4 @@ export interface RecipleModule {
29
29
  * @param client Reciple client
30
30
  * @param folder Modules folder
31
31
  */
32
- export declare function loadModules(client: RecipleClient, folder?: string): Promise<LoadedModules>;
32
+ export declare function getModules(client: RecipleClient, folder?: string): Promise<LoadedModules>;
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.loadModules = void 0;
15
+ exports.getModules = void 0;
16
16
  const builders_1 = require("./types/builders");
17
17
  const version_1 = require("./version");
18
18
  const fs_1 = require("fs");
@@ -24,11 +24,11 @@ const discord_js_1 = require("discord.js");
24
24
  * @param client Reciple client
25
25
  * @param folder Modules folder
26
26
  */
27
- function loadModules(client, folder) {
27
+ function getModules(client, folder) {
28
28
  var _a;
29
29
  return __awaiter(this, void 0, void 0, function* () {
30
30
  const response = { commands: [], modules: [] };
31
- const modulesDir = client.config.modulesFolder || folder || './modules';
31
+ const modulesDir = folder || 'modules';
32
32
  if (!(0, fs_1.existsSync)(modulesDir))
33
33
  (0, fs_1.mkdirSync)(modulesDir, { recursive: true });
34
34
  const ignoredFiles = (client.config.ignoredFiles || []).map(file => file.endsWith('.js') ? file : `${file}.js`);
@@ -36,7 +36,7 @@ function loadModules(client, folder) {
36
36
  return file.endsWith('.js') && (!file.startsWith('_') && !file.startsWith('.')) && !ignoredFiles.some(f => (0, wildcard_match_1.default)(f)(file));
37
37
  });
38
38
  for (const script of scripts) {
39
- const modulePath = path_1.default.join(process.cwd(), modulesDir, script);
39
+ const modulePath = path_1.default.join(modulesDir, script);
40
40
  const commands = [];
41
41
  let module_;
42
42
  try {
@@ -91,4 +91,4 @@ function loadModules(client, folder) {
91
91
  return response;
92
92
  });
93
93
  }
94
- exports.loadModules = loadModules;
94
+ exports.getModules = getModules;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reciple",
3
- "version": "5.0.0-pre.5",
3
+ "version": "5.0.0-pre.6",
4
4
  "bin": "bin/bin.js",
5
5
  "license": "GPL-3.0",
6
6
  "main": "bin/index.js",
@@ -60,7 +60,7 @@ fileLogging:
60
60
  # stringify logged JSONs
61
61
  stringifyLoggedJSON: false
62
62
  # log file path
63
- logFilePath: './logs/latest.log'
63
+ logFilePath:
64
64
 
65
65
  # Client options
66
66
  # Learn more about client options at https://discord.js.org/#/docs/discord.js/main/typedef/ClientOptions