Skip to content

Add pre-defined check can_invite - #120

Open
AnayGarodia wants to merge 6 commits into
Code-Society-Lab:mainfrom
AnayGarodia:feat/can-invite-check
Open

Add pre-defined check can_invite#120
AnayGarodia wants to merge 6 commits into
Code-Society-Lab:mainfrom
AnayGarodia:feat/can-invite-check

Conversation

@AnayGarodia

Copy link
Copy Markdown
Contributor

Description

Adds the pre-defined check can_invite to matrix/checks.py, following the same decorator pattern as is_admin/is_moderator. The check uses PowerLevels.can_user_invite to compare the sender's power level against the room's invite power level, so commands decorated with it raise CheckError when the sender is not allowed to invite. Includes unit tests mirroring the existing check tests, including one against a custom room invite level.

Closes #106

Type of Change

  • Feature
  • Refactor
  • Bug fix
  • Documentation
  • Other: ___

Pre-merge Checklist

  • Run tests: pytest (384 passed)
  • Run type check: mypy
  • Run formatting: black .

akagifreeez and others added 6 commits July 22, 2026 10:39
* 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
Copilot AI review requested due to automatic review settings July 29, 2026 19:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@PenguinBoi12

Copy link
Copy Markdown
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:

git fetch origin
git rebase origin/main
git push --force-with-lease

@PenguinBoi12

Copy link
Copy Markdown
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:

git fetch origin
git rebase origin/main
git push --force-with-lease

@AnayGarodia can you please do this (for all your PR) otherwise I can't review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check: can_invite

4 participants