reciple 1.1.4 → 1.2.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/CHANGELOG.md ADDED
@@ -0,0 +1,28 @@
1
+ #### 1.2.0 (2022-05-21)
2
+
3
+ ##### New Features
4
+
5
+ * **permissions:** you can now set required permissions for interaction command (3a80154f)
6
+
7
+ ##### Refactors
8
+
9
+ * **permissions:** some changes to message command required permissions (22a01ae3)
10
+
11
+ #### 1.2.0 (2022-05-21)
12
+
13
+ ##### New Features
14
+
15
+ * **permissions:** you can now set required permissions for interaction command (3a80154f)
16
+
17
+ ##### Refactors
18
+
19
+ * **permissions:** some changes to message command required permissions (22a01ae3)
20
+
21
+ #### 1.1.6 (2022-05-21)
22
+
23
+ ##### Bug Fixes
24
+
25
+ * **interactionCommands:** Interaction commands error (55a29d74)
26
+
27
+ #### 1.1.5 (2022-05-21)
28
+
package/bin/bin.js CHANGED
@@ -15,7 +15,7 @@ const Client_1 = require("./reciple/classes/Client");
15
15
  const fs_1 = require("fs");
16
16
  const fallout_utility_1 = require("fallout-utility");
17
17
  require("dotenv/config");
18
- const allowedFiles = ['node_modules', 'reciple.yml', 'package.json', 'package.lock.json'];
18
+ const allowedFiles = ['node_modules', 'reciple.yml', 'package.json', 'package.lock.json', 'modules.yml', '.rmmcache'];
19
19
  if ((0, fs_1.readdirSync)('./').filter(f => !f.startsWith('.') && allowedFiles.indexOf(f)).length > 0 && !(0, fs_1.existsSync)('./reciple.yml')) {
20
20
  const ask = (0, fallout_utility_1.input)('This directory does not contain reciple.yml. Would you like to init axis here? [y/n] ');
21
21
  if (ask !== 'y')
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ // Dear precious programmer,
3
+ // If you're trying to understand this code, please, consider that
4
+ // at the time of writing this code, It was written the way humans
5
+ // can understand it but I transformed into a dog at Apr 12th 2022
6
+ // and accidentally made it unreadable for humans. So, if you're
7
+ // trying to understand this code, please, consider being a dog first.
2
8
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
9
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
10
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -82,29 +88,29 @@ class RecipleClient extends discord_js_1.Client {
82
88
  if (!message.content || !((_a = this.config) === null || _a === void 0 ? void 0 : _a.commands.messageCommand.enabled))
83
89
  return this;
84
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) || ' ');
85
- if (parseCommand && parseCommand.command) {
86
- const command = this.commands.MESSAGE_COMMANDS[parseCommand.command];
87
- 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));
88
101
  return this;
89
- 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)) {
90
- 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))
91
- return this;
92
- if (command.validateOptions && !command.getCommandOptionValues(parseCommand)) {
93
- 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
- return this;
95
- }
96
- const options = {
97
- message: message,
98
- command: parseCommand,
99
- builder: command,
100
- client: this
101
- };
102
- yield Promise.resolve(command.execute(options)).catch(err => this._commandExecuteError(err, options));
103
- this.emit('recipleMessageCommandCreate', options);
104
- }
105
- else {
106
- 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));
107
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));
108
114
  }
109
115
  return this;
110
116
  });
@@ -115,6 +121,8 @@ class RecipleClient extends discord_js_1.Client {
115
121
  if (!interaction || !interaction.isCommand() || !((_a = this.config) === null || _a === void 0 ? void 0 : _a.commands.interactionCommand.enabled))
116
122
  return this;
117
123
  const command = this.commands.INTERACTION_COMMANDS[interaction.commandName];
124
+ if (!command)
125
+ return this;
118
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)) {
119
127
  if (!command.allowExecuteInDM && interaction.member === null || (0, isIgnoredChannel_1.isIgnoredChannel)(interaction.channelId, (_d = this.config) === null || _d === void 0 ? void 0 : _d.ignoredChannels))
120
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
  };
@@ -47,7 +48,7 @@ export interface Config {
47
48
  [key: string]: any;
48
49
  };
