Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to allow roles to remove sounds from config.json #85

Merged
merged 14 commits into from
Jul 12, 2020
Merged

Conversation

ibito
Copy link
Contributor

@ibito ibito commented Jun 4, 2020

Hope this is up to your standards :(

Copy link
Owner

@markokajzer markokajzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello boss! Thank you so much for using the bot, and now even contributing AGAIN.

I saw you initially added to and edited the Spanish translation, so feel free to open up a separate PR for that. Thank you so much for updating that! 🇪🇸

There a couple of issues here, especially the fact that other commands need the same changes, as we have a number of commands that are restricted. So we definitely need to make some more changes.

config/config.example.json Outdated Show resolved Hide resolved
Comment on lines 24 to 33

let allowedToRemove = false;

if (this.config.rolesAllowedToRemoveSounds !== undefined) {
allowedToRemove = message.member!.roles.cache.some(
r => this.config.rolesAllowedToRemoveSounds.indexOf(r.name) >= 0
);
}

if (!message.member.hasPermission(Permissions.FLAGS.ADMINISTRATOR!) && !allowedToRemove) return;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is multiple things here.

The way you implemented it, the user would have to be in the rolesAllowedToRemoveSounds AND they would still need to have the administrator flag. That does not change the functionality all too much, and maybe that is a bit too overkill. We are allowing users to set the roles explicitly, so I don't think we need the extra check anymore. What do you think?

You can use Array.includes instead of .indexOf.

I don't think you need the bang ! after message.member, as the first line of the method checks for it already. With the ! you tell TypeScript to not care about nullable values any more, but we already made the explicit check for it.

You need to add rolesAllowedToRemoveSounds to both Config (see other examples), ConfigInterface and DefaultConfig. After that it cannot be undefined anymore, so the check becomes obsolete.

This is one of the commands that need elevated rights. The same check for the ADMINISTRATOR flag, seems to appear 6 times overall in the code base, so I expect us to make the same change across the whole code base. Now, we also don't want to repeat ourselves all too much, right? So if the code needed to check for the rights is a couple lines (like here), we can put it in a different file and call that piece of code instead (e.g. hasElevatedRights(member), as well as re-use it across the other 5 occurrences.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I applied all of your comments, and sorry, I'm terribly new and bad to typescript 🤦‍♂️

Copy link
Owner

@markokajzer markokajzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more issues here and there to bring this to the ultimate solution. 👍

src/bot/commands/AvatarCommand.ts Outdated Show resolved Hide resolved
src/bot/commands/helpers/checkElevatedRights.ts Outdated Show resolved Hide resolved
src/bot/commands/helpers/checkElevatedRights.ts Outdated Show resolved Hide resolved
config/config.example.json Show resolved Hide resolved
src/bot/commands/helpers/checkElevatedRights.ts Outdated Show resolved Hide resolved
src/bot/commands/helpers/checkElevatedRights.ts Outdated Show resolved Hide resolved
Copy link
Owner

@markokajzer markokajzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible remove the remaining unnessary fields and imports, otherwise I can take care of it!

Again, thank you for your contribution, and feel free to open another PR with the Spanish translation changes :) 🎉

Copy link
Owner

@markokajzer markokajzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said, this is looking good! I'll merge in the next days. Thank you for your time and effort!

@markokajzer markokajzer merged commit 0b02319 into markokajzer:master Jul 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants