reciple 1.0.1 → 1.0.4

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/README.md CHANGED
@@ -1,2 +1,61 @@
1
- # reciple
2
- A Discord.js bot
1
+ <h1 align="center">
2
+ <img src="https://i.imgur.com/8pYGOWW.png" width="50%">
3
+ <br>
4
+ <img alt="Lines of code" src="https://img.shields.io/tokei/lines/github/FalloutStudios/Reciple">
5
+ <img alt="GitHub" src="https://img.shields.io/github/license/FalloutStudios/Reciple">
6
+ <a href="https://www.codefactor.io/repository/github/falloutstudios/reciple/overview/main"><img src="https://www.codefactor.io/repository/github/falloutstudios/reciple/badge/main" alt="CodeFactor"></a>
7
+ </h1>
8
+
9
+ A simple modular Discord bot made with Discord.js written in TypeScript.
10
+
11
+
12
+ ## Installation
13
+ To install the bot, run the following command:
14
+
15
+ ```bash
16
+ npm i reciple
17
+ ```
18
+
19
+ You can initialize the bot to the current directory with the following command:
20
+
21
+ ```bash
22
+ reciple
23
+ ```
24
+
25
+ It will ask you to continue if the directory is not empty type `y` to continue after the bot has been initialized it will ask you for your `TOKEN`.
26
+
27
+ > You can always change the token on `reciple.yml`
28
+
29
+ ## Config
30
+
31
+ You can configure the bot on `reciple.yml` in the bot root directory.
32
+
33
+ ### Token
34
+
35
+ You can directly change the token on `reciple.yml` like so:
36
+
37
+ ```yml
38
+ token: "YOUR_TOKEN_HERE"
39
+ ```
40
+
41
+ Using environment variables is also supported:
42
+
43
+ ```yml
44
+ token: "env:TOKEN_VARIABLE"
45
+ ```
46
+
47
+ You can override the token on the command line like so:
48
+
49
+ ```bash
50
+ reciple --token "YOUR_TOKEN_HERE"
51
+ ```
52
+
53
+ ## Running the bot
54
+ To run the bot, run the following command:
55
+
56
+ ```bash
57
+ reciple
58
+ ```
59
+
60
+ > ## Fun Fact
61
+ > The name reciple is from a minecraft bug. The bug was a misspelling of the word `recipe`. [Mojang Reciple](https://bugs.mojang.com/browse/MC-225837)
@@ -31,4 +31,5 @@ export declare class RecipleClient extends Client {
31
31
  addCommandListeners(): RecipleClient;
32
32
  messageCommandExecute(message: Message): Promise<RecipleClient>;
33
33
  interactionCommandExecute(interaction: Interaction): Promise<RecipleClient>;
34
+ private _commandExecuteError;
34
35
  }
@@ -17,6 +17,7 @@ const logger_1 = require("../logger");
17
17
  const modules_1 = require("../modules");
18
18
  const version_1 = require("../version");
19
19
  const commandPermissions_1 = require("../commandPermissions");
20
+ const isIgnoredChannel_1 = require("../isIgnoredChannel");
20
21
  class RecipleClient extends discord_js_1.Client {
21
22
  constructor(options) {
22
23
  super(options);
@@ -75,20 +76,18 @@ class RecipleClient extends discord_js_1.Client {
75
76
  return this;
76
77
  }
77
78
  messageCommandExecute(message) {
78
- var _a, _b, _c, _d, _e;
79
+ var _a, _b, _c, _d, _e, _f, _g;
79
80
  return __awaiter(this, void 0, void 0, function* () {
80
- if (!message.content)
81
+ if (!message.content || !((_a = this.config) === null || _a === void 0 ? void 0 : _a.commands.messageCommand.enabled))
81
82
  return this;
82
- const parseCommand = (0, fallout_utility_1.getCommand)(message.content, ((_a = this.config) === null || _a === void 0 ? void 0 : _a.prefix) || '!', ((_b = this.config) === null || _b === void 0 ? void 0 : _b.commands.messageCommand.commandArgumentSeparator) || ' ');
83
+ 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) || ' ');
83
84
  if (parseCommand && parseCommand.command) {
84
85
  const command = this.commands.MESSAGE_COMMANDS[parseCommand.command];
85
- if (command && (0, commandPermissions_1.commandPermissions)(command.name, ((_c = message.member) === null || _c === void 0 ? void 0 : _c.permissions) || null, (_d = this.config) === null || _d === void 0 ? void 0 : _d.permissions.messageCommands)) {
86
- if (!command.allowExecuteInDM && message.channel.type === 'DM')
87
- return this;
88
- if (!command.allowExecuteByBots && (message.author.bot || message.author.system))
86
+ if (command && (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)) {
87
+ 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))
89
88
  return this;
90
89
  if (command.validateOptions && !command.getCommandOptionValues(parseCommand)) {
91
- yield message.reply(((_e = this.config) === null || _e === void 0 ? void 0 : _e.messages.notEnoughArguments) || 'Not enough arguments.').catch((err) => this.logger.error(err));
90
+ yield message.reply(((_g = this.config) === null || _g === void 0 ? void 0 : _g.messages.notEnoughArguments) || 'Not enough arguments.').catch((err) => this.logger.error(err));
92
91
  return this;
93
92
  }
94
93
  const options = {
@@ -97,7 +96,7 @@ class RecipleClient extends discord_js_1.Client {
97
96
  builder: command,
98
97
  client: this
99
98
  };
100
- yield Promise.resolve(command.execute(options));
99
+ yield Promise.resolve(command.execute(options)).catch(err => this._commandExecuteError(err, options));
101
100
  this.emit('recipleMessageCommandCreate', options);
102
101
  }
103
102
  }
@@ -105,13 +104,13 @@ class RecipleClient extends discord_js_1.Client {
105
104
  });
106
105
  }
107
106
  interactionCommandExecute(interaction) {
108
- var _a;
107
+ var _a, _b, _c;
109
108
  return __awaiter(this, void 0, void 0, function* () {
110
- if (!interaction || !interaction.isCommand())
109
+ if (!interaction || !interaction.isCommand() || !((_a = this.config) === null || _a === void 0 ? void 0 : _a.commands.interactionCommand.enabled))
111
110
  return this;
112
111
  const command = this.commands.INTERACTION_COMMANDS[interaction.commandName];
113
- if (command && (0, commandPermissions_1.commandPermissions)(command.name, interaction.memberPermissions, (_a = this.config) === null || _a === void 0 ? void 0 : _a.permissions.interactionCommands)) {
114
- if (!command.allowExecuteInDM && interaction.member === null)
112
+ if (command && (0, commandPermissions_1.commandPermissions)(command.name, interaction.memberPermissions, (_b = this.config) === null || _b === void 0 ? void 0 : _b.permissions.interactionCommands)) {
113
+ if (!command.allowExecuteInDM && interaction.member === null || (0, isIgnoredChannel_1.isIgnoredChannel)(interaction.channelId, (_c = this.config) === null || _c === void 0 ? void 0 : _c.ignoredChannels))
115
114
  return this;
116
115
  const options = {
117
116
  interaction: interaction,
@@ -119,11 +118,31 @@ class RecipleClient extends discord_js_1.Client {
119
118
  builder: command,
120
119
  client: this
121
120
  };
122
- yield Promise.resolve(command.execute(options));
121
+ yield Promise.resolve(command.execute(options)).catch(err => this._commandExecuteError(err, options));
123
122
  this.emit('recipleInteractionCommandCreate', options);
124
123
  }
125
124
  return this;
126
125
  });
127
126
  }
127
+ _commandExecuteError(err, command) {
128
+ var _a, _b, _c;
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ this.logger.error(`An error occured executing ${command.builder.type == 'MESSAGE_COMMAND' ? 'message' : 'interaction'} command "${command.builder.name}"`);
131
+ this.logger.error(err);
132
+ if (!err || !command)
133
+ return;
134
+ if (command === null || command === void 0 ? void 0 : command.message) {
135
+ yield command.message.reply(((_a = this.config) === null || _a === void 0 ? void 0 : _a.messages.error) || 'An error occured.').catch((e) => this.logger.error(e));
136
+ }
137
+ else if (command === null || command === void 0 ? void 0 : command.interaction) {
138
+ if (!(command === null || command === void 0 ? void 0 : command.interaction.deferred)) {
139
+ yield command.interaction.reply(((_b = this.config) === null || _b === void 0 ? void 0 : _b.messages.error) || 'An error occured.').catch((e) => this.logger.error(e));
140
+ }
141
+ else {
142
+ yield command.interaction.editReply(((_c = this.config) === null || _c === void 0 ? void 0 : _c.messages.error) || 'An error occured.').catch((e) => this.logger.error(e));
143
+ }
144
+ }
145
+ });
146
+ }
128
147
  }
129
148
  exports.RecipleClient = RecipleClient;
@@ -43,6 +43,7 @@ export interface Config {
43
43
  [key: string]: MessageOptions | string;
44
44
  };
45
45
  modulesFolder: string;
46
+ version?: string;
46
47
  }