49
50
  modulesFolder: string;
50
- version?: string;
51
+ version: string;
51
52
  }
52
53
  export declare class RecipleConfig {
53
54
  config?: Config;
@@ -67,7 +67,7 @@ class RecipleConfig {
67
67
  }
68
68
  isSupportedConfig() {
69
69
  var _a;
70
- return (((_a = this.config) === null || _a === void 0 ? void 0 : _a.version) && this.config.version != version_1.version) ? false : true;
70
+ return (0, version_1.isSupportedVersion)(((_a = this.config) === null || _a === void 0 ? void 0 : _a.version) || '0.0.0', version_1.version);
71
71
  }
72
72
  askToken() {
73
73
  return flags_1.token || (0, fallout_utility_1.input)({ 'text': 'Bot Token >>> ', echo: '*', repeatIfEmpty: true, exitStrings: ['exit', 'quit', ''], sigint: true }) || null;
@@ -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;
@@ -14,9 +14,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.loadModules = void 0;
16
16
  const fs_1 = require("fs");
17
+ const version_1 = require("./version");
17
18
  const path_1 = __importDefault(require("path"));
18
19
  function loadModules(client) {
19
- var _a;
20
+ var _a, _b;
20
21
  return __awaiter(this, void 0, void 0, function* () {
21
22
  const response = { commands: [], modules: [] };
22
23
  const modulesDir = ((_a = client.config) === null || _a === void 0 ? void 0 : _a.modulesFolder) || './modules';
@@ -29,8 +30,12 @@ function loadModules(client) {
29
30
  const commands = [];
30
31
  let module_;
31
32
  try {
32
- module_ = require(modulePath);
33
- if (!module_.versions || !(typeof module_.versions === 'object' ? module_.versions : [module_.versions]).includes(client.version))
33
+ const reqMod = require(modulePath);
34
+ 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))
36
+ throw new Error('Module does not have supported versions.');
37
+ const versions = typeof module_.versions === 'object' ? module_.versions : [module_.versions];
38
+ if (!versions.some(v => (0, version_1.isSupportedVersion)(v, version_1.version)))
34
39
  throw new Error('Module versions is not defined or unsupported.');
35
40
  if (!(yield Promise.resolve(module_.onStart(client))))
36
41
  throw new Error(script + ' onStart is not defined or returned false.');
@@ -1,6 +1,6 @@
1
1
  import { InteractionCommandBuilder } from './classes/builders/InteractionCommandBuilder';
2
2
  import { RecipleClient } from "./classes/Client";
3
- import { ApplicationCommandDataResolvable } from 'discord.js';
3
+ import { ApplicationCommandDataResolvable, GuildResolvable } from 'discord.js';
4
4
  import { ContextMenuCommandBuilder, SlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandOptionsOnlyBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandSubcommandsOnlyBuilder } from '@discordjs/builders';
5
5
  export declare type commandBuilders = InteractionCommandBuilder | ContextMenuCommandBuilder | SlashCommandBuilder | SlashCommandSubcommandBuilder | SlashCommandOptionsOnlyBuilder | SlashCommandSubcommandGroupBuilder | SlashCommandSubcommandsOnlyBuilder;
6
- export declare function registerInteractionCommands(client: RecipleClient, cmds?: (commandBuilders | ApplicationCommandDataResolvable)[]): Promise<void>;
6
+ export declare function registerInteractionCommands(client: RecipleClient, cmds?: (commandBuilders | ApplicationCommandDataResolvable)[], overwriteGuilds?: GuildResolvable | GuildResolvable[]): Promise<void>;
@@ -10,26 +10,41 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.registerInteractionCommands = void 0;
13
- function registerInteractionCommands(client, cmds) {
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(c => c.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) {
22
34
  client.logger.warn('No interaction commands found.');
23
35
  return;
24
36
  }
25
- if (!((_b = client.config) === null || _b === void 0 ? void 0 : _b.commands.interactionCommand.guilds.length)) {
37
+ const configGuilds = overwriteGuilds !== null && overwriteGuilds !== void 0 ? overwriteGuilds : (_b = client.config) === null || _b === void 0 ? void 0 : _b.commands.interactionCommand.guilds;
38
+ const guilds = typeof configGuilds === 'object' ? configGuilds : [configGuilds];
39
+ if (!guilds || !(guilds === null || guilds === void 0 ? void 0 : guilds.length)) {
26
40
  yield ((_d = (_c = client.application) === null || _c === void 0 ? void 0 : _c.commands.set(commands)) === null || _d === void 0 ? void 0 : _d.catch(e => client.logger.error(e)));
27
41
  client.logger.warn('No guilds were specified for interaction commands. Registered commands for all guilds.');
28
42
  }
29
43
  else {
30
- const guilds = typeof client.config.commands.interactionCommand.guilds === 'string' ? [client.config.commands.interactionCommand.guilds] : client.config.commands.interactionCommand.guilds;
31
44
  client.logger.warn(`Registering ${commands.length} interaction commands for ${guilds.length} guild(s).`);
32
45
  for (const guild of guilds) {
46
+ if (!guild)
47
+ continue;
33
48
  yield ((_f = (_e = client.application) === null || _e === void 0 ? void 0 : _e.commands.set(commands, guild)) === null || _f === void 0 ? void 0 : _f.catch(e => client.logger.error(e)));
34
49
  client.logger.warn(`Registered ${commands.length} interaction commands for ${guild}.`);
35
50
  }
@@ -1 +1,8 @@
1
- export declare const version: any;
1
+ export declare const version: string;
2
+ export declare function validVersion(ver: string): boolean;
3
+ export declare function parseVersion(ver: string): {
4
+ major: number;
5
+ minor: number;
6
+ patch: number;
7
+ };
8
+ export declare function isSupportedVersion(ver: string, supportedVersion?: string): boolean;
@@ -1,4 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.version = void 0;
3
+ exports.isSupportedVersion = exports.parseVersion = exports.validVersion = exports.version = void 0;
4
+ const fallout_utility_1 = require("fallout-utility");
4
5
  exports.version = require('../../package.json').version;
6
+ 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;
13
+ }
14
+ exports.validVersion = validVersion;
15
+ function parseVersion(ver) {
16
+ if (!validVersion(ver))
17
+ throw new TypeError(`Invalid version: ${ver}`);
18
+ const [major, minor, patch] = ver.split('.');
19
+ return { major: parseInt(major), minor: parseInt(minor), patch: parseInt(patch) };
20
+ }
21
+ exports.parseVersion = parseVersion;
22
+ function isSupportedVersion(ver, supportedVersion) {
23
+ supportedVersion = supportedVersion || exports.version;
24
+ if (!validVersion(ver))
25
+ throw new TypeError(`Invalid version: ${ver}`);
26
+ if (!validVersion(supportedVersion))
27
+ 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;
37
+ }
38
+ exports.isSupportedVersion = isSupportedVersion;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reciple",
3
- "version": "1.1.4",
3
+ "version": "1.2.0",
4
4
  "description": "A Discord.js bot",
5
5
  "author": "FalloutStudios",
6
6
  "license": "GPL-3.0",
@@ -13,13 +13,15 @@
13
13
  "resource",
14
14
  "package.json",
15
15
  "LICENSE",
16
- "README.md"
16
+ "README.md",
17
+ "CHANGELOG.md"
17
18
  ],
18
19
  "scripts": {
19
20
  "clean": "rimraf bin",
20
21
  "compile": "yarn clean && tsc",
21
22
  "build": "yarn compile && npm un reciple -g && npm i ./ -g",
22
- "build:publish": "yarn run build && yarn publish",
23
+ "build:publish": "yarn run build && yarn run changelog && yarn publish",
24
+ "changelog": "changelog generate",
23
25
  "test": "cd test && reciple",
24
26
  "test:compile": "yarn run build && yarn test:run"
25
27
  },
@@ -31,7 +33,8 @@
31
33
  "yaml": "^2.1.0"
32
34
  },
33
35
  "devDependencies": {
34
- "@types/node": "^17.0.33",
36
+ "@types/node": "^17.0.35",
37
+ "generate-changelog": "^1.8.0",
35
38
  "typescript": "^4.6.4"
36
39
  }
37
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