reciple 1.5.2 → 1.5.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/bin/index.d.ts CHANGED
@@ -5,6 +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/classes/builders/MessageCommandOptions';
8
9
  export * from './reciple/hasPermissions';
9
10
  export * from './reciple/flags';
10
11
  export * from './reciple/isIgnoredChannel';
package/bin/index.js CHANGED
@@ -25,6 +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/classes/builders/MessageCommandOptions"), exports);
28
29
  __exportStar(require("./reciple/hasPermissions"), exports);
29
30
  __exportStar(require("./reciple/flags"), exports);
30
31
  __exportStar(require("./reciple/isIgnoredChannel"), exports);
@@ -45,8 +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<void>;
49
- interactionCommandExecute(interaction: Interaction): Promise<void>;
50
- getMessage<T = any>(messageKey: string, defaultMessage?: T): T;
48
+ messageCommandExecute(message: Message, prefix?: string): Promise<void | RecipleMessageCommandExecute>;
49
+ interactionCommandExecute(interaction: Interaction): Promise<void | RecipleInteractionCommandExecute>;
50
+ getMessage<T = unknown>(messageKey: string, defaultMessage?: T): T;
51
51
  private _commandExecuteError;
52
52
  }
@@ -24,6 +24,7 @@ const version_1 = require("../version");
24
24
  const logger_1 = require("../logger");
25
25
  const discord_js_1 = require("discord.js");
26
26
  const modules_1 = require("../modules");
27
+ const MessageCommandOptions_1 = require("./builders/MessageCommandOptions");
27
28
  class RecipleClient extends discord_js_1.Client {
28
29
  constructor(options) {
29
30
  super(options);
@@ -95,7 +96,7 @@ class RecipleClient extends discord_js_1.Client {
95
96
  this.commands.INTERACTION_COMMANDS[command.name] = command;
96
97
  }
97
98
  else {
98
- this.logger.error(`Command "${(_a = command.name) !== null && _a !== void 0 ? _a : 'unknown'}" has an invalid builder.`);
99
+ this.logger.error(`Unknow command "${(_a = typeof command) !== null && _a !== void 0 ? _a : 'unknown'}".`);
99
100
  }
100
101
  return this;
101
102
  }
@@ -106,12 +107,12 @@ class RecipleClient extends discord_js_1.Client {
106
107
  this.on('interactionCreate', (interaction) => { this.interactionCommandExecute(interaction); });
107
108
  return this;
108
109
  }
109
- messageCommandExecute(message) {
110
+ messageCommandExecute(message, prefix) {
110
111
  var _a;
111
112
  return __awaiter(this, void 0, void 0, function* () {
112
- if (!message.content || !this.config.commands.messageCommand.enabled)
113
+ if (!message.content)
113
114
  return;
114
- const parseCommand = (0, fallout_utility_1.getCommand)(message.content, this.config.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
115
+ const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
115
116
  if (!(parseCommand === null || parseCommand === void 0 ? void 0 : parseCommand.command) || !parseCommand)
116
117
  return;
117
118
  const command = this.commands.MESSAGE_COMMANDS[parseCommand.command.toLowerCase()];
@@ -126,33 +127,34 @@ class RecipleClient extends discord_js_1.Client {
126
127
  const commandOptions = command.getCommandOptionValues(parseCommand);
127
128
  if (command.validateOptions) {
128
129
  if (commandOptions.some(o => o.invalid)) {
129
- yield message.reply(this.getMessage('invalidArguments', 'Invalid argument(s) given.'));
130
+ yield message.reply(this.getMessage('invalidArguments', 'Invalid argument(s) given.')).catch(err => this.logger.debug(err));
130
131
  return;
131
132
  }
132
133
  if (commandOptions.some(o => o.missing)) {
133
- yield message.reply(this.getMessage('notEnoughArguments', 'Not enough arguments.'));
134
+ yield message.reply(this.getMessage('notEnoughArguments', 'Not enough arguments.')).catch(err => this.logger.debug(err));
134
135
  return;
135
136
  }
136
137
  }
137
138
  const options = {
138
139
  message: message,
139
- options: commandOptions,
140
+ options: new MessageCommandOptions_1.MessageCommandOptions(commandOptions),
140
141
  command: parseCommand,
141
142
  builder: command,
142
143
  client: this
143
144
  };
144
145
  yield Promise.resolve(command.execute(options)).catch(err => this._commandExecuteError(err, options));
145
146
  this.emit('recipleMessageCommandCreate', options);
147
+ return options;
146
148
  }
147
149
  else {
148
- yield message.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch((err) => this.logger.error(err));
150
+ yield message.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(err => this.logger.debug(err));
149
151
  }
150
152
  });
151
153
  }
152
154
  interactionCommandExecute(interaction) {
153
155
  var _a;
154
156
  return __awaiter(this, void 0, void 0, function* () {
155
- if (!interaction || !interaction.isCommand() || !this.config.commands.interactionCommand.enabled)
157
+ if (!interaction || !interaction.isCommand())
156
158
  return;
157
159
  const command = this.commands.INTERACTION_COMMANDS[interaction.commandName];
158
160
  if (!command)
@@ -170,9 +172,10 @@ class RecipleClient extends discord_js_1.Client {
170
172
  };
171
173
  yield Promise.resolve(command.execute(options)).catch(err => this._commandExecuteError(err, options));
172
174
  this.emit('recipleInteractionCommandCreate', options);
175
+ return options;
173
176
  }
174
177
  else {
175
- yield interaction.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch((err) => this.logger.error(err));
178
+ yield interaction.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(err => this.logger.debug(err));
176
179
  }
177
180
  });
178
181
  }
@@ -189,12 +192,12 @@ class RecipleClient extends discord_js_1.Client {
189
192
  if (command === null || command === void 0 ? void 0 : command.message) {
190
193
  if (!this.config.commands.messageCommand.replyOnError)
191
194
  return;
192
- yield command.message.reply(this.getMessage('error', 'An error occurred.')).catch((e) => this.logger.error(e));
195
+ yield command.message.reply(this.getMessage('error', 'An error occurred.')).catch(err => this.logger.debug(err));
193
196
  }
194
197
  else if (command === null || command === void 0 ? void 0 : command.interaction) {
195
198
  if (!this.config.commands.interactionCommand.replyOnError)
196
199
  return;
197
- yield command.interaction.followUp(this.getMessage('error', 'An error occurred.')).catch((e) => this.logger.error(e));
200
+ yield command.interaction.followUp(this.getMessage('error', 'An error occurred.')).catch(err => this.logger.debug(err));
198
201
  }
199
202
  });
200
203
  }
