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

Added simple base for a has_any_role decorator check. #81

Closed

Conversation

patchwork-systems
Copy link
Contributor

I just wanted to submit this for an initial review. I'd be happy to make any changes that might be necessary!

Copy link
Contributor

@nxtlo nxtlo left a comment

Choose a reason for hiding this comment

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

Ain't this suppose to check if the member was human? or None?

tanjun/checks.py Outdated Show resolved Hide resolved
tanjun/checks.py Outdated Show resolved Hide resolved
tanjun/checks.py Outdated Show resolved Hide resolved
tanjun/checks.py Outdated Show resolved Hide resolved
tanjun/checks.py Show resolved Hide resolved
tanjun/checks.py Outdated Show resolved Hide resolved
tanjun/checks.py Outdated
) -> bool:

if not ctx.member:
return _handle_result(False, "You must be a member to use this!", True)
Copy link
Owner

Choose a reason for hiding this comment

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

This isn't really a good way to handle this, these fields should also be decided based on user input and while halt_execution can just be re-used here you'd likely have to distinguish between the two error messages somehow (possibly by taking them as separate keyword-arguments).

tanjun/checks.py Outdated Show resolved Hide resolved
tanjun/checks.py Outdated Show resolved Hide resolved
tanjun/checks.py Outdated
if not ctx.member:
return _handle_result(False, "You must be a member to use this!", True)

member_roles = ctx.member.get_roles()
Copy link
Owner

Choose a reason for hiding this comment

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

It would probably make sense to fallback to fetching the roles from rest if necessary to make this check more compatible with a cacheless bot (e.g. interaction server).

Plus if we process the roles while initialising the class for this check we could add a hot path for when no role names are provided which avoids getting the role objects all together and rather just checks against ctx.member.role_ids

@FasterSpeeding
Copy link
Owner

FasterSpeeding commented Sep 3, 2021

Just got those couple of comments I added which need addressing (sorry if it's a bit much, what you've written so far is good, just need some changes to bring it inline with the other checks) + there's a couple of errors popping up in the CI which need to be solves (for reference you can also run the CI's checks locally pretty easily using nox (similar to tox and more info can be found on it here https://nox.thea.codes/en/stable/, the tasks it has can be found at https://github.com/FasterSpeeding/Tanjun/blob/master/noxfile.py)

@patchwork-systems
Copy link
Contributor Author

We will work on add these changes in today!

- with_any_roles_check internal logic separated into classes for compatibility
- Removed 3.10 only features
@patchwork-systems
Copy link
Contributor Author

We made some of the changes requested tonight!

The check was transformed into a class to use with Components and everything fits the proper style and nox linting.

We started reading up on how to fix the roles issue with the rest client tonight. We'll try to get that fix in tomorrow.

We can also apply that fix for the if ctx.member: issue too. We are just not sure what the best way to not allow that leak but still ensure ctx.member.roles or ctx.member.roles_id would still be accessible.

@FasterSpeeding
Copy link
Owner

We can also apply that fix for the if ctx.member: issue too. We are just not sure what the best way to not allow that leak but still ensure ctx.member.roles or ctx.member.roles_id would still be accessible.

How you're handling the member check is fine for the most part right now, just need to ensure that it's error handling is configurable (so use self._halt_execution and add a way to set the custom message for it)

@FasterSpeeding
Copy link
Owner

Might want to rebase this onto master when you next work on it, I've updated the github actions which apply to prs quite a bit since

@patchwork-systems
Copy link
Contributor Author

Instead of trying to rebase and update all of this, we elected to just make a new PR instead: #145

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.

3 participants