-
Notifications
You must be signed in to change notification settings - Fork 7
🔥 Feature: Add broadcast to bot and space #86
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
Open
grivera64
wants to merge
8
commits into
Code-Society-Lab:main
Choose a base branch
from
grivera64:feature/add-space-broadcast
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
77a3c76
🔥 Feature: Add space.broadcast() method
grivera64 169e6fd
🚨 Test: Add space.broadcast() tests
grivera64 233d9d1
🔥 Feature: Add depth option to space.broadcast()
grivera64 b461f75
🚨 Test(space): Consider depth in space related test cases
grivera64 c43a2bc
🔥 Feature: Add bot.broadcast() and tests
grivera64 f9bb663
Create pull request template (#87)
PenguinBoi12 1e13fe6
🎨 Style: Run black formatter
grivera64 9ce1c87
🎨 Style: Respect mypy linter
grivera64 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| ## Description | ||
| Brief description of what this PR does and why. | ||
|
|
||
| ### Type of Change | ||
| - [ ] Feature | ||
| - [ ] Refactor | ||
| - [ ] Bug fix | ||
| - [ ] Documentation | ||
| - [ ] Other: ___ | ||
|
|
||
| ### Pre-merge Checklist | ||
| - [ ] Run tests: `pytest` | ||
| - [ ] Run type check: `mypy` | ||
| - [ ] Run formatting: `black . |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,9 @@ | |
|
|
||
| from nio import AsyncClient, Event, MatrixRoom | ||
|
|
||
| from matrix.message import Message | ||
| from matrix.types import File | ||
|
|
||
| from .room import Room, make_room | ||
| from .space import Space | ||
| from .group import Group | ||
|
|
@@ -423,3 +426,44 @@ async def _build_context(self, matrix_room: Room, event: Event) -> Context: | |
| ctx.command = cmd | ||
|
|
||
| return ctx | ||
|
|
||
| # ROOMS | ||
|
|
||
| async def broadcast( | ||
| self, | ||
| rooms: list[Room], | ||
| content: str | None = None, | ||
| *, | ||
| raw: bool = False, | ||
| notice: bool = False, | ||
| file: File | None = None, | ||
| ) -> list[Message]: | ||
| """Broadcasts a message to the specified rooms. | ||
|
|
||
| Supports text messages (with optional markdown formatting) | ||
| and file uploads (including images, videos, and audio). | ||
| If a space is provided, it is silently skipped. | ||
|
|
||
| ## Example | ||
|
|
||
| ```python | ||
| # Broadcast a markdown-formatted text message | ||
| await bot.broadcast([room1, room2, ...], "Hello **world**!") | ||
|
|
||
| # Broadcast a notice message | ||
| await bot.broadcast([room1, room2, ...], "Event started", notice=True) | ||
|
|
||
| # Broadcast a file | ||
| file = File(path="mxc://...", filename="document.pdf", mimetype="application/pdf") | ||
| await bot.broadcast([room1, room2, ...], file=file) | ||
|
|
||
| # Broadcast an image | ||
| image = Image(path="mxc://...", filename="photo.jpg", mimetype="image/jpeg", width=800, height=600) | ||
| await bot.broadcast([room1, room2, ...], file=image) | ||
| ``` | ||
| """ | ||
| rooms = list(filter(lambda child: not isinstance(child, Space), rooms)) | ||
| async_send = [ | ||
| room.send(content, raw=raw, notice=notice, file=file) for room in rooms | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although |
||
| ] | ||
| return await asyncio.gather(*async_send) | ||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be
list[Room | Space]