@@ -8,7 +8,7 @@ export interface RecipleInteractionCommandExecute {
8
8
  client: RecipleClient;
9
9
  }
10
10
  export declare class InteractionCommandBuilder extends SlashCommandBuilder {
11
- readonly builder: string;
11
+ readonly builder = "INTERACTION_COMMAND";
12
12
  requiredPermissions: (PermissionFlags | PermissionString)[];
13
13
  allowExecuteInDM: boolean;
14
14
  execute: (options: RecipleInteractionCommandExecute) => void;
@@ -2,10 +2,11 @@ import { MessageCommandOptionBuilder } from './MessageCommandOptionBuilder';
2
2
  import { Message, PermissionFlags, PermissionString } from 'discord.js';
3
3
  import { Command } from 'fallout-utility';
4
4
  import { RecipleClient } from '../Client';
5
+ import { MessageCommandOptions } from './MessageCommandOptions';
5
6
  export declare type CommandMessage = Command;
6
7
  export interface RecipleMessageCommandExecute {
7
8
  message: Message;
8
- options: MessageCommandValidatedOption[];
9
+ options: MessageCommandOptions;
9
10
  command: CommandMessage;
10
11
  builder: MessageCommandBuilder;
11
12
  client: RecipleClient;
@@ -18,7 +19,7 @@ export interface MessageCommandValidatedOption {
18
19
  missing: boolean;
19
20
  }
20
21
  export declare class MessageCommandBuilder {
21
- readonly builder: string;
22
+ readonly builder = "MESSAGE_COMMAND";
22
23
  name: string;
23
24
  description: string;
24
25
  options: MessageCommandOptionBuilder[];
@@ -72,7 +72,7 @@ class MessageCommandBuilder {
72
72
  const required = this.options.filter(o => o.required);
73
73
  const optional = this.options.filter(o => !o.required);
74
74
  const allOptions = [...required, ...optional];
75
- let result = [];
75
+ const result = [];
76
76
  let i = 0;
77
77
  for (const option of allOptions) {
78
78
  const arg = args[i];
@@ -0,0 +1,8 @@
1
+ import { MessageCommandValidatedOption } from './MessageCommandBuilder';
2
+ export declare class MessageCommandOptions extends Array<MessageCommandValidatedOption> {
3
+ constructor(options: MessageCommandValidatedOption[]);
4
+ get(name: string, requied: true): MessageCommandValidatedOption;
5
+ get(name: string, requied?: boolean): MessageCommandValidatedOption | null;
6
+ getValue(name: string, requied: true): string;
7
+ getValue(name: string, requied?: boolean): string | null;
8
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessageCommandOptions = void 0;
4
+ class MessageCommandOptions extends Array {
5
+ constructor(options) {
6
+ super();
7
+ this.push(...options);
8
+ }
9
+ get(name, required) {
10
+ const option = this.find(o => o.name == name);
11
+ if (!(option === null || option === void 0 ? void 0 : option.value) == undefined && required)
12
+ throw new TypeError(`Can't find option named ${name}`);
13
+ return option !== null && option !== void 0 ? option : null;
14
+ }
15
+ getValue(name, requied) {
16
+ var _a;
17
+ const option = this.get(name, requied);
18
+ if (!(option === null || option === void 0 ? void 0 : option.value) && requied)
19
+ throw new TypeError(`Value of option named ${name} is undefined`);
20
+ return (_a = option === null || option === void 0 ? void 0 : option.value) !== null && _a !== void 0 ? _a : null;
21
+ }
22
+ }
23
+ exports.MessageCommandOptions = MessageCommandOptions;
@@ -18,7 +18,7 @@ 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, _b;
22
22
  return __awaiter(this, void 0, void 0, function* () {
23
23
  const response = { commands: [], modules: [] };
24
24
  const modulesDir = client.config.modulesFolder || './modules';
@@ -30,17 +30,17 @@ function loadModules(client) {
30
30
  return file.endsWith('.js') && (!file.startsWith('_') && !file.startsWith('.')) && !ignoredFiles.some(f => (0, wildcard_match_1.default)(f)(file));
31
31
  });
32
32
  for (const script of scripts) {
33
- const modulePath = path_1.default.resolve(modulesDir, script);
33
+ const modulePath = path_1.default.join(process.cwd(), modulesDir, script);
34
34
  const commands = [];
35
35
  let module_;
36
36
  try {
37
37
  const reqMod = require(modulePath);
38
- module_ = !!(reqMod === null || reqMod === void 0 ? void 0 : reqMod.default) ? reqMod.default : reqMod;
38
+ module_ = typeof (reqMod === null || reqMod === void 0 ? void 0 : reqMod.default) != 'undefined' ? reqMod.default : reqMod;
39
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)))
43
- throw new Error('Module versions is not defined or unsupported.');
43
+ throw new Error((_b = 'Module versions is not defined or unsupported; supported versions: ' + module_.versions) !== null && _b !== void 0 ? _b : 'none' + '; current version: ' + version_1.version);
44
44
  if (!(yield Promise.resolve(module_.onStart(client))))
45
45
  throw new Error(script + ' onStart is not defined or returned false.');
46
46
  if (module_.commands) {
@@ -55,13 +55,13 @@ function loadModules(client) {
55
55
  logger.error(error);
56
56
  continue;
57
57
  }
58
- response.commands = response.commands.concat(commands.filter((c) => {
58
+ response.commands.push(...commands.filter((c) => {
59
59
  if (!c.name) {
60
- logger.error(`A message command name is not defined in ${script}`);
60
+ logger.error(`A ${c.builder} command name is not defined in ${script}`);
61
61
  return false;
62
62
  }
63
63
  if (c.builder === 'MESSAGE_COMMAND' && c.options.length && c.options.some(o => !o.name)) {
64
- logger.error(`A message command option name is not defined in ${script}`);
64
+ logger.error(`A ${c.builder} option name is not defined in ${script}`);
65
65
  return false;
66
66
  }
67
67
  return true;
@@ -24,7 +24,7 @@ function registerInteractionCommands(client, cmds, overwriteGuilds) {
24
24
  undefined)) !== null && _d !== void 0 ? _d : cmd.requiredPermissions;
25
25
  cmd.setRequiredPermissions(permissions);
26
26
  client.commands.INTERACTION_COMMANDS[cmd.name] = cmd;
27
- client.logger.debug(`Set required permissions for ${cmd.name} to ${permissions.join(', ')}`);
27
+ client.logger.debug(`Set required permissions for ${cmd.name}`);
28
28
  return cmd.toJSON();
29
29
  }
30
30
  return c.toJSON();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reciple",
3
- "version": "1.5.2",
3
+ "version": "1.5.5",
4
4
  "description": "A Discord.js bot",
5
5
  "author": "FalloutStudios",
6
6
  "license": "GPL-3.0",