reciple 1.1.5 → 1.3.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.
@@ -88,29 +88,29 @@ class RecipleClient extends discord_js_1.Client {
88
88
  if (!message.content || !((_a = this.config) === null || _a === void 0 ? void 0 : _a.commands.messageCommand.enabled))
89
89
  return this;
90
90
  const parseCommand = (0, fallout_utility_1.getCommand)(message.content, ((_b = this.config) === null || _b === void 0 ? void 0 : _b.prefix) || '!', ((_c = this.config) === null || _c === void 0 ? void 0 : _c.commands.messageCommand.commandArgumentSeparator) || ' ');
91
- if (parseCommand && parseCommand.command) {
92
- const command = this.commands.MESSAGE_COMMANDS[parseCommand.command];
93
- if (!command)
91
+ if (!(parseCommand === null || parseCommand === void 0 ? void 0 : parseCommand.command) || !parseCommand)
92
+ return this;
93
+ const command = this.commands.MESSAGE_COMMANDS[parseCommand.command];
94
+ if (!command)
95
+ return this;
96
+ if ((0, commandPermissions_1.commandPermissions)(command.name, (_d = message.member) === null || _d === void 0 ? void 0 : _d.permissions, (_e = this.config) === null || _e === void 0 ? void 0 : _e.permissions.messageCommands, command)) {
97
+ if (!command.allowExecuteInDM && message.channel.type === 'DM' || !command.allowExecuteByBots && (message.author.bot || message.author.system) || (0, isIgnoredChannel_1.isIgnoredChannel)(message.channelId, (_f = this.config) === null || _f === void 0 ? void 0 : _f.ignoredChannels))
98
+ return this;
99
+ if (command.validateOptions && !command.getCommandOptionValues(parseCommand)) {
100
+ yield message.reply(((_g = this.config) === null || _g === void 0 ? void 0 : _g.messages.notEnoughArguments) || 'Not enough arguments.').catch((err) => this.logger.error(err));
94
101
  return this;
95
- if ((0, commandPermissions_1.commandPermissions)(command.name, (_d = message.member) === null || _d === void 0 ? void 0 : _d.permissions, (_e = this.config) === null || _e === void 0 ? void 0 : _e.permissions.messageCommands, command)) {
96
- if (!command.allowExecuteInDM && message.channel.type === 'DM' || !command.allowExecuteByBots && (message.author.bot || message.author.system) || (0, isIgnoredChannel_1.isIgnoredChannel)(message.channelId, (_f = this.config) === null || _f === void 0 ? void 0 : _f.ignoredChannels))
97
- return this;
98
- if (command.validateOptions && !command.getCommandOptionValues(parseCommand)) {
99
- yield message.reply(((_g = this.config) === null || _g === void 0 ? void 0 : _g.messages.notEnoughArguments) || 'Not enough arguments.').catch((err) => this.logger.error(err));
100
- return this;
101
- }
102
- const options = {
103
- message: message,
104
- command: parseCommand,
105
- builder: command,
106
- client: this
107
- };
108
- yield Promise.resolve(command.execute(options)).catch(err => this._commandExecuteError(err, options));
109
- this.emit('recipleMessageCommandCreate', options);
110
- }
111
- else {
112
- yield message.reply(((_h = this.config) === null || _h === void 0 ? void 0 : _h.messages.noPermissions) || 'You do not have permission to use this command.').catch((err) => this.logger.error(err));
113
102
  }
103
+ const options = {
104
+ message: message,
105
+ command: parseCommand,
106
+ builder: command,
107
+ client: this
108
+ };
109
+ yield Promise.resolve(command.execute(options)).catch(err => this._commandExecuteError(err, options));
110
+ this.emit('recipleMessageCommandCreate', options);
111
+ }
112
+ else {
113
+ yield message.reply(((_h = this.config) === null || _h === void 0 ? void 0 : _h.messages.noPermissions) || 'You do not have permission to use this command.').catch((err) => this.logger.error(err));
114
114
  }
115
115
  return this;
116
116
  });
@@ -121,6 +121,8 @@ class RecipleClient extends discord_js_1.Client {
121
121
  if (!interaction || !interaction.isCommand() || !((_a = this.config) === null || _a === void 0 ? void 0 : _a.commands.interactionCommand.enabled))
122
122
  return this;
123
123
  const command = this.commands.INTERACTION_COMMANDS[interaction.commandName];
124
+ if (!command)
125
+ return this;
124
126
  if ((0, commandPermissions_1.commandPermissions)(command.name, (_b = interaction.memberPermissions) !== null && _b !== void 0 ? _b : undefined, (_c = this.config) === null || _c === void 0 ? void 0 : _c.permissions.interactionCommands, command)) {
125
127
  if (!command.allowExecuteInDM && interaction.member === null || (0, isIgnoredChannel_1.isIgnoredChannel)(interaction.channelId, (_d = this.config) === null || _d === void 0 ? void 0 : _d.ignoredChannels))
126
128
  return this;
@@ -1,4 +1,4 @@
1
- import { ClientOptions, PermissionResolvable } from 'discord.js';
1
+ import { ClientOptions, PermissionFlags, PermissionString } from 'discord.js';
2
2
  export interface Config {
3
3
  token: string;
4
4
  prefix: string;
@@ -12,6 +12,7 @@ export interface Config {
12
12
  enabled: boolean;
13
13
  replyOnError: boolean;
14
14
  registerCommands: boolean;
15
+ setRequiredPermissions: boolean;
15
16
  guilds: string[] | string;
16
17
  };
17
18
  };
@@ -20,14 +21,14 @@ export interface Config {
20
21
  enabled: boolean;
21
22
  commands: {
22
23
  command: string;
23
- permissions: PermissionResolvable[];
24
+ permissions: (PermissionFlags | PermissionString)[];
24
25
  }[];
25
26
  };
26
27
  interactionCommands: {
27
28
  enabled: boolean;
28
29
  commands: {
29
30
  command: string;
30
- permissions: PermissionResolvable[];
31
+ permissions: (PermissionFlags | PermissionString)[];
31
32
  }[];
32
33
  };
33
34
  };
@@ -46,6 +47,7 @@ export interface Config {
46
47
  messages: {
47
48
  [key: string]: any;
48
49
  };
50
+ ignoredFiles: string[];
49
51
  modulesFolder: string;
50
52
  version: string;
51
53
  }
@@ -1,5 +1,5 @@
1
1
  import { SlashCommandBuilder } from '@discordjs/builders';
2
- import { CommandInteraction, PermissionFlags } from 'discord.js';
2
+ import { CommandInteraction, PermissionFlags, PermissionString } from 'discord.js';
3
3
  import { RecipleClient } from '../Client';
4
4
  export interface RecipleInteractionCommandExecute {
5
5
  interaction: CommandInteraction;
@@ -9,7 +9,7 @@ export interface RecipleInteractionCommandExecute {
9
9
  }
10
10
  export declare class InteractionCommandBuilder extends SlashCommandBuilder {
11
11
  readonly builder: string;
12
- requiredPermissions: (keyof PermissionFlags)[];
12
+ requiredPermissions: (PermissionFlags | PermissionString)[];
13
13
  allowExecuteInDM: boolean;
14
14
  execute: (options: RecipleInteractionCommandExecute) => void;
15
15
  setRequiredPermissions(requiredPermissions: (keyof PermissionFlags)[]): InteractionCommandBuilder;
@@ -8,7 +8,7 @@ class InteractionCommandBuilder extends builders_1.SlashCommandBuilder {
8
8
  this.builder = 'INTERACTION_COMMAND';
9
9
  this.requiredPermissions = [];
10
10
  this.allowExecuteInDM = true;
11
- this.execute = (options) => { };
11
+ this.execute = () => { };
12
12
  }
13
13
  setRequiredPermissions(requiredPermissions) {
14
14
  if (!requiredPermissions || !Array.isArray(requiredPermissions))
@@ -1,4 +1,4 @@
1
- import { Message, PermissionFlags } from 'discord.js';
1
+ import { Message, PermissionFlags, PermissionString } from 'discord.js';
2
2
  import { Command } from 'fallout-utility';
3
3
  import { RecipleClient } from '../Client';
4
4
  export declare type CommandMessage = Command;
@@ -29,12 +29,12 @@ export declare class MessageCommandBuilder {
29
29
  description: string;
30
30
  options: MessageOption[];
31
31
  validateOptions: boolean;
32
- requiredPermissions: (keyof PermissionFlags)[];
32
+ requiredPermissions: (PermissionFlags | PermissionString)[];
33
33
  allowExecuteInDM: boolean;
34
34
  allowExecuteByBots: boolean;
35
35
  execute: (options: RecipleMessageCommandExecute) => void;
36
36
  setName(name: string): MessageCommandBuilder;
37
- setRequiredPermissions(permissions: (keyof PermissionFlags)[]): MessageCommandBuilder;
37
+ setRequiredPermissions(permissions: (PermissionFlags | PermissionString)[]): MessageCommandBuilder;
38
38
  setAllowExecuteInDM(allowExecuteInDM: boolean): MessageCommandBuilder;
39
39
  setAllowExecuteByBots(allowExecuteByBots: boolean): MessageCommandBuilder;
40
40
  setDescription(description: string): MessageCommandBuilder;
@@ -44,7 +44,7 @@ class MessageCommandBuilder {
44
44
  this.requiredPermissions = [];
45
45
  this.allowExecuteInDM = true;
46
46
  this.allowExecuteByBots = false;
47
- this.execute = (options) => { };
47
+ this.execute = () => { };
48
48
  }
49
49
  setName(name) {
50
50
  if (!name || typeof name !== 'string' || !name.match(/^[\w-]{1,32}$/))
@@ -9,8 +9,8 @@ export declare type loadedModules = {
9
9
  export interface RecipleScript {
10
10
  versions: string | string[];
11
11
  commands?: (MessageCommandBuilder | InteractionCommandBuilder)[];
12
- onLoad?: (reciple: RecipleClient) => void | Promise<void>;
13
- onStart: (reciple: RecipleClient) => boolean | Promise<boolean>;
12
+ onLoad?: (reciple: RecipleClient) => (void | Promise<void>);
13
+ onStart: (reciple: RecipleClient) => (boolean | Promise<boolean>);
14
14
  }
15
15
  export interface RecipleModule {
16
16
  script: RecipleScript;
@@ -17,14 +17,17 @@ const fs_1 = require("fs");
17
17
  const version_1 = require("./version");
18
18
  const path_1 = __importDefault(require("path"));
19
19
  function loadModules(client) {
20
- var _a, _b;
20
+ var _a, _b, _c;
21
21
  return __awaiter(this, void 0, void 0, function* () {
22
22
  const response = { commands: [], modules: [] };
23
23
  const modulesDir = ((_a = client.config) === null || _a === void 0 ? void 0 : _a.modulesFolder) || './modules';
24
24
  const logger = client.logger;
25
25
  if (!(0, fs_1.existsSync)(modulesDir))
26
26
  (0, fs_1.mkdirSync)(modulesDir, { recursive: true });
27
- const scripts = (0, fs_1.readdirSync)(modulesDir).filter(file => file.endsWith('.js') && (!file.startsWith('_') && !file.startsWith('.')));
27
+ const ignoredFiles = (((_b = client.config) === null || _b === void 0 ? void 0 : _b.ignoredFiles) || []).map(file => file.endsWith('.js') ? file : `${file}.js`);
28
+ const scripts = (0, fs_1.readdirSync)(modulesDir).filter(file => {
29
+ return file.endsWith('.js') && (!file.startsWith('_') && !file.startsWith('.')) && !ignoredFiles.includes(file);
30
+ });
28
31
  for (const script of scripts) {
29
32
  const modulePath = path_1.default.resolve(modulesDir, script);
30
33
  const commands = [];
@@ -32,7 +35,7 @@ function loadModules(client) {
32
35
  try {
33
36
  const reqMod = require(modulePath);
34
37
  module_ = !!(reqMod === null || reqMod === void 0 ? void 0 : reqMod.default) ? reqMod.default : reqMod;
35
- if (!((_b = module_.versions) === null || _b === void 0 ? void 0 : _b.length))
38
+ if (!((_c = module_.versions) === null || _c === void 0 ? void 0 : _c.length))
36
39
  throw new Error('Module does not have supported versions.');
37
40
  const versions = typeof module_.versions === 'object' ? module_.versions : [module_.versions];
38
41
  if (!versions.some(v => (0, version_1.isSupportedVersion)(v, version_1.version)))
@@ -13,9 +13,21 @@ exports.registerInteractionCommands = void 0;
13
13
  function registerInteractionCommands(client, cmds, overwriteGuilds) {
14
14
  var _a, _b, _c, _d, _e, _f;
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
- const commands = (_a = Object.values(cmds !== null && cmds !== void 0 ? cmds : client.commands.INTERACTION_COMMANDS).map(c => {
17
- if (typeof c.toJSON !== 'undefined')
16
+ let commands = (_a = Object.values(cmds !== null && cmds !== void 0 ? cmds : client.commands.INTERACTION_COMMANDS).map(c => {
17
+ var _a, _b, _c, _d, _e, _f, _g;
18
+ if (typeof c.toJSON !== 'undefined') {
19
+ const cmd = c;
20
+ if ((cmd === null || cmd === void 0 ? void 0 : cmd.builder) === 'INTERACTION_COMMAND' && ((_a = client.config) === null || _a === void 0 ? void 0 : _a.commands.interactionCommand.setRequiredPermissions)) {
21
+ const permissions = (_g = (((_c = (_b = client.config) === null || _b === void 0 ? void 0 : _b.permissions) === null || _c === void 0 ? void 0 : _c.interactionCommands.enabled) ?
22
+ (_f = (_e = (_d = client.config) === null || _d === void 0 ? void 0 : _d.permissions) === null || _e === void 0 ? void 0 : _e.interactionCommands.commands.find(cmd_ => cmd_.command.toLowerCase() === cmd.name.toLowerCase())) === null || _f === void 0 ? void 0 : _f.permissions :
23
+ undefined)) !== null && _g !== void 0 ? _g : cmd.requiredPermissions;
24
+ cmd.setRequiredPermissions(permissions);
25
+ client.commands.INTERACTION_COMMANDS[cmd.name] = cmd;
26
+ client.logger.debug(`Set required permissions for ${cmd.name} to ${permissions.join(', ')}`);
27
+ return cmd.toJSON();
28
+ }
18
29
  return c.toJSON();
30
+ }
19
31
  return c;
20
32
  })) !== null && _a !== void 0 ? _a : [];
21
33
  if (!commands || !commands.length) {
@@ -5,4 +5,4 @@ export declare function parseVersion(ver: string): {
5
5
  minor: number;
6
6
  patch: number;
7
7
  };
8
- export declare function isSupportedVersion(ver: string, supportedVersion?: string): boolean;
8
+ export declare function isSupportedVersion(versionRange: string, supportedVersion?: string): boolean;
@@ -1,38 +1,29 @@
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
6
  exports.isSupportedVersion = exports.parseVersion = exports.validVersion = exports.version = void 0;
4
- const fallout_utility_1 = require("fallout-utility");
7
+ const semver_1 = __importDefault(require("semver"));
5
8
  exports.version = require('../../package.json').version;
6
9
  function validVersion(ver) {
7
- if (!ver || typeof ver !== 'string' || ver.split('.').length < 3)
8
- return false;
9
- const [major, minor, patch] = ver.split('.');
10
- if (!(0, fallout_utility_1.isNumber)(major) || !(0, fallout_utility_1.isNumber)(minor) || !(0, fallout_utility_1.isNumber)(patch))
11
- return false;
12
- return true;
10
+ return semver_1.default.valid(semver_1.default.coerce(ver)) !== null;
13
11
  }
14
12
  exports.validVersion = validVersion;
15
13
  function parseVersion(ver) {
14
+ var _a, _b;
16
15
  if (!validVersion(ver))
17
16
  throw new TypeError(`Invalid version: ${ver}`);
18
- const [major, minor, patch] = ver.split('.');
17
+ const [major, minor, patch] = (_b = (_a = `${semver_1.default.coerce(ver)}`) === null || _a === void 0 ? void 0 : _a.split('.')) !== null && _b !== void 0 ? _b : [];
19
18
  return { major: parseInt(major), minor: parseInt(minor), patch: parseInt(patch) };
20
19
  }
21
20
  exports.parseVersion = parseVersion;
22
- function isSupportedVersion(ver, supportedVersion) {
21
+ function isSupportedVersion(versionRange, supportedVersion) {
23
22
  supportedVersion = supportedVersion || exports.version;
24
- if (!validVersion(ver))
25
- throw new TypeError(`Invalid version: ${ver}`);
23
+ if (!validVersion(versionRange))
24
+ throw new TypeError(`Invalid version: ${versionRange}`);
26
25
  if (!validVersion(supportedVersion))
27
26
  throw new TypeError(`Invalid supported version: ${supportedVersion}`);
28
- const { major, minor, patch } = parseVersion(ver);
29
- const { major: supportedMajor, minor: supportedMinor, patch: supportedPatch } = parseVersion(supportedVersion);
30
- if (major !== supportedMajor)
31
- return false;
32
- if (minor !== supportedMinor)
33
- return false;
34
- if (patch > supportedPatch)
35
- return false;
36
- return true;
27
+ return semver_1.default.satisfies(supportedVersion, versionRange);
37
28
  }
38
29
  exports.isSupportedVersion = isSupportedVersion;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reciple",
3
- "version": "1.1.5",
3
+ "version": "1.3.0",
4
4
  "description": "A Discord.js bot",
5
5
  "author": "FalloutStudios",
6
6
  "license": "GPL-3.0",
@@ -21,20 +21,20 @@
21
21
  "compile": "yarn clean && tsc",
22
22
  "build": "yarn compile && npm un reciple -g && npm i ./ -g",
23
23
  "build:publish": "yarn run build && yarn run changelog && yarn publish",
24
- "changelog": "changelog generate",
25
24
  "test": "cd test && reciple",
26
- "test:compile": "yarn run build && yarn test:run"
25
+ "test:build": "yarn run build && yarn test:run"
27
26
  },
28
27
  "dependencies": {
29
28
  "commander": "^9.2.0",
30
29
  "discord.js": "^13.7.0",
31
30
  "dotenv": "^16.0.1",
32
31
  "fallout-utility": "^1.3.14",
32
+ "semver": "^7.3.7",
33
33
  "yaml": "^2.1.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/node": "^17.0.35",
37
- "generate-changelog": "^1.8.0",
37
+ "@types/semver": "^7.3.9",
38
38
  "typescript": "^4.6.4"
39
39
  }
40
40
  }
@@ -22,6 +22,8 @@ commands:
22
22
  replyOnError: false
23
23
  # register interaction commands on bot ready
24
24
  registerCommands: true
25
+ # set required permissions for interaction commands
26
+ setRequiredPermissions: true
25
27
  # register commands to specific guild(s) empty to make it global
26
28
  guilds: []
27
29
 
@@ -83,6 +85,10 @@ messages:
83
85
  content: 'An error occurred.'
84
86
  ephemeral: true
85
87
 
88
+ # Ignored Files
89
+ ignoredFiles:
90
+ - 'test.js'
91
+
86
92
 
87
93
  ###################################################
88
94
  # #
package/CHANGELOG.md DELETED
@@ -1,71 +0,0 @@
1
- #### 1.1.4 (2022-05-21)
2
-
3
- ##### New Features
4
-
5
- * **version.ts:** Version checking functions (491b97b2)
6
- * **registerinteractions:** You can now overwrite guilds in register interactions (422fe8ad)
7
-
8
- ##### Bug Fixes
9
-
10
- * **modules:** fix module loading version check (c3c2ad94)
11
- * **versions:** Fixed checking supported version (4220ea96)
12
- * **scripts:** Fixed changelog when deleting non existing file (cafdfe47)
13
-
14
- ##### Other Changes
15
-
16
- * **changelog:** Don't delete current changelog (29c49362)
17
- * **dependencies:** Updated dev dependency (8b4a131c)
18
-
19
- ##### Refactors
20
-
21
- * **versions:** supported versions made backwards compatible (addf514a)
22
- * **modules:** Check if module is supported (d79fbd49)
23
- * **Config.ts:** Checks if version is supported (83bae35b)
24
- * **modules.ts:** import default when available (cdad52e9)
25
- * **ignoredfiles:** Ignore rmm files (55760c0e)
26
-
27
- #### 1.1.4 (2022-05-21)
28
-
29
- ##### New Features
30
-
31
- * **version.ts:** Version checking functions (491b97b2)
32
- * **registerinteractions:** You can now overwrite guilds in register interactions (422fe8ad)
33
-
34
- ##### Bug Fixes
35
-
36
- * **modules:** fix module loading version check (c3c2ad94)
37
- * **versions:** Fixed checking supported version (4220ea96)
38
- * **scripts:** Fixed changelog when deleting non existing file (cafdfe47)
39
-
40
- ##### Other Changes
41
-
42
- * **changelog:** Don't delete current changelog (29c49362)
43
- * **dependencies:** Updated dev dependency (8b4a131c)
44
-
45
- ##### Refactors
46
-
47
- * **modules:** Check if module is supported (d79fbd49)
48
- * **Config.ts:** Checks if version is supported (83bae35b)
49
- * **modules.ts:** import default when available (cdad52e9)
50
- * **ignoredfiles:** Ignore rmm files (55760c0e)
51
-
52
- #### 1.1.4 (2022-05-20)
53
-
54
- ##### New Features
55
-
56
- * **version.ts:** Version checking functions (491b97b2)
57
- * **registerinteractions:** You can now overwrite guilds in register interactions (422fe8ad)
58
-
59
- ##### Bug Fixes
60
-
61
- * **scripts:** Fixed changelog when deleting non existing file (cafdfe47)
62
-
63
- ##### Other Changes
64
-
65
- * **dependencies:** Updated dev dependency (8b4a131c)
66
-
67
- ##### Refactors
68
-
69
- * **modules.ts:** import default when available (cdad52e9)
70
- * **ignoredfiles:** Ignore rmm files (55760c0e)
71
-