From b0ca631fb8e3a7f1bef8e9793fa4c69b53504c01 Mon Sep 17 00:00:00 2001 From: Trivernis Date: Fri, 18 Jan 2019 16:38:47 +0100 Subject: [PATCH] Fixed Role-Permission Bug - Fixed bug where role-permission did not work (except for the bot-owner commands) --- README.md | 23 +++++++++++++++++++++-- bot.js | 4 +--- lib/cmd.js | 8 ++++---- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 00b3970..899c26b 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,30 @@ discordbot A bot that does the discord thing. -`node bot.js --token= --ytapi= [--owner=] [--prefix=] [--game=]` +`node bot.js [--token=] [--ytapi=] [--owner=] [--prefix=] [--game=]` + +The arguments are optional because the token and youtube-api-key that the bot needs to run can also be defined in the config.json in the bot's directory: +```json5 +// config.json +{ + "prefix": "_", + "token": "DISCORD BOT TOKEN", + "ytapikey": "YOUTUBE API KEY", + "presence": "THE DEFAULT GAME IF NO presences.txt IS FOUND IN ./data/", + "presence_duration": 300000, + "owners": [ + "SPECIFY A LIST OF BOT-OWNERS" + ], + "music": { + "timeout": 300000 + } +} +``` Ideas --- - command replies saved in file (server specific file and global file) - reddit api - anilist api -- othercoolstuff api \ No newline at end of file +- othercoolstuff api +- SQLIITE Server-Data Storage \ No newline at end of file diff --git a/bot.js b/bot.js index e205e44..0a1464d 100644 --- a/bot.js +++ b/bot.js @@ -39,8 +39,6 @@ function main() { client.login(authToken).then(() => { logger.debug("Logged in"); }); - - } function registerCommands() { @@ -87,7 +85,7 @@ function registerCommands() { // returns the time the bot is running cmd.createGlobalCommand(prefix + 'uptime', () => { - return `Uptime: \`${client.uptime/1000} s\`` + return `Uptime: \`${client.uptime / 1000} s\`` }, [], 'Returns the uptime of the bot', 'owner'); // returns the numbe of guilds, the bot has joined diff --git a/lib/cmd.js b/lib/cmd.js index fee63c3..ad98d23 100644 --- a/lib/cmd.js +++ b/lib/cmd.js @@ -189,16 +189,16 @@ function parseGlobalCommand(msg) { /** * @param msg - * @param role {String} + * @param rolePerm {String} * @returns {boolean} */ -function checkPermission(msg, role) { - if (!role || ['all', 'any', 'everyone'].includes(role)) +function checkPermission(msg, rolePerm) { + if (!rolePerm || ['all', 'any', 'everyone'].includes(rolePerm)) return true; if (msg.author.tag === args.owner || config.owners.includes(msg.author.tag)) { return true; } else { - if (msg.member && role && msg.member.roles.some(role => role.name.toLowerCase() === role.toLowerCase())) + if (msg.member && rolePerm && msg.member.roles.some(role => role.name.toLowerCase() === rolePerm.toLowerCase())) return true } return false