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,11 +3,30 @@ 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
---
- command replies saved in file (server specific file and global file)
- reddit api
- anilist api
- othercoolstuff api
- othercoolstuff api
- SQLIITE Server-Data Storage

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

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