reciple 1.5.4 → 1.6.1

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
@@ -12,7 +12,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
12
12
  var _a, _b;
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  const Config_1 = require("./reciple/classes/Config");
15
- const Client_1 = require("./reciple/classes/Client");
15
+ const RecipleClient_1 = require("./reciple/classes/RecipleClient");
16
16
  const fs_1 = require("fs");
17
17
  const version_1 = require("./reciple/version");
18
18
  const flags_1 = require("./reciple/flags");
@@ -29,7 +29,7 @@ if ((0, fs_1.readdirSync)('./').filter(f => !f.startsWith('.') && allowedFiles.i
29
29
  process.exit(0);
30
30
  }
31
31
  const config = new Config_1.RecipleConfig((_b = flags_1.flags.config) !== null && _b !== void 0 ? _b : './reciple.yml').parseConfig().getConfig();
32
- const client = new Client_1.RecipleClient(Object.assign({ config: config }, config.client));
32
+ const client = new RecipleClient_1.RecipleClient(Object.assign({ config: config }, config.client));
33
33
  (() => __awaiter(void 0, void 0, void 0, function* () {
34
34
  yield client.startModules();
35
35
  client.on('ready', () => __awaiter(void 0, void 0, void 0, function* () {
package/bin/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import discord from 'discord.js';
2
2
  export declare const discordjs: typeof discord;
3
- export * from './reciple/classes/Client';
3
+ export * from './reciple/classes/RecipleClient';
4
4
  export * from './reciple/classes/Config';
5
5
  export * from './reciple/classes/builders/InteractionCommandBuilder';
6
6
  export * from './reciple/classes/builders/MessageCommandBuilder';
package/bin/index.js CHANGED
@@ -20,7 +20,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.discordjs = void 0;
21
21
  const discord_js_1 = __importDefault(require("discord.js"));
22
22
  exports.discordjs = discord_js_1.default;
23
- __exportStar(require("./reciple/classes/Client"), exports);
23
+ __exportStar(require("./reciple/classes/RecipleClient"), exports);
24
24
  __exportStar(require("./reciple/classes/Config"), exports);
25
25
  __exportStar(require("./reciple/classes/builders/InteractionCommandBuilder"), exports);
26
26
  __exportStar(require("./reciple/classes/builders/MessageCommandBuilder"), exports);
@@ -3,8 +3,8 @@ import { interactionCommandBuilders } from '../registerInteractionCommands';
3
3
  import { MessageCommandBuilder, RecipleMessageCommandExecute } from './builders/MessageCommandBuilder';
4
4
  import { Logger as ILogger } from 'fallout-utility';
5
5
  import { Config } from './Config';
6
- import { ApplicationCommandDataResolvable, Awaitable, Client, ClientEvents, ClientOptions, Interaction, Message } from 'discord.js';
7
- import { recipleCommandBuilders, RecipleScript } from '../modules';
6
+ import { ApplicationCommandDataResolvable, Awaitable, Client, ClientEvents, ClientOptions, CommandInteraction, Interaction, Message } from 'discord.js';
7
+ import { recipleCommandBuilders, RecipleModule, RecipleScript } from '../modules';
8
8
  export interface RecipleClientOptions extends ClientOptions {
9
9
  config: Config;
10
10
  }
@@ -20,7 +20,7 @@ export interface RecipleClientEvents extends ClientEvents {
20
20
  recipleMessageCommandCreate: [command: RecipleMessageCommandExecute];
21
21
  recipleInteractionCommandCreate: [command: RecipleInteractionCommandExecute];
22
22
  }
23
- export interface RecipleClient extends Client {
23
+ export interface RecipleClient<Ready extends boolean = boolean> extends Client<Ready> {
24
24
  on<E extends keyof RecipleClientEvents>(event: E, listener: (...args: RecipleClientEvents[E]) => Awaitable<void>): this;
25
25
  on<E extends string | symbol>(event: Exclude<E, keyof RecipleClientEvents>, listener: (...args: any) => Awaitable<void>): this;
26
26
  once<E extends keyof RecipleClientEvents>(event: E, listener: (...args: RecipleClientEvents[E]) => Awaitable<void>): this;
@@ -31,22 +31,23 @@ export interface RecipleClient extends Client {
31
31
  off<E extends string | symbol>(event: Exclude<E, keyof RecipleClientEvents>, listener: (...args: any) => Awaitable<void>): this;
32
32
  removeAllListeners<E extends keyof RecipleClientEvents>(event?: E): this;
33
33
  removeAllListeners(event?: string | symbol): this;
34
+ isReady(): this is RecipleClient<true>;
34
35
  }
35
- export declare class RecipleClient extends Client {
36
+ export declare class RecipleClient<Ready extends boolean = boolean> extends Client<Ready> {
36
37
  config: Config;
37
38
  commands: RecipleClientCommands;
38
39
  otherApplicationCommandData: (interactionCommandBuilders | ApplicationCommandDataResolvable)[];
39
- modules: RecipleScript[];
40
+ modules: RecipleModule[];
40
41
  logger: ILogger;
41
42
  version: string;
42
43
  constructor(options: RecipleClientOptions);
43
- startModules(): Promise<RecipleClient>;
44
- loadModules(): Promise<RecipleClient>;
44
+ startModules(): Promise<RecipleClient<Ready>>;
45
+ loadModules(): Promise<RecipleClient<Ready>>;
45
46
  addModule(script: RecipleScript, registerCommands?: boolean): Promise<void>;
46
- addCommand(command: recipleCommandBuilders): RecipleClient;
47
- addCommandListeners(): RecipleClient;
47
+ addCommand(command: recipleCommandBuilders): RecipleClient<Ready>;
48
+ addCommandListeners(): RecipleClient<Ready>;
48
49
  messageCommandExecute(message: Message, prefix?: string): Promise<void | RecipleMessageCommandExecute>;
49
- interactionCommandExecute(interaction: Interaction): Promise<void | RecipleInteractionCommandExecute>;
50
+ interactionCommandExecute(interaction: Interaction | CommandInteraction): Promise<void | RecipleInteractionCommandExecute>;
50
51
  getMessage<T = unknown>(messageKey: string, defaultMessage?: T): T;
51
52
  private _commandExecuteError;
52
53
  }
@@ -46,24 +46,32 @@ class RecipleClient extends discord_js_1.Client {
46
46
  const modules = yield (0, modules_1.loadModules)(this);
47
47
  if (!modules)
48
48
  throw new Error('Failed to load modules.');
49
- this.modules = modules.modules.map(m => m.script);
50
- for (const command of modules.commands) {
51
- if (!command.name)
52
- continue;
53
- this.addCommand(command);
54
- }
55
- this.logger.info(`${Object.keys(this.commands.MESSAGE_COMMANDS).length} message commands loaded.`);
56
- this.logger.info(`${Object.keys(this.commands.INTERACTION_COMMANDS).length} interaction commands loaded.`);
49
+ this.modules = modules.modules;
57
50
  return this;
58
51
  });
59
52
  }
60
53
  loadModules() {
54
+ var _a, _b;
61
55
  return __awaiter(this, void 0, void 0, function* () {
62
- for (const module_ of this.modules) {
63
- if (typeof (module_ === null || module_ === void 0 ? void 0 : module_.onLoad) === 'function')
64
- yield Promise.resolve(module_.onLoad(this));
56
+ for (let m in this.modules) {
57
+ const module_ = this.modules[m];
58
+ if (typeof ((_a = module_.script) === null || _a === void 0 ? void 0 : _a.onLoad) === 'function') {
59
+ yield Promise.resolve(module_.script.onLoad(this)).catch(err => {
60
+ var _a;
61
+ this.logger.error(`Error loading ${(_a = module_.info.filename) !== null && _a !== void 0 ? _a : 'unknown module'}:`);
62
+ this.logger.error(err);
63
+ this.modules = this.modules.filter((r, i) => i.toString() !== m.toString());
64
+ });
65
+ }
66
+ if (typeof ((_b = module_.script) === null || _b === void 0 ? void 0 : _b.commands) !== 'undefined') {
67
+ for (const command of module_.script.commands) {
68
+ this.addCommand(command);
69
+ }
70
+ }
65
71
  }
66
72
  this.logger.info(`${this.modules.length} modules loaded.`);
73
+ this.logger.info(`${Object.keys(this.commands.MESSAGE_COMMANDS).length} message commands loaded.`);
74
+ this.logger.info(`${Object.keys(this.commands.INTERACTION_COMMANDS).length} interaction commands loaded.`);
67
75
  if (!this.config.commands.interactionCommand.registerCommands)
68
76
  return this;
69
77
  yield (0, registerInteractionCommands_1.registerInteractionCommands)(this, [...Object.values(this.commands.INTERACTION_COMMANDS), ...this.otherApplicationCommandData]);
@@ -73,7 +81,14 @@ class RecipleClient extends discord_js_1.Client {
73
81
  addModule(script, registerCommands = true) {
74
82
  var _a;
75
83
  return __awaiter(this, void 0, void 0, function* () {
76
- this.modules.push(script);
84
+ this.modules.push({
85
+ script,
86
+ info: {
87
+ filename: undefined,
88
+ versions: typeof script.versions == 'string' ? [script.versions] : script.versions,
89
+ path: undefined
90
+ }
91
+ });
77
92
  if (typeof (script === null || script === void 0 ? void 0 : script.onLoad) === 'function')
78
93
  yield Promise.resolve(script.onLoad(this));
79
94
  this.logger.info(`${this.modules.length} modules loaded.`);
@@ -110,7 +125,7 @@ class RecipleClient extends discord_js_1.Client {
110
125
  messageCommandExecute(message, prefix) {
111
126
  var _a;
112
127
  return __awaiter(this, void 0, void 0, function* () {
113
- if (!message.content)
128
+ if (!message.content || !this.isReady())
114
129
  return;
115
130
  const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
116
131
  if (!(parseCommand === null || parseCommand === void 0 ? void 0 : parseCommand.command) || !parseCommand)
@@ -154,12 +169,13 @@ class RecipleClient extends discord_js_1.Client {
154
169
  interactionCommandExecute(interaction) {
155
170
  var _a;
156
171
  return __awaiter(this, void 0, void 0, function* () {
157
- if (!interaction || !interaction.isCommand())
172
+ if (!interaction || !interaction.isCommand() || !this.isReady())
158
173
  return;
159
174
  const command = this.commands.INTERACTION_COMMANDS[interaction.commandName];
160
175
  if (!command)
161
176
  return;
162
177
  if ((0, hasPermissions_1.hasPermissions)(command.name, (_a = interaction.memberPermissions) !== null && _a !== void 0 ? _a : undefined, this.config.permissions.interactionCommands, command)) {
178
+ // TODO: Deprecated allowEcuteInDM
163
179
  if (!command.allowExecuteInDM && !interaction.inCachedGuild() || (0, isIgnoredChannel_1.isIgnoredChannel)(interaction.channelId, this.config.ignoredChannels))
164
180
  return;
165
181
  if (!command)
@@ -192,12 +208,12 @@ class RecipleClient extends discord_js_1.Client {
192
208
  if (command === null || command === void 0 ? void 0 : command.message) {
193
209
  if (!this.config.commands.messageCommand.replyOnError)
194
210
  return;
195
- yield command.message.reply(this.getMessage('error', 'An error occurred.')).catch(err => this.logger.debug(err));
211
+ yield command.message.reply(this.getMessage('error', 'An error occurred.')).catch(e => this.logger.debug(e));
196
212
  }
197
213
  else if (command === null || command === void 0 ? void 0 : command.interaction) {
198
214
  if (!this.config.commands.interactionCommand.replyOnError)
199
215
  return;
200
- yield command.interaction.followUp(this.getMessage('error', 'An error occurred.')).catch(err => this.logger.debug(err));
216
+ yield command.interaction.followUp(this.getMessage('error', 'An error occurred.')).catch(e => this.logger.debug(e));
201
217
  }
202
218
  });
203
219
  }
@@ -1,11 +1,11 @@
1
1
  import { CommandInteraction, PermissionFlags, PermissionString } from 'discord.js';
2
2
  import { SlashCommandBuilder } from '@discordjs/builders';
3
- import { RecipleClient } from '../Client';
3
+ import { RecipleClient } from '../RecipleClient';
4
4
  export interface RecipleInteractionCommandExecute {
5
5
  interaction: CommandInteraction;
6
6
  command: InteractionCommandBuilder;
7
7
  builder: InteractionCommandBuilder;
8
- client: RecipleClient;
8
+ client: RecipleClient<true>;
9
9
  }
10
10
  export declare class InteractionCommandBuilder extends SlashCommandBuilder {
11
11
  readonly builder = "INTERACTION_COMMAND";
@@ -13,6 +13,10 @@ export declare class InteractionCommandBuilder extends SlashCommandBuilder {
13
13
  allowExecuteInDM: boolean;
14
14
  execute: (options: RecipleInteractionCommandExecute) => void;
15
15
  setRequiredPermissions(requiredPermissions: (keyof PermissionFlags)[]): InteractionCommandBuilder;
16
+ /**
17
+ * TODO: Deprecated this
18
+ * @deprecated use `InteractionCommandBuilder.setDMPermission()` instead
19
+ */
16
20
  setAllowExecuteInDM(allowExecuteInDM: boolean): InteractionCommandBuilder;
17
21
  setExecute(execute: (options: RecipleInteractionCommandExecute) => void): InteractionCommandBuilder;
18
22
  }
@@ -16,6 +16,10 @@ class InteractionCommandBuilder extends builders_1.SlashCommandBuilder {
16
16
  this.requiredPermissions = requiredPermissions;
17
17
  return this;
18
18
  }
19
+ /**
20
+ * TODO: Deprecated this
21
+ * @deprecated use `InteractionCommandBuilder.setDMPermission()` instead
22
+ */
19
23
  setAllowExecuteInDM(allowExecuteInDM) {
20
24
  if (typeof allowExecuteInDM !== 'boolean')
21
25
  throw new Error('allowExecuteInDM must be a boolean.');
@@ -1,7 +1,7 @@
1
1
  import { MessageCommandOptionBuilder } from './MessageCommandOptionBuilder';
2
2
  import { Message, PermissionFlags, PermissionString } from 'discord.js';
3
3
  import { Command } from 'fallout-utility';
4
- import { RecipleClient } from '../Client';
4
+ import { RecipleClient } from '../RecipleClient';
5
5
  import { MessageCommandOptions } from './MessageCommandOptions';
6
6
  export declare type CommandMessage = Command;
7
7
  export interface RecipleMessageCommandExecute {
@@ -9,7 +9,7 @@ export interface RecipleMessageCommandExecute {
9
9
  options: MessageCommandOptions;
10
10
  command: CommandMessage;
11
11
  builder: MessageCommandBuilder;
12
- client: RecipleClient;
12
+ client: RecipleClient<true>;
13
13
  }
14
14
  export interface MessageCommandValidatedOption {
15
15
  name: string;
@@ -3,4 +3,6 @@ export declare class MessageCommandOptions extends Array<MessageCommandValidated
3
3
  constructor(options: MessageCommandValidatedOption[]);
4
4
  get(name: string, requied: true): MessageCommandValidatedOption;
5
5
  get(name: string, requied?: boolean): MessageCommandValidatedOption | null;
6
+ getValue(name: string, requied: true): string;
7
+ getValue(name: string, requied?: boolean): string | null;
6
8
  }
@@ -8,9 +8,16 @@ class MessageCommandOptions extends Array {
8
8
  }
9
9
  get(name, required) {
10
10
  const option = this.find(o => o.name == name);
11
- if (!option && required || (option === null || option === void 0 ? void 0 : option.value) == undefined && required)
11
+ if (!(option === null || option === void 0 ? void 0 : option.value) == undefined && required)
12
12
  throw new TypeError(`Can't find option named ${name}`);
13
13
  return option !== null && option !== void 0 ? option : null;
14
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
+ }
15
22
  }
16
23
  exports.MessageCommandOptions = MessageCommandOptions;
@@ -1,6 +1,6 @@
1
1
  import { InteractionCommandBuilder, RecipleInteractionCommandExecute } from './classes/builders/InteractionCommandBuilder';
2
2
  import { MessageCommandBuilder, RecipleMessageCommandExecute } from './classes/builders/MessageCommandBuilder';
3
- import { RecipleClient } from './classes/Client';
3
+ import { RecipleClient } from './classes/RecipleClient';
4
4
  export declare type recipleCommandBuilders = MessageCommandBuilder | InteractionCommandBuilder;
5
5
  export declare type recipleCommandBuildersExecute = RecipleInteractionCommandExecute | RecipleMessageCommandExecute;
6
6
  export declare type loadedModules = {
@@ -16,9 +16,9 @@ export declare class RecipleScript {
16
16
  export interface RecipleModule {
17
17
  script: RecipleScript;
18
18
  info: {
19
- filename: string;
19
+ filename?: string;
20
20
  versions: string[];
21
- path: string;
21
+ path?: string;
22
22
  };
23
23
  }
24
24
  export declare function loadModules(client: RecipleClient): Promise<loadedModules>;
@@ -1,6 +1,6 @@
1
1
  import { InteractionCommandBuilder } from './classes/builders/InteractionCommandBuilder';
2
2
  import { ApplicationCommandDataResolvable } from 'discord.js';
3
- import { RecipleClient } from './classes/Client';
3
+ import { RecipleClient } from './classes/RecipleClient';
4
4
  import { ContextMenuCommandBuilder, SlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandOptionsOnlyBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandSubcommandsOnlyBuilder } from '@discordjs/builders';
5
5
  export declare type interactionCommandBuilders = InteractionCommandBuilder | ContextMenuCommandBuilder | SlashCommandBuilder | SlashCommandSubcommandBuilder | SlashCommandOptionsOnlyBuilder | SlashCommandSubcommandGroupBuilder | SlashCommandSubcommandsOnlyBuilder;
6
6
  export declare function registerInteractionCommands(client: RecipleClient, cmds?: (interactionCommandBuilders | ApplicationCommandDataResolvable)[], overwriteGuilds?: string | string[]): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reciple",
3
- "version": "1.5.4",
3
+ "version": "1.6.1",
4
4
  "description": "A Discord.js bot",
5
5
  "author": "FalloutStudios",
6
6
  "license": "GPL-3.0",
@@ -8,6 +8,9 @@
8
8
  "bin": {
9
9
  "reciple": "bin/bin.js"
10
10
  },
11
+ "engines": {
12
+ "node": ">=16.9.0"
13
+ },
11
14
  "files": [
12
15
  "bin",
13
16
  "resource",
@@ -16,12 +19,11 @@
16
19
  "README.md"
17
20
  ],
18
21
  "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"
22
+ "clean": "rm -rf bin",
23
+ "build": "yarn clean && npx tsc && npm un reciple -g && npm i ./ -g",
24
+ "build:publish": "yarn run build && yarn publish",
25
+ "test": "yarn run build && yarn test:start",
26
+ "test:start": "cd test && npx reciple"
25
27
  },
26
28
  "dependencies": {
27
29
  "commander": "^9.3.0",