reciple 5.6.0 → 6.0.0-dev.10

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.
Files changed (37) hide show
  1. package/dist/cjs/bin.js +13 -10
  2. package/dist/cjs/index.js +8 -7
  3. package/dist/cjs/reciple/classes/RecipleClient.js +90 -184
  4. package/dist/cjs/reciple/classes/RecipleConfig.js +9 -2
  5. package/dist/cjs/reciple/classes/RecipleModule.js +94 -0
  6. package/dist/cjs/reciple/classes/builders/MessageCommandBuilder.js +7 -5
  7. package/dist/cjs/reciple/classes/builders/SlashCommandBuilder.js +12 -23
  8. package/dist/cjs/reciple/classes/managers/ApplicationCommandManager.js +136 -0
  9. package/dist/cjs/reciple/classes/managers/ClientCommandManager.js +62 -0
  10. package/dist/cjs/reciple/classes/managers/ClientModuleManager.js +167 -0
  11. package/dist/cjs/reciple/classes/{CommandCooldownManager.js → managers/CommandCooldownManager.js} +15 -6
  12. package/dist/cjs/reciple/classes/{MessageCommandOptionManager.js → managers/MessageCommandOptionManager.js} +0 -0
  13. package/dist/cjs/reciple/permissions.js +3 -4
  14. package/dist/cjs/reciple/types/builders.js +6 -6
  15. package/dist/cjs/reciple/util.js +44 -1
  16. package/dist/types/index.d.ts +8 -7
  17. package/dist/types/reciple/classes/RecipleClient.d.ts +17 -65
  18. package/dist/types/reciple/classes/RecipleModule.d.ts +56 -0
  19. package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +7 -7
  20. package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +17 -17
  21. package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +15 -0
  22. package/dist/types/reciple/classes/managers/ClientCommandManager.d.ts +37 -0
  23. package/dist/types/reciple/classes/managers/ClientModuleManager.d.ts +19 -0
  24. package/dist/types/reciple/classes/{CommandCooldownManager.d.ts → managers/CommandCooldownManager.d.ts} +4 -3
  25. package/dist/types/reciple/classes/{MessageCommandOptionManager.d.ts → managers/MessageCommandOptionManager.d.ts} +1 -1
  26. package/dist/types/reciple/types/builders.d.ts +19 -19
  27. package/dist/types/reciple/types/commands.d.ts +12 -12
  28. package/dist/types/reciple/types/paramOptions.d.ts +6 -32
  29. package/dist/types/reciple/util.d.ts +10 -0
  30. package/package.json +30 -24
  31. package/dist/cjs/reciple/logger.js +0 -35
  32. package/dist/cjs/reciple/modules.js +0 -113
  33. package/dist/cjs/reciple/registerApplicationCommands.js +0 -49
  34. package/dist/types/reciple/logger.d.ts +0 -8
  35. package/dist/types/reciple/modules.d.ts +0 -64
  36. package/dist/types/reciple/registerApplicationCommands.d.ts +0 -9
  37. package/docs/README.md +0 -1
@@ -1,37 +1,6 @@
1
- import { ApplicationCommandBuilder } from '../registerApplicationCommands';
2
- import { ApplicationCommandData, PermissionsBitField } from 'discord.js';
3
1
  import { ConfigCommandPermissions } from '../classes/RecipleConfig';
4
- import { RecipleModule, RecipleScript } from '../modules';
5
- import { RecipleClient } from '../classes/RecipleClient';
2
+ import { PermissionsBitField } from 'discord.js';
6
3
  import { AnyCommandBuilder } from './builders';
