Fixed Role-Permission Bug

- Fixed bug where role-permission did not work (except for the bot-owner commands)
pull/13/head
Trivernis 6 years ago
parent c29c578f92
commit b0ca631fb8

@ -3,7 +3,25 @@ discordbot
A bot that does the discord thing.
`node bot.js --token=<DiscordBotToken> --ytapi=<GoogleApiKey> [--owner=<DiscordTag>] [--prefix=<Char>] [--game=<String>]`
`node bot.js [--token=<DiscordBotToken>] [--ytapi=<GoogleApiKey>] [--owner=<DiscordTag>] [--prefix=<Char>] [--game=<String>]`
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
---
@ -11,3 +29,4 @@ Ideas
- reddit api
- anilist api
- othercoolstuff api
- SQLIITE Server-Data Storage

@ -39,8 +39,6 @@ function main() {
client.login(authToken).then(() => {
logger.debug("Logged in");
});
}
function registerCommands() {

@ -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

Loading…
Cancel
Save