MSC Bot Devlog – Refactoring permissions
The way MSC Bot handles permissions before today was by having an if
statement in every command that required a specific role:
Since every command has roughly the same structure, there was a lot of duplication of these if statements. Almost every command had one of them.
To get rid of this duplication, and to simplify the creation of new commands, I added an option field to the exported object (each command exports an object with various information about the command) called requireOneOfRoles
. This field should be an array of role names, exactly the same array as in the image above.
Now in the main file where I loop over all the commands to check which command is being called, I can now also check if the user has the required permission!
MSC Bot functions exactly the same way as it did before all these changes, but it is now easier for me to add more commands, because I don't have to do the permission logic every time!
Something that did change the way MSC Bot functions though, was the help
command. Previously the help
command just used to show all the commands, didn't matter if you actually had the permissions to execute the commands or not.
Well now, with the refactoring of the permissions, I was able to filter out commands based on the permissions!