7
- export interface RecipleClientAddModuleOptions {
8
- /**
9
- * The module script
10
- */
11
- script: RecipleScript;
12
- /**
13
- * Register application commands if possible
14
- */
15
- registerApplicationCommands?: boolean;
16
- /**
17
- * Module optional info
18
- */
19
- moduleInfo?: RecipleModule["info"];
20
- }
21
- export interface RegisterApplicationCommandsOptions {
22
- /**
23
- * Bot client
24
- */
25
- client: RecipleClient;
26
- /**
27
- * Commands to register
28
- */
29
- commands: (ApplicationCommandData | ApplicationCommandBuilder)[];
30
- /**
31
- * Set guild to not register commands globally
32
- */
33
- guilds?: string | string[];
34
- }
35
4
  export interface UserHasCommandPermissionsOptions {
36
5
  /**
37
6
  * Command builder
@@ -49,3 +18,8 @@ export interface UserHasCommandPermissionsOptions {
49
18
  commands: ConfigCommandPermissions[];
50
19
  };
51
20
  }
21
+ export interface ClientModuleManagerGetModulesFromFilesOptions {
22
+ files: string[];
23
+ disabeVersionCheck?: boolean;
24
+ dontSkipError?: boolean;
25
+ }
@@ -1,3 +1,5 @@
1
+ import { Logger } from 'fallout-utility';
2
+ import { AnyCommandBuilder } from './types/builders';
1
3
  /**
2
4
  * Check if an object is a class
3
5
  * @param object Object to identify
@@ -8,3 +10,11 @@ export declare function isClass<T = any>(object: any): object is T;
8
10
  * @param content Warning content
9
11
  */
10
12
  export declare function deprecationWarning(content: string | Error): void;
13
+ export declare function validateCommandBuilder(command: AnyCommandBuilder): boolean;
14
+ /**
15
+ * Create new logger
16
+ * @param stringifyJSON stringify json objects in console
17
+ * @param debugmode display debug messages
18
+ * @param colorizeMessage add logger colours to messages
19
+ */
20
+ export declare function createLogger(stringifyJSON: boolean, debugmode?: boolean, colorizeMessage?: boolean): Logger;
package/package.json CHANGED
@@ -1,19 +1,23 @@
1
1
  {
2
2
  "name": "reciple",
3
- "version": "5.6.0",
4
- "bin": "dist/cjs/bin.js",
3
+ "version": "6.0.0-dev.10",
4
+ "bin": "./dist/cjs/bin.js",
5
5
  "license": "GPL-3.0",
6
- "main": "dist/cjs/index.js",
7
- "typings": "dist/types/index.d.ts",
6
+ "main": "./dist/cjs/index.js",
7
+ "types": "./dist/types/index.d.ts",
8
+ "module": "./dist/mjs/index.js",
8
9
  "author": "FalloutStudios",
9
10
  "description": "Handler for Discord.js",
10
11
  "homepage": "https://reciple.js.org",
12
+ "exports": {
13
+ "require": "./dist/cjs/index.js",
14
+ "import": "./dist/mjs/index.js",
15
+ "types": "./dist/types/index.d.ts"
16
+ },
11
17
  "keywords": [
12
18
  "Discord",
13
19
  "Discord.js handler",
14
- "Reciple",
15
- "Slash command handler",
16
- "Message command handler"
20
+ "Reciple"
17
21
  ],
18
22
  "contributors": [
19
23
  "GhexterCortes"
@@ -22,13 +26,15 @@
22
26
  "url": "https://github.com/FalloutStudios/reciple/issues"
23
27
  },
24
28
  "scripts": {
25
- "clean": "yarn exec rimraf dist",
26
- "build": "yarn clean && yarn exec tsc",
27
- "build:publish": "yarn build && yarn docs && yarn npm publish",
28
- "build:publish-prerelease": "yarn build && yarn npm publish --tag pre",
29
- "test": "yarn build && yarn workspace test start",
30
- "docs": "yarn exec docgen --typescript true -c ./docs/index.json -o ./docs/docs.json -i src/index.ts",
31
- "watch": "yarn exec tsc --watch --noEmit"
29
+ "format": "npx prettier --write src",
30
+ "clean": "npx rimraf dist",
31
+ "build": "npm run clean && npx tsc",
32
+ "build:publish": "npm run format && npm run build && npx docs && npm publish",
33
+ "build:publish-dev": "npm run format && npm run build && npm publish --tag dev",
34
+ "test": "npm run build && npm run start -w test",
35
+ "docs": "npx docgen --typescript true -c ./docs/index.json -o ./docs/docs.json -i src/index.ts",
36
+ "watch": "npx tsc --watch --noEmit",
37
+ "husky:install": "npx husky install"
32
38
  },
33
39
  "repository": {
34
40
  "type": "git",
@@ -41,7 +47,6 @@
41
47
  "files": [
42
48
  "dist",
43
49
  "resource",
44
- "package.json",
45
50
  "LICENSE",
46
51
  "README.md"
47
52
  ],
@@ -49,24 +54,25 @@
49
54
  "chalk": "4.1.2",
50
55
  "commander": "^9.4.1",
51
56
  "dotenv": "^16.0.3",
52
- "fallout-utility": "^1.5.2",
53
- "semver": "^7.3.8",
57
+ "fallout-utility": "^1.5.4",
58
+ "semver": "^7.3.7",
54
59
  "wildcard-match": "^5.1.2",
55
- "yaml": "^2.1.3"
60
+ "yaml": "^2.1.1"
56
61
  },
57
62
  "devDependencies": {
58
63
  "@discordjs/docgen": "^0.12.1",
59
- "@types/node": "^18.8.3",
64
+ "@types/node": "^18.11.0",
60
65
  "@types/semver": "^7.3.12",
61
- "discord.js": "^14.5.0",
66
+ "discord.js": "^14.6.0",
67
+ "husky": "^8.0.1",
68
+ "prettier": "2.7.1",
62
69
  "rimraf": "^3.0.2",
63
70
  "typescript": "^4.8.4"
64
71
  },
65
72
  "peerDependencies": {
66
- "discord.js": "^14.1.0"
73
+ "discord.js": "^14.5.0"
67
74
  },
68
75
  "workspaces": [
69
76
  "test"
70
- ],
71
- "packageManager": "yarn@3.2.2"
72
- }
77
+ ]
78
+ }
@@ -1,35 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createLogger = void 0;
7
- const fallout_utility_1 = require("fallout-utility");
8
- const flags_1 = require("./flags");
9
- const chalk_1 = __importDefault(require("chalk"));
10
- /**
11
- * Create new logger
12
- * @param stringifyJSON stringify json objects in console
13
- * @param debugmode display debug messages
14
- * @param colorizeMessage add logger colours to messages
15
- */
16
- function createLogger(stringifyJSON, debugmode = false, colorizeMessage = true) {
17
- return new fallout_utility_1.Logger({
18
- stringifyJSON: stringifyJSON,
19
- enableDebugMode: flags_1.flags.debugmode ?? debugmode,
20
- loggerName: 'Main',
21
- prefixes: {
22
- [fallout_utility_1.LogLevels.INFO]: (name) => `[${new Date().toLocaleTimeString(undefined, { hour12: false })}][${(name ? name + "/" : '') + "INFO"}]`,
23
- [fallout_utility_1.LogLevels.WARN]: (name) => `[${chalk_1.default.yellow(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.yellow((name ? name + "/" : '') + "WARN")}]`,
24
- [fallout_utility_1.LogLevels.ERROR]: (name) => `[${chalk_1.default.red(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.red((name ? name + "/" : '') + "ERROR")}]`,
25
- [fallout_utility_1.LogLevels.DEBUG]: (name) => `[${chalk_1.default.blue(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.blue((name ? name + "/" : '') + "DEBUG")}]`
26
- },
27
- colorMessages: {
28
- [fallout_utility_1.LogLevels.INFO]: (message) => message,
29
- [fallout_utility_1.LogLevels.WARN]: (message) => !colorizeMessage ? message : chalk_1.default.yellow(message),
30
- [fallout_utility_1.LogLevels.ERROR]: (message) => !colorizeMessage ? message : chalk_1.default.red(message),
31
- [fallout_utility_1.LogLevels.DEBUG]: (message) => !colorizeMessage ? message : chalk_1.default.blue(message)
32
- }
33
- });
34
- }
35
- exports.createLogger = createLogger;
@@ -1,113 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getModules = void 0;
30
- const builders_1 = require("./types/builders");
31
- const MessageCommandBuilder_1 = require("./classes/builders/MessageCommandBuilder");
32
- const SlashCommandBuilder_1 = require("./classes/builders/SlashCommandBuilder");
33
- const discord_js_1 = require("discord.js");
34
- const version_1 = require("./version");
35
- const fs_1 = require("fs");
36
- const wildcard_match_1 = __importDefault(require("wildcard-match"));
37
- const flags_1 = require("./flags");
38
- const path_1 = __importDefault(require("path"));
39
- /**
40
- * Load modules from folder
41
- * @param client Reciple client
42
- * @param folder Modules folder
43
- */
44
- async function getModules(client, folder) {
45
- const response = { commands: [], modules: [] };
46
- const modulesDir = folder || path_1.default.join(flags_1.cwd, 'modules');
47
- if (!(0, fs_1.existsSync)(modulesDir))
48
- (0, fs_1.mkdirSync)(modulesDir, { recursive: true });
49
- const ignoredFiles = (client.config.ignoredFiles || []).map(file => file.endsWith('.js') ? file : `${file}.js`);
50
- const scripts = (0, fs_1.readdirSync)(modulesDir).filter(file => {
51
- return file.endsWith('.js') && (!file.startsWith('_') && !file.startsWith('.')) && !ignoredFiles.some(f => (0, wildcard_match_1.default)(f)(file));
52
- });
53
- for (const script of scripts) {
54
- const modulePath = path_1.default.join(modulesDir, script);
55
- const commands = [];
56
- let module_;
57
- try {
58
- const reqMod = await Promise.resolve().then(() => __importStar(require(modulePath)));
59
- module_ = reqMod?.default !== undefined ? reqMod.default : reqMod;
60
- if (typeof module_ !== 'object')
61
- throw new Error(`Module ${modulePath} is not an object`);
62
- if (!client.config.disableVersionCheck && !module_?.versions?.length)
63
- throw new Error(`${modulePath} does not have supported versions.`);
64
- const versions = (0, discord_js_1.normalizeArray)([module_.versions]);
65
- if (!client.config.disableVersionCheck && !versions.some(v => (0, version_1.isSupportedVersion)(v, version_1.version)))
66
- throw new Error(`${modulePath} is unsupported; current version: ${version_1.version}; module supported versions: ` + versions.join(', ') ?? 'none');
67
- if (!await Promise.resolve(module_.onStart(client)).catch(() => false))
68
- throw new Error(script + ' onStart returned false or undefined.');
69
- if (module_.commands) {
70
- for (const command of module_.commands) {
71
- if (command.type === builders_1.CommandBuilderType.MessageCommand) {
72
- commands.push(MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command));
73
- }
74
- else if (command.type === builders_1.CommandBuilderType.SlashCommand) {
75
- commands.push(SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command));
76
- }
77
- }
78
- }
79
- }
80
- catch (error) {
81
- if (client.isClientLogsEnabled()) {
82
- client.logger.error(`Failed to load module ${script}`);
83
- client.logger.error(error);
84
- }
85
- continue;
86
- }
87
- response.commands.push(...commands.filter((c) => {
88
- if (!c.name) {
89
- if (client.isClientLogsEnabled())
90
- client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} command name is not defined in ${modulePath}`);
91
- return false;
92
- }
93
- if (c.type === builders_1.CommandBuilderType.MessageCommand && c.options.length && c.options.some(o => !o.name)) {
94
- if (client.isClientLogsEnabled())
95
- client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} option name is not defined in ${modulePath}`);
96
- return false;
97
- }
98
- return true;
99
- }));
100
- response.modules.push({
101
- script: module_,
102
- info: {
103
- filename: script,
104
- versions: (0, discord_js_1.normalizeArray)([module_.versions]),
105
- path: modulePath
106
- }
107
- });
108
- if (client.isClientLogsEnabled())
109
- client.logger.info(`Loaded module ${modulePath}`);
110
- }
111
- return response;
112
- }
113
- exports.getModules = getModules;
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.registerApplicationCommands = void 0;
4
- const discord_js_1 = require("discord.js");
5
- const SlashCommandBuilder_1 = require("./classes/builders/SlashCommandBuilder");
6
- /**
7
- * Register application commands
8
- * @param options Register application commands options
9
- */
10
- async function registerApplicationCommands(options) {
11
- const client = options.client;
12
- const guilds = (0, discord_js_1.normalizeArray)([options.guilds]);
13
- const commands = options.commands ?? client.commands.slashCommands.toJSON().map(cmd => {
14
- if (cmd?.toJSON === undefined)
15
- return (cmd);
16
- if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandBuilder(cmd) && client.config.commands.slashCommand.setRequiredPermissions) {
17
- const permissions = client.config.commands.slashCommand.permissions.enabled
18
- ? client.config.commands.slashCommand.permissions.commands.find(cmd_ => cmd_.command.toLowerCase() === cmd.name.toLowerCase())?.permissions
19
- : undefined;
20
- if (permissions) {
21
- cmd.setRequiredMemberPermissions(...permissions);
22
- if (client.isClientLogsEnabled())
23
- client.logger.debug(`Set required permissions for ${cmd.name}`);
24
- }
25
- }
26
- return cmd.toJSON();
27
- }) ?? [];
28
- if (!client.isReady())
29
- throw new Error('Client is not ready');
30
- if (!guilds || !guilds?.length) {
31
- client.application?.commands.set(commands).then(() => {
32
- if (client.isClientLogsEnabled())
33
- client.logger.warn('No guilds were specified for application commands. Registered application commands globally.');
34
- });
35
- }
36
- else {
37
- if (client.isClientLogsEnabled())
38
- client.logger.warn(`Registering ${commands.length} application commands to ${guilds.length} guild(s).`);
39
- for (const guild of guilds) {
40
- if (!guild)
41
- continue;
42
- client.application?.commands.set(commands, guild).then(() => {
43
- if (client.isClientLogsEnabled())
44
- client.logger.warn(`Registered ${commands.length} application command(s) for ${guild}.`);
45
- });
46
- }
47
- }
48
- }
49
- exports.registerApplicationCommands = registerApplicationCommands;
@@ -1,8 +0,0 @@
1
- import { Logger } from 'fallout-utility';
2
- /**
3
- * Create new logger
4
- * @param stringifyJSON stringify json objects in console
5
- * @param debugmode display debug messages
6
- * @param colorizeMessage add logger colours to messages
7
- */
8
- export declare function createLogger(stringifyJSON: boolean, debugmode?: boolean, colorizeMessage?: boolean): Logger;
@@ -1,64 +0,0 @@
1
- import { AnyCommandBuilder, AnyCommandData } from './types/builders';
2
- import { RecipleClient } from './classes/RecipleClient';
3
- /**
4
- * Loaded modules and commands
5
- */
6
- export interface LoadedModules {
7
- commands: AnyCommandBuilder[];
8
- modules: RecipleModule[];
9
- }
10
- /**
11
- * Reciple script object
12
- */
13
- export interface RecipleScript {
14
- /**
15
- * Supported reciple versions
16
- */
17
- versions: string | string[];
18
- /**
19
- * Module commands
20
- */
21
- commands?: (AnyCommandBuilder | AnyCommandData)[];
22
- /**
23
- * Action on bot ready
24
- * @param client Bot client
25
- */
26
- onLoad?(client: RecipleClient<true>): void | Promise<void>;
27
- /**
28
- * Action on module start
29
- * @param client Bot client
30
- */
31
- onStart(client: RecipleClient<false>): boolean | Promise<boolean>;
32
- }
33
- /**
34
- * Reciple module object
35
- */
36
- export interface RecipleModule {
37
- /**
38
- * Module script
39
- */
40
- script: RecipleScript;
41
- /**
42
- * Module local information
43
- */
44
- info: {
45
- /**
46
- * Module file name
47
- */
48
- filename?: string;
49
- /**
50
- * Supported reciple versions
51
- */
52
- versions: string[];
53
- /**
54
- * Module local file path
55
- */
56
- path?: string;
57
- };
58
- }
59
- /**
60
- * Load modules from folder
61
- * @param client Reciple client
62
- * @param folder Modules folder
63
- */
64
- export declare function getModules(client: RecipleClient, folder?: string): Promise<LoadedModules>;
@@ -1,9 +0,0 @@
1
- import { ContextMenuCommandBuilder, SlashCommandBuilder as DiscordJsSlashCommandBuilder } from 'discord.js';
2
- import { RegisterApplicationCommandsOptions } from './types/paramOptions';
3
- import { AnySlashCommandBuilder } from './types/builders';
4
- export declare type ApplicationCommandBuilder = AnySlashCommandBuilder | ContextMenuCommandBuilder | DiscordJsSlashCommandBuilder;
5
- /**
6
- * Register application commands
7
- * @param options Register application commands options
8
- */
9
- export declare function registerApplicationCommands(options: RegisterApplicationCommandsOptions): Promise<void>;
package/docs/README.md DELETED
@@ -1 +0,0 @@
1
- # [VIEW DOCS](https://reciple.js.org/#/docs)