Archived
Version 2.0.0
This commit is contained in:
1 parent
98a4b21a8d
commit
7cd2be09b6
6 files changed
+65
-55
No files matched your search
+11
-8
@@ -68,32 +68,35 @@
|
||||
- stability improvement - your bot won't crash if a command function throws an error. It will display an error message to the user instead.
|
||||
## 1.4.2
|
||||
- change from 1.4.1 now works with asynchronous functions as well (I forgot to add "await" in one place :D)
|
||||
## 1.5.0-beta1
|
||||
## 1.5.0
|
||||
### beta1
|
||||
- added command aliases
|
||||
+ add aliases by inserting an array into the first argument of the addCommand method (first element of the array is your command's name)
|
||||
+ aliases will display in the help message
|
||||
+ getCommand and addCommand methods have been reworked to handle this new feature properly (the usage is still the same and they are backwards compatible)
|
||||
- command permissions and keywords in "help" message are now being shown in separated lines (1 per line)
|
||||
- few tweaks and code cleanups
|
||||
## 1.5.0-beta2
|
||||
### beta2
|
||||
- fixed a bug that made the prefix stack up and make aliases unusable + caused "help" command to display incorrectly
|
||||
- changed the appearance of "command does not exist" message in "help" command to an error style
|
||||
- "help" command can now remove prefix if it was passed with an argument (for example: `!help !show` is going to act as intended now)
|
||||
## 1.5.0-beta3
|
||||
### beta3
|
||||
- "show" command can now display informations about servers (guilds)
|
||||
+ call it by using `show [your server ID]`
|
||||
+ you can only view informations about your own server (for security reasons)
|
||||
## 1.5.0
|
||||
### FINAL
|
||||
- some minor tweaks
|
||||
## 2.0.0-beta1
|
||||
- **no backwards compatibility** (`{admin: true}, all responses and old properties are not going to work anymore`)
|
||||
## 2.0.0 (this version is not compatible with features marked as deprecated in earlier versions)
|
||||
### beta1
|
||||
- string processor is now separated from the class (you can import it using `import { stringProcessor } from 'ezdiscordbot'`)
|
||||
- string processor is now included in `Message.reply()` and `Message.channel.send()` methods (it will replace square bracket expressions automatically)
|
||||
## 2.0.0-beta2
|
||||
### beta2
|
||||
- new command structure
|
||||
+ new "commands" property
|
||||
+ commandsList is being replaced with commands.list
|
||||
+ addCommand() is being replaced with commands.add() (new usage)
|
||||
+ getCommand() is being replaced with commands.get()
|
||||
+ old methods are still present and they can be used without any modifications (backwards compatible)
|
||||
+ more details in documentation
|
||||
+ more details in documentation
|
||||
### FINAL
|
||||
- minor tweaks
|
||||
+4
-40
@@ -3,6 +3,7 @@ import { Command, CommandManager } from './src/commands.js';
|
||||
import { createCommandHelp, createHelpCommandsList } from './src/generators/helpMessage.js';
|
||||
import { generateShowCommand } from './src/generators/showCommand.js';
|
||||
import { stringProcessor } from './src/stringProcessor.js';
|
||||
import { checkCommandAccess } from './src/permissions.js';
|
||||
import http from 'http';
|
||||
|
||||
class EasyDiscordBot {
|
||||
@@ -269,7 +270,7 @@ class EasyDiscordBot {
|
||||
this.events.onCommand(message);
|
||||
const command = this.commands.get(message.command.name);
|
||||
if(command) {
|
||||
if(await this.permissionsProxy(message, command)) {
|
||||
if(await checkCommandAccess(message, command)) {
|
||||
try {
|
||||
await command.execute(message);
|
||||
} catch (e) {
|
||||
@@ -334,7 +335,7 @@ class EasyDiscordBot {
|
||||
addCommand(name, description, permissions, callFunction, keywords, usage, hidden) {
|
||||
//BACKWARDS COMPATIBILITY (DEPRECATED)
|
||||
try {
|
||||
console.warn('WARN! This method is deprecated! Please use commands.add(options) instead.')
|
||||
console.warn('WARN! EasyDiscordBot.addCommand() is deprecated! Please use EasyDiscordBot.commands.add(options) instead.')
|
||||
const options = {
|
||||
name: name,
|
||||
description: description,
|
||||
@@ -353,7 +354,7 @@ class EasyDiscordBot {
|
||||
}
|
||||
getCommand(name) {
|
||||
//BACKWARDS COMPATIBILITY (DEPRECATED)
|
||||
console.warn('WARN! This method is deprecated! Please use commands.get(name) instead.')
|
||||
console.warn('WARN! EasyDiscordBot.getCommand() is deprecated! Please use EasyDiscordBot.commands.get(name) instead.')
|
||||
return this.commands.get(name);
|
||||
}
|
||||
async getGuild(id) {
|
||||
@@ -472,43 +473,6 @@ class EasyDiscordBot {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
async permissionsProxy(message, command) {
|
||||
try {
|
||||
if(command.permissions) {
|
||||
if(command.permissions.users && command.permissions.users instanceof Array) {
|
||||
if(command.permissions.users.findIndex(u => u == message.author.id) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(command.permissions.roles && command.permissions.roles instanceof Array) {
|
||||
let userRoles = message.member.roles.cache;
|
||||
userRoles = userRoles.array();
|
||||
for(let i = 0; i < userRoles.length; i++) {
|
||||
if(command.permissions.roles.findIndex(r => r == userRoles[i]) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(command.permissions.permissions && command.permissions.permissions instanceof Array) {
|
||||
const permissionList = command.permissions.permissions;
|
||||
const userPermissions = message.member.permissions.toArray();
|
||||
for(let i = 0; i < userPermissions.length; i++) {
|
||||
if(permissionList.findIndex(p => p.toUpperCase() == userPermissions[i]) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
static createEmbed(params) {
|
||||
try {
|
||||
const message = new MessageEmbed();
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
# EasyDiscordBot
|
||||
2.0.0-beta2
|
||||
2.0.0
|
||||
|
||||
[Changelog](https://github.com/GRZ4NA/EasyDiscordBot/blob/master/CHANGELOG.md#200-beta2)
|
||||
|
||||
This version may contain some bugs since it hasn't been fully tested yet. Documentation for the latest stable release can be found [here](https://github.com/GRZ4NA/EasyDiscordBot/blob/15047369944340b19aa7255236c77dca4acd2ada/README.md). If you find a bug, typo etc, report it to me using the Issues tab on GitHub or make your own pull request.
|
||||
[Changelog](https://github.com/GRZ4NA/EasyDiscordBot/blob/master/CHANGELOG.md#200)
|
||||
|
||||
*Documentation might change without patching the package on npmjs. Please read [README.md](https://github.com/GRZ4NA/EasyDiscordBot/blob/master/README.md) on the GitHub repo to get the latest documentation.*
|
||||
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "ezdiscordbot",
|
||||
"version": "2.0.0-beta2",
|
||||
"version": "2.0.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "ezdiscordbot",
|
||||
"version": "2.0.0-beta2",
|
||||
"version": "2.0.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"discord.js": "^12.5.1"
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ezdiscordbot",
|
||||
"description": "Create your own Discord bot in minutes.",
|
||||
"version": "2.0.0-beta2",
|
||||
"version": "2.0.0",
|
||||
"main": "EasyDiscordBot.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { Message } from 'discord.js';
|
||||
import { Command } from './commands.js';
|
||||
|
||||
async function checkCommandAccess(message, command) {
|
||||
try {
|
||||
if(!message instanceof Message || !command instanceof Command) {
|
||||
throw new TypeError('Cannot check user permissions. Incorrect arguments.');
|
||||
}
|
||||
if(command.permissions) {
|
||||
if(command.permissions.users && command.permissions.users instanceof Array) {
|
||||
if(command.permissions.users.findIndex(u => u == message.author.id) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(command.permissions.roles && command.permissions.roles instanceof Array) {
|
||||
let userRoles = message.member.roles.cache;
|
||||
userRoles = userRoles.array();
|
||||
for(let i = 0; i < userRoles.length; i++) {
|
||||
if(command.permissions.roles.findIndex(r => r == userRoles[i]) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(command.permissions.permissions && command.permissions.permissions instanceof Array) {
|
||||
const permissionList = command.permissions.permissions;
|
||||
const userPermissions = message.member.permissions.toArray();
|
||||
for(let i = 0; i < userPermissions.length; i++) {
|
||||
if(permissionList.findIndex(p => p.toUpperCase() == userPermissions[i]) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export { checkCommandAccess };
|
||||
Reference in new issue
Block a user