From 283caba6cd76d0ddd67141f170b46fc63dabd682 Mon Sep 17 00:00:00 2001 From: GRZ4NA Date: Mon, 5 Jul 2021 23:18:18 +0200 Subject: [PATCH] 2.0.0-beta2 --- README.md | 14 ++++++++------ package-lock.json | 4 ++-- package.json | 2 +- src/Bot.ts | 23 +++++++---------------- src/Help.ts | 1 + 5 files changed, 19 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 3cc8454..964e145 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ # CommandBot -**2.0.0-beta** +**2.0.0-beta2** + +> [IMPORTANT] +> Upgrading to this version from 1.1.3 may require additional changes in your code since 2.0.0 is not fully backwards compatible Discord.js framework that helps you build your own Discord bot. @@ -59,10 +62,9 @@ import { Bot, Command } from "commandbot"; const bot = new Bot({ name: "Command bot", // Name of your bot prefix: "!", // Prefix used to call commands - argumentSeparator: ",", // Used to get arguments from message - helpCommand: true, // Enable or disable the *help* command (optional) - clientOptions: undefined, // Instance of ClientOptions from Discord.js - token: "", // Bot token from Discord Developer Portal (optional, you can pass the token in *start* method) + argumentSeparator: ",", // Used to get arguments from message (optional) + clientOptions: undefined, // Instance of ClientOptions from Discord.js (optional) + token: "", // Bot token from Discord Developer Portal (optional, you can pass the token in the *start* method) }); ``` @@ -86,7 +88,6 @@ The main object of this library has the following properties - **commands** - _CommandManager_ - base of the command system (see [Commands](#commands)) - **config** - _object_ - object that stores the login token and _helpMessage_ value from the constructor - **messages** - _SystemMessageManager_ - object instance containing all configuration parameters for built-in messages (see [Customization and built-in messages](#customization-and-built-in-messages)) -- **on** - _object_ - object containing function that trigger on specified events (see [Events](#events)) ## Commands @@ -251,6 +252,7 @@ All configuration parameters for messages are stored in _messages_ property (exa Configuration parameters are stored in _messages.help_ property +- **enabled** - _boolean_ - enables or disables the help message - **title** - _string_ - title of help message - **bottomText** - _string_ - text shown below the title - **color** - _[ColorResolvable](https://discord.js.org/#/docs/main/stable/typedef/ColorResolvable)_ - color of the embedded content diff --git a/package-lock.json b/package-lock.json index c806952..8c40e16 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "commandbot", - "version": "2.0.0-beta", + "version": "2.0.0-beta2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "commandbot", - "version": "2.0.0-beta", + "version": "2.0.0-beta2", "license": "MIT", "dependencies": { "discord.js": "^12.5.3" diff --git a/package.json b/package.json index 908d4c9..9fcbfbb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "commandbot", - "version": "2.0.0-beta", + "version": "2.0.0-beta2", "description": "A framework that helps you create your own Discord bot easier.", "type": "module", "main": "dist/index.js", diff --git a/src/Bot.ts b/src/Bot.ts index dbdeb0d..c35d5e8 100644 --- a/src/Bot.ts +++ b/src/Bot.ts @@ -21,15 +21,10 @@ export declare interface Bot { ): this; on(event: "error", listener: (e: any) => void): this; } -interface ConfigurationOptions { - token?: string; - helpCommand: boolean; -} interface ConstructorOptions { name: string; prefix: string; argumentSeparator?: string; - helpCommand?: boolean; clientOptions?: ClientOptions; token?: string; } @@ -39,7 +34,7 @@ export class Bot extends EventEmitter { name: string; client: Client; commands: CommandManager; - config: ConfigurationOptions; + token: string; messages: { help: HelpMessageParams; system: SystemMessageManager; @@ -52,7 +47,6 @@ export class Bot extends EventEmitter { * @param {string} options.name - name of your bot * @param {string} options.prefix - prefix used to call commands * @param {string} [options.argumentSeparator=','] - used to get arguments from message - * @param {boolean} [options.helpCommand = true] - enable or disable the *help* command * @param {ClientOptions} [options.clientOptions] - client options from Discord.js * @param {string} [options.token] - bot token from Discord Developer Portal */ @@ -64,13 +58,10 @@ export class Bot extends EventEmitter { options.prefix, options.argumentSeparator ); - this.config = { - token: options.token, - helpCommand: - options.helpCommand != undefined ? options.helpCommand : true, - }; + this.token = options.token || ""; this.messages = { help: { + enabled: true, title: "Help", description: "List of all available commands", color: "#ff5500", @@ -91,8 +82,8 @@ export class Bot extends EventEmitter { try { console.log(`Bot name: ${this.name}`); console.log(`Prefix: ${this.commands.prefix} \n`); - const loginToken: string = token || this.config.token || ""; - if (loginToken === "") { + this.token = token || this.token; + if (this.token === "") { throw new ReferenceError( 'No token specified. Please pass your Discord application token as an argument to the "start" method or in the constructor' ); @@ -102,7 +93,7 @@ export class Bot extends EventEmitter { http.createServer().listen(port); } console.log("Starting modules..."); - if (this.config.helpCommand) { + if (this.messages.help.enabled === true) { const helpMsg: Command = new HelpMessage( this.commands, this.messages.help, @@ -111,7 +102,7 @@ export class Bot extends EventEmitter { this.commands.add(helpMsg); } console.log("Connecting to Discord..."); - if (await this.client.login(loginToken)) { + if (await this.client.login(this.token)) { this.client.on("ready", () => { this.emit("ready"); }); diff --git a/src/Help.ts b/src/Help.ts index 3bf845d..4c6c770 100644 --- a/src/Help.ts +++ b/src/Help.ts @@ -2,6 +2,7 @@ import { ColorResolvable, MessageEmbed } from "discord.js"; import { Command, CommandManager } from "./Command.js"; export interface HelpMessageParams { + enabled: boolean; title: string; bottomText: string; color: ColorResolvable;