reciple 1.0.0 → 1.0.3

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)
@@ -12,8 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.RecipleClient = void 0;
13
13
  const discord_js_1 = require("discord.js");
14
14
  const fallout_utility_1 = require("fallout-utility");
15
- const MessageCommandBuilder_1 = require("./builders/MessageCommandBuilder");
16
- const InteractionCommandBuilder_1 = require("./builders/InteractionCommandBuilder");
17
15
  const registerInteractionCommands_1 = require("../registerInteractionCommands");
18
16
  const logger_1 = require("../logger");
19
17
  const modules_1 = require("../modules");
@@ -43,10 +41,10 @@ class RecipleClient extends discord_js_1.Client {
43
41
  for (const command of modules.commands) {
44
42
  if (!command.name)
45
43
  continue;
46
- if (command instanceof MessageCommandBuilder_1.MessageCommandBuilder) {
44
+ if (command.type === 'MESSAGE_COMMAND') {
47
45
  this.commands.MESSAGE_COMMANDS[command.name] = command;
48
46
  }
49
- else if (command instanceof InteractionCommandBuilder_1.InteractionCommandBuilder) {
47
+ else if (command.type === 'INTERACTION_COMMAND') {
50
48
  this.commands.INTERACTION_COMMANDS[command.name] = command;
51
49
  }
52
50
  }
@@ -85,9 +83,7 @@ class RecipleClient extends discord_js_1.Client {
85
83
  if (parseCommand && parseCommand.command) {
86
84
  const command = this.commands.MESSAGE_COMMANDS[parseCommand.command];
87
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)) {
88
- if (!command.allowExecuteInDM && message.channel.type === 'DM')
89
- return this;
90
- if (!command.allowExecuteByBots && (message.author.bot || message.author.system))
86
+ if (!command.allowExecuteInDM && message.channel.type === 'DM' || !command.allowExecuteByBots && (message.author.bot || message.author.system))
91
87
  return this;
92
88
  if (command.validateOptions && !command.getCommandOptionValues(parseCommand)) {
93
89
  yield message.reply(((_e = this.config) === null || _e === void 0 ? void 0 : _e.messages.notEnoughArguments) || 'Not enough arguments.').catch((err) => this.logger.error(err));
@@ -99,7 +95,7 @@ class RecipleClient extends discord_js_1.Client {
99
95
  builder: command,
100
96
  client: this
101
97
  };
102
- yield Promise.resolve(command.execute(options));
98
+ yield Promise.resolve(command.execute(options)).catch(err => { this.logger.error(`An error occured executing "${command.name}"`); this.logger.error(err); });
103
99
  this.emit('recipleMessageCommandCreate', options);
104
100
  }
105
101
  }
@@ -121,7 +117,7 @@ class RecipleClient extends discord_js_1.Client {
121
117
  builder: command,
122
118
  client: this
123
119
  };
124
- yield Promise.resolve(command.execute(options));
120
+ yield Promise.resolve(command.execute(options)).catch(err => { this.logger.error(`An error occured executing "${command.name}"`); this.logger.error(err); });
125
121
  this.emit('recipleInteractionCommandCreate', options);
126
122
  }
127
123
  return this;
@@ -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
  }
@@ -8,6 +8,7 @@ export interface RecipleInteractionCommandExecute {
8
8
  client: RecipleClient;
9
9
  }
10
10
  export declare class InteractionCommandBuilder extends SlashCommandBuilder {
11
+ readonly type: string;
11
12
  allowExecuteInDM: boolean;
12
13
  execute: (options: RecipleInteractionCommandExecute) => void;
13
14
  setAllowExecuteInDM(allowExecuteInDM: boolean): InteractionCommandBuilder;
@@ -5,6 +5,7 @@ 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
9
  this.allowExecuteInDM = true;
9
10
  this.execute = (options) => { };
10
11
  }
@@ -15,20 +15,21 @@ 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
+ readonly type: string;
32
33
  name: string;
33
34
  description: string;
34
35
  options: MessageOption[];
@@ -36,6 +36,7 @@ class MessageOption {
36
36
  exports.MessageOption = MessageOption;
37
37
  class MessageCommandBuilder {
38
38
  constructor() {
39
+ this.type = 'MESSAGE_COMMAND';
39
40
  this.name = '';
40
41
  this.description = '';
41
42
  this.options = [];
@@ -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;
@@ -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;
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.loadModules = void 0;
16
16
  const fs_1 = require("fs");
17
17
  const MessageCommandBuilder_1 = require("./classes/builders/MessageCommandBuilder");
18
- const InteractionCommandBuilder_1 = require("./classes/builders/InteractionCommandBuilder");
19
18
  const path_1 = __importDefault(require("path"));
20
19
  function loadModules(client) {
21
20
  var _a;
@@ -38,10 +37,8 @@ function loadModules(client) {
38
37
  throw new Error(script + ' onStart is not defined or returned false.');
39
38
  if (module_.commands) {
40
39
  for (const command of module_.commands) {
41
- if (!(command instanceof MessageCommandBuilder_1.MessageCommandBuilder) && !(command instanceof InteractionCommandBuilder_1.InteractionCommandBuilder)) {
42
- continue;
43
- }
44
- commands.push(command);
40
+ if (command.type === 'MESSAGE_COMMAND' || command.type === 'INTERACTION_COMMAND')
41
+ commands.push(command);
45
42
  }
46
43
  }
47
44
  }
@@ -55,7 +52,7 @@ function loadModules(client) {
55
52
  logger.error(`A message command name is not defined in ${script}`);
56
53
  return false;
57
54
  }
58
- if (c instanceof MessageCommandBuilder_1.MessageCommandBuilder && c.options.some(o => !o.name)) {
55
+ if (c instanceof MessageCommandBuilder_1.MessageCommandBuilder && c.options.length && c.options.some(o => !o.name)) {
59
56
  logger.error(`A message command option name is not defined in ${script}`);
60
57
  return false;
61
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reciple",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
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