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

Make updating read receipts optional #11

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/niobot/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class NioBot(nio.AsyncClient):
:param global_message_type: The message type to default to. Defaults to m.notice
:param ignore_old_events: Whether to simply discard events before the bot's login.
:param auto_join_rooms: Whether to automatically join rooms the bot is invited to.
:param auto_read_messages: Whether to automatically update read recipts
:param automatic_markdown_renderer: Whether to automatically render markdown in messages when sending/editing.
:param owner_id: The user ID of the bot owner. If set, only this user can run owner-only commands, etc.
:param max_message_cache: The maximum number of messages to cache. Defaults to 1000.
Expand All @@ -68,6 +69,7 @@ def __init__(
global_message_type: typing.Literal["m.text", "m.notice"] = "m.notice",
ignore_old_events: bool = True,
auto_join_rooms: bool = True,
auto_read_messages: bool = True,
automatic_markdown_renderer: bool = True,
max_message_cache: int = 1000,
ignore_self: bool = True,
Expand Down Expand Up @@ -146,10 +148,10 @@ def __init__(
self.global_message_type = global_message_type
self.ignore_old_events = ignore_old_events
self.auto_join_rooms = auto_join_rooms
self.auto_read_messages = auto_read_messages
self.automatic_markdown_renderer = automatic_markdown_renderer

self.add_event_callback(self.process_message, nio.RoomMessageText) # type: ignore
self.add_event_callback(self.update_read_receipts, nio.RoomMessage)
self.direct_rooms: dict[str, nio.MatrixRoom] = {}

self.message_cache: typing.Deque[typing.Tuple[nio.MatrixRoom, nio.RoomMessageText]] = deque(
Expand All @@ -162,6 +164,10 @@ def __init__(
self.log.info("Auto-joining rooms enabled.")
self.add_event_callback(self._auto_join_room_backlog_callback, nio.InviteMemberEvent) # type: ignore

if self.auto_read_messages:
self.log.info("Auto-updating read receipts enabled.")
self.add_event_callback(self.update_read_receipts, nio.RoomMessage)

if import_keys:
keys_path, keys_password = import_keys
if not keys_password:
Expand Down