47
48
  export declare class RecipleConfig {
48
49
  config?: Config;
@@ -51,5 +52,6 @@ export declare class RecipleConfig {
51
52
  parseConfig(): RecipleConfig;
52
53
  getConfig(): Config;
53
54
  parseToken(askIfNull?: boolean): string | null;
55
+ private isSupportedConfig;
54
56
  private askToken;
55
57
  }
@@ -9,6 +9,7 @@ const fs_1 = require("fs");
9
9
  const flags_1 = require("../flags");
10
10
  const path_1 = __importDefault(require("path"));
11
11
  const yaml_1 = __importDefault(require("yaml"));
12
+ const version_1 = require("../version");
12
13
  class RecipleConfig {
13
14
  constructor(configPath) {
14
15
  this.configPath = './reciple.yml';
@@ -17,11 +18,12 @@ class RecipleConfig {
17
18
  this.configPath = configPath;
18
19
  }
19
20
  parseConfig() {
21
+ var _a;
20
22
  if (!(0, fs_1.existsSync)(this.configPath)) {
21
23
  const defaultConfigPath = path_1.default.join(__dirname, '../../../resource/reciple.yml');
22
24
  if (!(0, fs_1.existsSync)(defaultConfigPath))
23
25
  throw new Error('Default Config file not found. Please reinstall Reciple.');
24
- const defaultConfig = (0, fs_1.readFileSync)(defaultConfigPath, 'utf-8');
26
+ const defaultConfig = (0, fallout_utility_1.replaceAll)((0, fs_1.readFileSync)(defaultConfigPath, 'utf-8'), 'VERSION', version_1.version);
25
27
  (0, fs_1.writeFileSync)(this.configPath, defaultConfig, 'utf-8');
26
28
  if (!(0, fs_1.existsSync)(this.configPath))
27
29
  throw new Error('Failed to create config file.');
@@ -36,6 +38,8 @@ class RecipleConfig {
36
38
  throw new Error('Failed to read config file.');
37
39
  const config = (0, fs_1.readFileSync)(this.configPath, 'utf-8');
38
40
  this.config = yaml_1.default.parse(config);
41
+ if (!this.isSupportedConfig())
42
+ throw new Error('Unsupported config version. Your config version: ' + (((_a = this.config) === null || _a === void 0 ? void 0 : _a.version) || 'No version specified.') + ', Reciple version: ' + version_1.version);
39
43
  return this;
40
44
  }
41
45
  getConfig() {
@@ -61,6 +65,10 @@ class RecipleConfig {
61
65
  }
62
66
  return token || (askIfNull ? this.askToken() : null);
63
67
  }
68
+ isSupportedConfig() {
69
+ var _a;
70
+ return (((_a = this.config) === null || _a === void 0 ? void 0 : _a.version) && this.config.version != version_1.version) ? false : true;
71
+ }
64
72
  askToken() {
65
73
  return flags_1.token || (0, fallout_utility_1.input)({ 'text': 'Bot Token >>> ', echo: '*', repeatIfEmpty: true, exitStrings: ['exit', 'quit', ''], sigint: true }) || null;
66
74
  }
@@ -15,18 +15,18 @@ export interface RecipleMessageCommandExecute {
15
15
  }
16
16
  export interface MessageCommandValidatedOption {
17
17
  name: string;
18
- value: any;
18
+ value: string;
19
19
  required: boolean;
20
20
  }
21
21
  export declare class MessageOption {
22
22
  name: string;
23
23
  description: string;
24
24
  required: boolean;
25
- validate: (value: any) => boolean;
25
+ validate: (value: string) => boolean;
26
26
  setName(name: string): MessageOption;
27
27
  setDescription(description: string): MessageOption;
28
28
  setRequired(required: boolean): MessageOption;
29
- setValidator(validator: (value: any) => boolean): MessageOption;
29
+ setValidator(validator: (value: string) => boolean): MessageOption;
30
30
  }
31
31
  export declare class MessageCommandBuilder {
32
32
  readonly type: string;
@@ -1,3 +1,3 @@
1
1
  import { Permissions } from "discord.js";
2
2
  import { Config } from "./classes/Config";
3
- export declare function commandPermissions(commandName: string, member: Permissions | null, permissions?: Config['permissions']['messageCommands'] | Config['permissions']['interactionCommands']): boolean;
3
+ export declare function commandPermissions(commandName: string, memberPermissions: Permissions | null, configConmmandPermissions?: Config['permissions']['messageCommands'] | Config['permissions']['interactionCommands']): boolean;
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.commandPermissions = void 0;
4
- function commandPermissions(commandName, member, permissions) {
5
- if (!(permissions === null || permissions === void 0 ? void 0 : permissions.enabled))
4
+ function commandPermissions(commandName, memberPermissions, configConmmandPermissions) {
5
+ if (!(configConmmandPermissions === null || configConmmandPermissions === void 0 ? void 0 : configConmmandPermissions.enabled))
6
6
  return true;
7
- const command = permissions.commands.find(c => c.command.toLowerCase() === commandName.toLowerCase());
7
+ const command = configConmmandPermissions.commands.find(c => c.command.toLowerCase() === commandName.toLowerCase());
8
8
  if (!command)
9
9
  return true;
10
10
  if (!command.permissions.length)
11
11
  return true;
12
- return member ? member.has(command.permissions) : false;
12
+ return memberPermissions ? memberPermissions.has(command.permissions) : false;
13
13
  }
14
14
  exports.commandPermissions = commandPermissions;
@@ -1 +1,2 @@
1
+ export declare const flags: import("commander").OptionValues;
1
2
  export declare const token: any;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.token = void 0;
3
+ exports.token = exports.flags = void 0;
4
4
  const commander_1 = require("commander");
5
- const flags = commander_1.program
5
+ exports.flags = commander_1.program
6
6
  .option('-t, --token <token>', 'Replace used bot token')
7
7
  .parse().opts();
8
- exports.token = flags.token;
8
+ exports.token = exports.flags.token;
@@ -0,0 +1,2 @@
1
+ import { Config } from './classes/Config';
2
+ export declare function isIgnoredChannel(channelId: string, ignoredChannelsConfig?: Config["ignoredChannels"]): boolean;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isIgnoredChannel = void 0;
4
+ function isIgnoredChannel(channelId, ignoredChannelsConfig) {
5
+ if (!(ignoredChannelsConfig === null || ignoredChannelsConfig === void 0 ? void 0 : ignoredChannelsConfig.enabled))
6
+ return false;
7
+ if (ignoredChannelsConfig.channels.includes(channelId) && !ignoredChannelsConfig.convertToAllowList)
8
+ return false;
9
+ if (!ignoredChannelsConfig.channels.includes(channelId) && ignoredChannelsConfig.convertToAllowList)
10
+ return false;
11
+ return true;
12
+ }
13
+ exports.isIgnoredChannel = isIgnoredChannel;
@@ -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;
13
- onStart: (reciple: RecipleClient) => 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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reciple",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "description": "A Discord.js bot",
5
5
  "author": "FalloutStudios",
6
6
  "license": "GPL-3.0",
@@ -45,4 +45,6 @@ messages:
45
45
  noPermission: 'You do not have permission to use this command.'
46
46
  notEnoughArguments: 'Not enough arguments.'
47
47
 
48
- modulesFolder: 'modules'
48
+ modulesFolder: 'modules'
49
+
50
+ version: VERSION