reciple 1.0.17 → 1.1.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/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export * from './reciple/classes/Client';
2
2
  export * from './reciple/classes/Config';
3
- export * from './reciple/classes/builders/MessageCommandBuilder';
4
3
  export * from './reciple/classes/builders/InteractionCommandBuilder';
4
+ export * from './reciple/classes/builders/MessageCommandBuilder';
5
5
  export * from './reciple/commandPermissions';
6
6
  export * from './reciple/flags';
7
7
  export * from './reciple/isIgnoredChannel';
package/bin/index.js CHANGED
@@ -16,8 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./reciple/classes/Client"), exports);
18
18
  __exportStar(require("./reciple/classes/Config"), exports);
19
- __exportStar(require("./reciple/classes/builders/MessageCommandBuilder"), exports);
20
19
  __exportStar(require("./reciple/classes/builders/InteractionCommandBuilder"), exports);
20
+ __exportStar(require("./reciple/classes/builders/MessageCommandBuilder"), exports);
21
21
  __exportStar(require("./reciple/commandPermissions"), exports);
22
22
  __exportStar(require("./reciple/flags"), exports);
23
23
  __exportStar(require("./reciple/isIgnoredChannel"), exports);
@@ -42,10 +42,10 @@ class RecipleClient extends discord_js_1.Client {
42
42
  for (const command of modules.commands) {
43
43
  if (!command.name)
44
44
  continue;
45
- if (command.type === 'MESSAGE_COMMAND') {
45
+ if (command.builder === 'MESSAGE_COMMAND') {
46
46
  this.commands.MESSAGE_COMMANDS[command.name] = command;
47
47
  }
48
- else if (command.type === 'INTERACTION_COMMAND') {
48
+ else if (command.builder === 'INTERACTION_COMMAND') {
49
49
  this.commands.INTERACTION_COMMANDS[command.name] = command;
50
50
  }
51
51
  }
@@ -85,7 +85,7 @@ class RecipleClient extends discord_js_1.Client {
85
85
  const command = this.commands.MESSAGE_COMMANDS[parseCommand.command];
86
86
  if (!command)
87
87
  return this;
88
- if ((0, commandPermissions_1.commandPermissions)(command.name, ((_d = message.member) === null || _d === void 0 ? void 0 : _d.permissions) || null, (_e = this.config) === null || _e === void 0 ? void 0 : _e.permissions.messageCommands)) {
88
+ 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)) {
89
89
  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))
90
90
  return this;
91
91
  if (command.validateOptions && !command.getCommandOptionValues(parseCommand)) {
@@ -109,13 +109,13 @@ class RecipleClient extends discord_js_1.Client {
109
109
  });
110
110
  }
111
111
  interactionCommandExecute(interaction) {
112
- var _a, _b, _c, _d;
112
+ var _a, _b, _c, _d, _e;
113
113
  return __awaiter(this, void 0, void 0, function* () {
114
114
  if (!interaction || !interaction.isCommand() || !((_a = this.config) === null || _a === void 0 ? void 0 : _a.commands.interactionCommand.enabled))
115
115
  return this;
116
116
  const command = this.commands.INTERACTION_COMMANDS[interaction.commandName];
117
- if ((0, commandPermissions_1.commandPermissions)(command.name, interaction.memberPermissions, (_b = this.config) === null || _b === void 0 ? void 0 : _b.permissions.interactionCommands)) {
118
- if (!command.allowExecuteInDM && interaction.member === null || (0, isIgnoredChannel_1.isIgnoredChannel)(interaction.channelId, (_c = this.config) === null || _c === void 0 ? void 0 : _c.ignoredChannels))
117
+ 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)) {
118
+ if (!command.allowExecuteInDM && interaction.member === null || (0, isIgnoredChannel_1.isIgnoredChannel)(interaction.channelId, (_d = this.config) === null || _d === void 0 ? void 0 : _d.ignoredChannels))
119
119
  return this;
120
120
  if (!command)
121
121
  return this;
@@ -129,7 +129,7 @@ class RecipleClient extends discord_js_1.Client {
129
129
  this.emit('recipleInteractionCommandCreate', options);
130
130
  }
131
131
  else {
132
- yield interaction.reply(((_d = this.config) === null || _d === void 0 ? void 0 : _d.messages.noPermissions) || 'You do not have permission to use this command.').catch((err) => this.logger.error(err));
132
+ yield interaction.reply(((_e = this.config) === null || _e === void 0 ? void 0 : _e.messages.noPermissions) || 'You do not have permission to use this command.').catch((err) => this.logger.error(err));
133
133
  }
134
134
  return this;
135
135
  });
@@ -137,7 +137,7 @@ class RecipleClient extends discord_js_1.Client {
137
137
  _commandExecuteError(err, command) {
138
138
  var _a, _b, _c, _d, _e;
139
139
  return __awaiter(this, void 0, void 0, function* () {
140
- this.logger.error(`An error occured executing ${command.builder.type == 'MESSAGE_COMMAND' ? 'message' : 'interaction'} command "${command.builder.name}"`);
140
+ this.logger.error(`An error occured executing ${command.builder.builder == 'MESSAGE_COMMAND' ? 'message' : 'interaction'} command "${command.builder.name}"`);
141
141
  this.logger.error(err);
142
142
  if (!err || !command)
143
143
  return;
@@ -149,11 +149,11 @@ class RecipleClient extends discord_js_1.Client {
149
149
  else if (command === null || command === void 0 ? void 0 : command.interaction) {
150
150
  if (!((_c = this.config) === null || _c === void 0 ? void 0 : _c.commands.interactionCommand.replyOnError))
151
151
  return;
152
- if (!(command === null || command === void 0 ? void 0 : command.interaction.deferred)) {
152
+ if (!(command === null || command === void 0 ? void 0 : command.interaction.deferred) && !(command === null || command === void 0 ? void 0 : command.interaction.replied)) {
153
153
  yield command.interaction.reply(((_d = this.config) === null || _d === void 0 ? void 0 : _d.messages.error) || 'An error occured.').catch((e) => this.logger.error(e));
154
154
  }
155
155
  else {
156
- yield command.interaction.editReply(((_e = this.config) === null || _e === void 0 ? void 0 : _e.messages.error) || 'An error occured.').catch((e) => this.logger.error(e));
156
+ yield command.interaction.followUp(((_e = this.config) === null || _e === void 0 ? void 0 : _e.messages.error) || 'An error occured.').catch((e) => this.logger.error(e));
157
157
  }
158
158
  }
159
159
  });
@@ -1,5 +1,5 @@
1
1
  import { SlashCommandBuilder } from '@discordjs/builders';
2
- import { CommandInteraction } from 'discord.js';
2
+ import { CommandInteraction, PermissionFlags } from 'discord.js';
3
3
  import { RecipleClient } from '../Client';
4
4
  export interface RecipleInteractionCommandExecute {
5
5
  interaction: CommandInteraction;
@@ -8,9 +8,11 @@ export interface RecipleInteractionCommandExecute {
8
8
  client: RecipleClient;
9
9
  }
10
10
  export declare class InteractionCommandBuilder extends SlashCommandBuilder {
11
- readonly type: string;
11
+ readonly builder: string;
12
+ requiredPermissions: (keyof PermissionFlags)[];
12
13
  allowExecuteInDM: boolean;
13
14
  execute: (options: RecipleInteractionCommandExecute) => void;
15
+ setRequiredPermissions(requiredPermissions: (keyof PermissionFlags)[]): InteractionCommandBuilder;
14
16
  setAllowExecuteInDM(allowExecuteInDM: boolean): InteractionCommandBuilder;
15
17
  setExecute(execute: (options: RecipleInteractionCommandExecute) => void): InteractionCommandBuilder;
16
18
  }
@@ -5,10 +5,17 @@ const builders_1 = require("@discordjs/builders");
5
5
  class InteractionCommandBuilder extends builders_1.SlashCommandBuilder {
6
6
  constructor() {
7
7
  super(...arguments);
8
- this.type = 'INTERACTION_COMMAND';
8
+ this.builder = 'INTERACTION_COMMAND';
9
+ this.requiredPermissions = [];
9
10
  this.allowExecuteInDM = true;
10
11
  this.execute = (options) => { };
11
12
  }
13
+ setRequiredPermissions(requiredPermissions) {
14
+ if (!requiredPermissions || !Array.isArray(requiredPermissions))
15
+ throw new Error('requiredPermissions must be an array.');
16
+ this.requiredPermissions = requiredPermissions;
17
+ return this;
18
+ }
12
19
  setAllowExecuteInDM(allowExecuteInDM) {
13
20
  if (typeof allowExecuteInDM !== 'boolean')
14
21
  throw new Error('allowExecuteInDM must be a boolean.');
@@ -1,4 +1,4 @@
1
- import { Message } from 'discord.js';
1
+ import { Message, PermissionFlags } from 'discord.js';
2
2
  import { Command } from 'fallout-utility';
3
3
  import { RecipleClient } from '../Client';
4
4
  export interface CommandMessage extends Command {
@@ -30,15 +30,17 @@ export declare class MessageOption {
30
30
  setValidator(validator: (value: string) => boolean): MessageOption;
31
31
  }
32
32
  export declare class MessageCommandBuilder {
33
- readonly type: string;
33
+ readonly builder: string;
34
34
  name: string;
35
35
  description: string;
36
36
  options: MessageOption[];
37
37
  validateOptions: boolean;
38
+ requiredPermissions: (keyof PermissionFlags)[];
38
39
  allowExecuteInDM: boolean;
39
40
  allowExecuteByBots: boolean;
40
41
  execute: (options: RecipleMessageCommandExecute) => void;
41
42
  setName(name: string): MessageCommandBuilder;
43
+ setRequiredPermissions(permissions: (keyof PermissionFlags)[]): MessageCommandBuilder;
42
44
  setAllowExecuteInDM(allowExecuteInDM: boolean): MessageCommandBuilder;
43
45
  setAllowExecuteByBots(allowExecuteByBots: boolean): MessageCommandBuilder;
44
46
  setDescription(description: string): MessageCommandBuilder;
@@ -36,11 +36,12 @@ class MessageOption {
36
36
  exports.MessageOption = MessageOption;
37
37
  class MessageCommandBuilder {
38
38
  constructor() {
39
- this.type = 'MESSAGE_COMMAND';
39
+ this.builder = 'MESSAGE_COMMAND';
40
40
  this.name = '';
41
41
  this.description = '';
42
42
  this.options = [];
43
43
  this.validateOptions = false;
44
+ this.requiredPermissions = [];
44
45
  this.allowExecuteInDM = true;
45
46
  this.allowExecuteByBots = false;
46
47
  this.execute = (options) => { };
@@ -51,6 +52,12 @@ class MessageCommandBuilder {
51
52
  this.name = name;
52
53
  return this;
53
54
  }
55
+ setRequiredPermissions(permissions) {
56
+ if (!permissions || !Array.isArray(permissions))
57
+ throw new Error('permissions must be an array.');
58
+ this.requiredPermissions = permissions;
59
+ return this;
60
+ }
54
61
  setAllowExecuteInDM(allowExecuteInDM) {
55
62
  if (typeof allowExecuteInDM !== 'boolean')
56
63
  throw new Error('allowExecuteInDM must be a boolean.');
@@ -1,3 +1,5 @@
1
1
  import { Permissions } from "discord.js";
2
+ import { InteractionCommandBuilder } from './classes/builders/InteractionCommandBuilder';
3
+ import { MessageCommandBuilder } from './classes/builders/MessageCommandBuilder';
2
4
  import { Config } from "./classes/Config";
3
- export declare function commandPermissions(commandName: string, memberPermissions: Permissions | null, configConmmandPermissions?: Config['permissions']['messageCommands'] | Config['permissions']['interactionCommands']): boolean;
5
+ export declare function commandPermissions(commandName: string, memberPermissions?: Permissions, configConmmandPermissions?: Config['permissions']['messageCommands'] | Config['permissions']['interactionCommands'], builder?: InteractionCommandBuilder | MessageCommandBuilder): boolean;
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.commandPermissions = void 0;
4
- function commandPermissions(commandName, memberPermissions, configConmmandPermissions) {
4
+ function commandPermissions(commandName, memberPermissions, configConmmandPermissions, builder) {
5
+ var _a, _b;
5
6
  if (!(configConmmandPermissions === null || configConmmandPermissions === void 0 ? void 0 : configConmmandPermissions.enabled))
6
7
  return true;
7
- const command = configConmmandPermissions.commands.find(c => c.command.toLowerCase() === commandName.toLowerCase());
8
- if (!command)
9
- return true;
8
+ const command = (_a = configConmmandPermissions.commands.find(c => c.command.toLowerCase() === commandName.toLowerCase())) !== null && _a !== void 0 ? _a : { permissions: (_b = builder === null || builder === void 0 ? void 0 : builder.requiredPermissions) !== null && _b !== void 0 ? _b : [] };
10
9
  if (!command.permissions.length)
11
10
  return true;
12
11
  return memberPermissions ? memberPermissions.has(command.permissions) : false;
@@ -4,5 +4,6 @@ exports.token = exports.flags = void 0;
4
4
  const commander_1 = require("commander");
5
5
  exports.flags = commander_1.program
6
6
  .option('-t, --token <token>', 'Replace used bot token')
7
+ .option('-D, --debugmode', 'Enabled debug mode')
7
8
  .parse().opts();
8
9
  exports.token = exports.flags.token;
@@ -2,11 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.logger = void 0;
4
4
  const fallout_utility_1 = require("fallout-utility");
5
+ const flags_1 = require("./flags");
5
6
  function logger(stringifyJSON, debugmode = false) {
6
7
  return new fallout_utility_1.Logger("Main", {
7
8
  addPrefixToEveryJsonNewLines: stringifyJSON,
8
9
  stringifyJSON: stringifyJSON,
9
- setDebugging: debugmode
10
+ setDebugging: flags_1.flags.debugmode || debugmode
10
11
  });
11
12
  }
12
13
  exports.logger = logger;
@@ -36,7 +36,7 @@ function loadModules(client) {
36
36
  throw new Error(script + ' onStart is not defined or returned false.');
37
37
  if (module_.commands) {
38
38
  for (const command of module_.commands) {
39
- if (command.type === 'MESSAGE_COMMAND' || command.type === 'INTERACTION_COMMAND')
39
+ if (command.builder === 'MESSAGE_COMMAND' || command.builder === 'INTERACTION_COMMAND')
40
40
  commands.push(command);
41
41
  }
42
42
  }
@@ -51,7 +51,7 @@ function loadModules(client) {
51
51
  logger.error(`A message command name is not defined in ${script}`);
52
52
  return false;
53
53
  }
54
- if (c.type === 'MESSAGE_COMMAND' && c.options.length && c.options.some(o => !o.name)) {
54
+ if (c.builder === 'MESSAGE_COMMAND' && c.options.length && c.options.some(o => !o.name)) {
55
55
  logger.error(`A message command option name is not defined in ${script}`);
56
56
  return false;
57
57
  }
@@ -1,2 +1,5 @@
1
+ import { InteractionCommandBuilder } from './classes/builders/InteractionCommandBuilder';
2
+ import { SlashCommandBuilder } from '@discordjs/builders';
1
3
  import { RecipleClient } from "./classes/Client";
2
- export declare function registerInteractionCommands(client: RecipleClient): Promise<void>;
4
+ import { ApplicationCommandData } from 'discord.js';
5
+ export declare function registerInteractionCommands(client: RecipleClient, cmds?: (InteractionCommandBuilder | SlashCommandBuilder | ApplicationCommandData)[]): Promise<void>;
@@ -10,23 +10,27 @@ 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) {
14
- var _a, _b, _c;
13
+ function registerInteractionCommands(client, cmds) {
14
+ var _a, _b, _c, _d;
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
- const commands = Object.values(client.commands.INTERACTION_COMMANDS).map(c => c.toJSON());
16
+ const commands = (_a = Object.values(cmds !== null && cmds !== void 0 ? cmds : client.commands.INTERACTION_COMMANDS).map(c => {
17
+ if (typeof c.toJSON !== 'undefined')
18
+ return c.toJSON();
19
+ return c;
20
+ })) !== null && _a !== void 0 ? _a : [];
17
21
  if (!commands.length) {
18
22
  client.logger.warn('No interaction commands found.');
19
23
  return;
20
24
  }
21
- if (!((_a = client.config) === null || _a === void 0 ? void 0 : _a.commands.interactionCommand.guilds.length)) {
22
- yield ((_b = client.application) === null || _b === void 0 ? void 0 : _b.commands.set(commands).catch(e => client.logger.error(e)));
25
+ if (!((_b = client.config) === null || _b === void 0 ? void 0 : _b.commands.interactionCommand.guilds.length)) {
26
+ yield ((_c = client.application) === null || _c === void 0 ? void 0 : _c.commands.set(commands).catch(e => client.logger.error(e)));
23
27
  client.logger.warn('No guilds were specified for interaction commands. Registered commands for all guilds.');
24
28
  }
25
29
  else {
26
30
  const guilds = typeof client.config.commands.interactionCommand.guilds === 'string' ? [client.config.commands.interactionCommand.guilds] : client.config.commands.interactionCommand.guilds;
27
31
  client.logger.warn(`Registering ${commands.length} interaction commands for ${guilds.length} guild(s).`);
28
32
  for (const guild of guilds) {
29
- yield ((_c = client.application) === null || _c === void 0 ? void 0 : _c.commands.set(commands, guild).catch(e => client.logger.error(e)));
33
+ yield ((_d = client.application) === null || _d === void 0 ? void 0 : _d.commands.set(commands, guild).catch(e => client.logger.error(e)));
30
34
  client.logger.warn(`Registered ${commands.length} interaction commands for ${guild}.`);
31
35
  }
32
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reciple",
3
- "version": "1.0.17",
3
+ "version": "1.1.0",
4
4
  "description": "A Discord.js bot",
5
5
  "author": "FalloutStudios",
6
6
  "license": "GPL-3.0",
@@ -17,11 +17,11 @@
17
17
  ],
18
18
  "scripts": {
19
19
  "clean": "rimraf bin",
20
- "compile": "npm run clean && tsc",
21
- "build": "npm run compile && npm un reciple -g && npm i ./ -g",
22
- "build:publish": "npm run build && npm publish",
20
+ "compile": "yarn clean && tsc",
21
+ "build": "yarn compile && npm un reciple -g && npm i ./ -g",
22
+ "build:publish": "yarn run build && npm publish",
23
23
  "test": "cd test && reciple",
24
- "test:compile": "npm run build && npm run test:run"
24
+ "test:compile": "yarn run build && yarn test:run"
25
25
  },
26
26
  "dependencies": {
27
27
  "commander": "^9.2.0",