reciple 1.5.5 → 1.6.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/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,22 @@ 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() {
61
54
  return __awaiter(this, void 0, void 0, function* () {
62
- for (const module_ of this.modules) {
55
+ for (const module_ of this.modules.map(m => m.script)) {
63
56
  if (typeof (module_ === null || module_ === void 0 ? void 0 : module_.onLoad) === 'function')
64
57
  yield Promise.resolve(module_.onLoad(this));
65
58
  }
66
59
  this.logger.info(`${this.modules.length} modules loaded.`);
60
+ for (const command of this.modules.map(m => { var _a; return (_a = m.script.commands) !== null && _a !== void 0 ? _a : []; })[0]) {
61
+ this.addCommand(command);
62
+ }
63
+ this.logger.info(`${Object.keys(this.commands.MESSAGE_COMMANDS).length} message commands loaded.`);
64
+ this.logger.info(`${Object.keys(this.commands.INTERACTION_COMMANDS).length} interaction commands loaded.`);
67
65
  if (!this.config.commands.interactionCommand.registerCommands)
68
66
  return this;
69
67
  yield (0, registerInteractionCommands_1.registerInteractionCommands)(this, [...Object.values(this.commands.INTERACTION_COMMANDS), ...this.otherApplicationCommandData]);
@@ -73,7 +71,14 @@ class RecipleClient extends discord_js_1.Client {
73
71
  addModule(script, registerCommands = true) {
74
72
  var _a;
75
73
  return __awaiter(this, void 0, void 0, function* () {
76
- this.modules.push(script);
74
+ this.modules.push({
75
+ script,
76
+ info: {
77
+ filename: undefined,
78
+ versions: typeof script.versions == 'string' ? [script.versions] : script.versions,
79
+ path: undefined
80
+ }
81
+ });
77
82
  if (typeof (script === null || script === void 0 ? void 0 : script.onLoad) === 'function')
78
83
  yield Promise.resolve(script.onLoad(this));
79
84
  this.logger.info(`${this.modules.length} modules loaded.`);
@@ -110,7 +115,7 @@ class RecipleClient extends discord_js_1.Client {
110
115
  messageCommandExecute(message, prefix) {
111
116
  var _a;
112
117
  return __awaiter(this, void 0, void 0, function* () {
113
- if (!message.content)
118
+ if (!message.content || !this.isReady())
114
119
  return;
115
120
  const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
116
121
  if (!(parseCommand === null || parseCommand === void 0 ? void 0 : parseCommand.command) || !parseCommand)
@@ -154,12 +159,13 @@ class RecipleClient extends discord_js_1.Client {
154
159
  interactionCommandExecute(interaction) {
155
160
  var _a;
156
161
  return __awaiter(this, void 0, void 0, function* () {
157
- if (!interaction || !interaction.isCommand())
162
+ if (!interaction || !interaction.isCommand() || !this.isReady())
158
163
  return;
159
164
  const command = this.commands.INTERACTION_COMMANDS[interaction.commandName];
160
165
  if (!command)
161
166
  return;
162
167
  if ((0, hasPermissions_1.hasPermissions)(command.name, (_a = interaction.memberPermissions) !== null && _a !== void 0 ? _a : undefined, this.config.permissions.interactionCommands, command)) {
168
+ // TODO: Deprecated allowEcuteInDM
163
169
  if (!command.allowExecuteInDM && !interaction.inCachedGuild() || (0, isIgnoredChannel_1.isIgnoredChannel)(interaction.channelId, this.config.ignoredChannels))
164
170
  return;
165
171
  if (!command)
@@ -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;
@@ -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.5",
3
+ "version": "1.6.0",
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:run",
26
+ "test:start": "cd test && npx reciple"
25
27
  },
26
28
  "dependencies": {
27
29
  "commander": "^9.3.0",