feat(transport): add sender_id and raw to MessageRef for plugins (#112)

Co-authored-by: Lewis Freiberg <lewis@freiberg.dev>
This commit is contained in:
Lewis Freiberg
2026-01-13 00:58:18 +01:00
committed by GitHub
parent abd0aa2bb4
commit 6ce08ee602
3 changed files with 45 additions and 1 deletions
+5 -1
View File
@@ -1537,7 +1537,11 @@ async def _dispatch_command(
stateful_mode=stateful_mode, stateful_mode=stateful_mode,
) )
message_ref = MessageRef( message_ref = MessageRef(
channel_id=chat_id, message_id=user_msg_id, thread_id=msg.thread_id channel_id=chat_id,
message_id=user_msg_id,
thread_id=msg.thread_id,
sender_id=msg.sender_id,
raw=msg.raw,
) )
try: try:
backend = get_command(command_id, allowlist=allowlist, required=False) backend = get_command(command_id, allowlist=allowlist, required=False)
+1
View File
@@ -14,6 +14,7 @@ class MessageRef:
message_id: MessageId message_id: MessageId
raw: Any | None = field(default=None, compare=False, hash=False) raw: Any | None = field(default=None, compare=False, hash=False)
thread_id: ThreadId | None = field(default=None, compare=False, hash=False) thread_id: ThreadId | None = field(default=None, compare=False, hash=False)
sender_id: int | None = field(default=None, compare=False, hash=False)
@dataclass(frozen=True, slots=True) @dataclass(frozen=True, slots=True)
+39
View File
@@ -0,0 +1,39 @@
"""Tests for the transport module."""
from takopi.transport import MessageRef
def test_message_ref_sender_id_field() -> None:
"""Test that MessageRef has sender_id field and it works correctly."""
# Without sender_id
ref1 = MessageRef(channel_id=123, message_id=456)
assert ref1.sender_id is None
# With sender_id
ref2 = MessageRef(channel_id=123, message_id=456, sender_id=789)
assert ref2.sender_id == 789
# sender_id should not affect equality (compare=False)
ref3 = MessageRef(channel_id=123, message_id=456, sender_id=999)
assert ref2 == ref3 # Same channel_id and message_id
# sender_id should not affect hash (hash=False)
assert hash(ref2) == hash(ref3)
def test_message_ref_all_fields() -> None:
"""Test MessageRef with all fields populated."""
raw_data = {"from": {"id": 789, "first_name": "Test"}}
ref = MessageRef(
channel_id=123,
message_id=456,
raw=raw_data,
thread_id=100,
sender_id=789,
)
assert ref.channel_id == 123
assert ref.message_id == 456
assert ref.raw == raw_data
assert ref.thread_id == 100
assert ref.sender_id == 789