Add pre-defined check has_power_level - #119
Open
AnayGarodia wants to merge 6 commits into
Open
Conversation
* feat: add is_admin and is_moderator checks Adds two check decorators alongside the existing cooldown() in matrix/checks.py, following the same pattern: an inner async predicate that inspects ctx.room.power_levels (via nio's MatrixRoom.power_levels / PowerLevels.get_user_level) and a wrapper that registers it with Command.check() and returns the command. - is_admin(): requires power level >= 100 - is_moderator(): requires power level >= 50 Both feed into the existing Command._invoke -> CheckError flow, no new exception types needed. Closes Code-Society-Lab#103, Code-Society-Lab#104 Co-Authored-By: Claude <noreply@anthropic.com> * test: cover users_default fallback for senders absent from power_levels Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * refactor: extract admin/moderator power levels into constants Addresses the review nit on Code-Society-Lab#111: is_admin() and is_moderator() had their thresholds hardcoded (100/50). They are now module-level constants, ADMIN_POWER_LEVEL and MODERATOR_POWER_LEVEL, referenced by the checks, their docstrings and the boundary tests. An extra test pins the values to the m.room.power_levels defaults so they cannot drift silently. No behaviour change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Simon Roy <49426163+PenguinBoi12@users.noreply.github.com>
* feat(message): add unreact method Signed-off-by: anay <agarodia98@gmail.com> * refactor(message): share reaction iteration Signed-off-by: anay <agarodia98@gmail.com> --------- Signed-off-by: anay <agarodia98@gmail.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019cFhMyHwVAQ9GieYbi3aUb
Contributor
|
main's history has to be rewritten to adjust a commit's message, no file content changed but your PR's diff may look off until you either click "Update branch" or rebase locally: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds the pre-defined check
has_power_level(level)tomatrix/checks.py, following the same decorator pattern asis_admin/is_moderator. The check compares the sender's power level in the room against the givenleveland passes when the sender's level is greater than or equal to it, so commands decorated with it raiseCheckErrorotherwise. Includes unit tests mirroring the existing check tests.Closes #105
Type of Change
Pre-merge Checklist
pytest(382 passed)mypyblack .