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

fix: crash with replies to messages containing mentions #96

Merged
merged 1 commit into from
Feb 8, 2025
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
18 changes: 17 additions & 1 deletion signalbot/context.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# from .bot import Signalbot # TODO: figure out how to enable this for typing
from .message import Message
from typing import Any
from copy import deepcopy


class Context:
Expand Down Expand Up @@ -32,12 +33,15 @@ async def reply(
) = None, # [{ "author": "uuid" , "start": 0, "length": 1 }]
text_mode: str = None,
):
send_mentions = self._convert_receive_mentions_into_send_mentions(
self.message.mentions
)
return await self.bot.send(
self.message.recipient(),
text,
base64_attachments=base64_attachments,
quote_author=self.message.source,
quote_mentions=self.message.mentions,
quote_mentions=send_mentions,
quote_message=self.message.text,
quote_timestamp=self.message.timestamp,
mentions=mentions,
Expand All @@ -52,3 +56,15 @@ async def start_typing(self):

async def stop_typing(self):
await self.bot.stop_typing(self.message.recipient())

def _convert_receive_mentions_into_send_mentions(
self, mentions: list[dict[str, Any]] | None = None
):
if mentions is None:
return None

send_mentions = deepcopy(mentions)
for mention in send_mentions:
if "author" not in mention:
mention["author"] = mention["uuid"]
return send_mentions