From 4880e47f3435adbd786b962647dd12720d1433d5 Mon Sep 17 00:00:00 2001 From: GRZ4NA Date: Mon, 28 Jun 2021 02:20:40 +0200 Subject: [PATCH] 1.1.0 -> permissionCheck property --- README.md | 5 ++++- package-lock.json | 4 ++-- package.json | 2 +- src/Command.ts | 6 +++++- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 844e0e3..9a2c3d6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # CommandBot -**1.0.0** +**1.1.0** Discord.js framework that helps you build your own Discord bot. @@ -80,6 +80,7 @@ The main object of this library has the following properties - **visible** - *boolean* - show command in the *help message* (optional, defaults to *true*) - **description** - *string* - command description shown in the *help message* (optional) - **usage** - *string* - command usage description shown in the *help message* (optional) +- **permissionCheck** - *"ALL" | "ANY"* - specifies if the caller has to have all of the specified permissions or any of that (optional, default value: "ANY") - **permissions** - *[PermissionResolvable](https://discord.js.org/#/docs/main/stable/typedef/PermissionResolvable)* - permissions needed to run the command (optional) - **aliases** - *string | string[]* - other words that can trigger the command with prefix (optional) - **keywords** - *string | string[]* - other words that can trigger the command without prefix (optional) @@ -207,6 +208,8 @@ Each message can be customized using these properties - **accentColor** - *[ColorResolvable](https://discord.js.org/#/docs/main/stable/typedef/ColorResolvable)* - color of the embedded content - **showTimestamp** - *boolean* - show time and date at the bottom of the embedded content - **footer** - *string* - footer of the embedded content + +The *messages.system* also contains a *deleteTimeout* property. It specifies the time (in ms) after which a system message will be deleted. Set it to *Infinity* to never delete messages (default value). ## Complete example ```javascript import { Bot, Command } from 'commandbot'; diff --git a/package-lock.json b/package-lock.json index 64a6377..4035a98 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "commandbot", - "version": "1.0.0", + "version": "1.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "commandbot", - "version": "1.0.0", + "version": "1.1.0", "license": "MIT", "dependencies": { "discord.js": "^12.5.3" diff --git a/package.json b/package.json index 4d214d3..c301d76 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "commandbot", - "version": "1.0.0", + "version": "1.1.0", "description": "A framework that helps you create your own Discord bot easier.", "type": "module", "main": "dist/index.js", diff --git a/src/Command.ts b/src/Command.ts index f18700c..2e066e4 100644 --- a/src/Command.ts +++ b/src/Command.ts @@ -8,6 +8,7 @@ interface CommandBuilder { keywords?: string[] | string, description?: string, usage?: string, + permissionCheck?: PermissionCheckTypes, permissions?: PermissionResolvable, visible?: boolean function: (message?: Message, cmdArguments?: string[]) => void | string | MessageEmbed; @@ -18,6 +19,7 @@ interface CommandMessageStructure { command: Command | null } type GetMode = 'ALL' | 'PREFIX' | 'NO_PREFIX'; +type PermissionCheckTypes = 'ALL' | 'ANY'; //ERROR CLASSES class PermissionsError { @@ -39,6 +41,7 @@ class Command { keywords: string[]; description: string; usage: string; + permissionCheck: PermissionCheckTypes; permissions: Permissions; visible: boolean; private function: (message?: Message, cmdArguments?: string[]) => void | string | MessageEmbed; @@ -49,13 +52,14 @@ class Command { this.keywords = Command.processPhrase(options.keywords); this.description = options.description || "No description"; this.usage = options.usage || ""; + this.permissionCheck = options.permissionCheck == 'ALL' || options.permissionCheck == 'ANY' ? options.permissionCheck : "ANY"; this.permissions = new Permissions(options.permissions || 0); this.visible = options.visible != undefined ? options.visible : true; this.function = options.function; } async start(message?: Message, cmdArguments?: string[]) : Promise { const memberPermissions : Readonly = message?.member?.permissions || new Permissions(0); - if(memberPermissions.has(this.permissions, true)) { + if(this.permissionCheck == 'ALL' ? memberPermissions.has(this.permissions, true) : memberPermissions.any(this.permissions, true)) { const fnResult = await this.function(message, cmdArguments); if(typeof fnResult == 'string') { await message?.reply(fnResult);