The array with bans can have duplicates, making it extremely hard to unban someone.
The workaround is to spam the unban command.
The solution is to remove duplicates from this array when loading it from the JSON file by converting it to a set and then converting it back to an array. You can remove duplicates like this.
I would also recommend just keeping it as a Set in memory so you can use its has() method, which is more efficient.
Next, make your ban and unban commands check if a user is already banned or unbanned before trying to ban/unban.
And please also make the admin-action handler tell the user if they are not an admin before doing anything else and return right away.
admin-action doesn't say anything if you aren't admin and you try executing a command (on normal msgroom) so we won't add that. but, we will fix the ban duplicates
The array with bans can have duplicates, making it extremely hard to unban someone. The workaround is to spam the unban command. The solution is to remove duplicates from this array when loading it from the JSON file by converting it to a set and then converting it back to an array. You can remove duplicates like this. I would also recommend just keeping it as a
Set
in memory so you can use its has() method, which is more efficient. Next, make your ban and unban commands check if a user is already banned or unbanned before trying to ban/unban. And please also make theadmin-action
handler tell the user if they are not an admin before doing anything else and return right away.