Nabrok / gw2-discord-bot

Discord bot for the Guild Wars 2 API.
GNU General Public License v3.0
33 stars 25 forks source link

Fix checking for multiple permissions when there's no API key #6

Closed Archomeda closed 8 years ago

Archomeda commented 8 years ago

With the latest changes to check for multiple permissions simultaneously, it bot crashes when someone with no API key executes !build:

                var hasPerm = permission.every(p => (token.permissions.indexOf(p) > -1));
                                                          ^
TypeError: Cannot read property 'permissions' of null

This PR fixes this issue and also adds an additional check in case db.checkKeyPermission is called with a zero-length permission array (should return true in that case). It also changes the waterfall sequence in builds a little bit, since this will notify the person without an API key with the proper message that the bot doesn't know him/her.