Skip to content

Commit 3eb776c

Browse files
committed
feat: save message ref data to MongoDB
1 parent cddd001 commit 3eb776c

2 files changed

Lines changed: 38 additions & 7 deletions

File tree

core/clients.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,8 @@ async def append_log(
673673
self,
674674
message: Message,
675675
*,
676-
message_id: str = "",
677-
channel_id: str = "",
676+
message_id: str | int = "",
677+
channel_id: str | int = "",
678678
type_: str = "thread_message",
679679
) -> dict:
680680
channel_id = str(channel_id) or str(message.channel.id)
@@ -697,13 +697,40 @@ async def append_log(
697697
"id": a.id,
698698
"filename": a.filename,
699699
# In previous versions this was true for both videos and images
700-
"is_image": a.content_type.startswith("image/"),
700+
"is_image": a.content_type and a.content_type.startswith("image/"),
701701
"size": a.size,
702702
"url": a.url,
703703
"content_type": a.content_type,
704704
}
705705
for a in message.attachments
706706
],
707+
"messageReference": {
708+
"message_id": message.reference.message_id,
709+
"channel_id": message.reference.channel_id,
710+
"guild_id": message.reference.guild_id,
711+
"type": message.reference.type.name,
712+
} if message.reference else None,
713+
"messageSnapshots": [
714+
{
715+
"type": m.type.name,
716+
"content": m.content,
717+
"attachments": [
718+
{
719+
"id": a.id,
720+
"filename": a.filename,
721+
# In previous versions this was true for both videos and images
722+
"is_image": a.content_type and a.content_type.startswith("image/"),
723+
"size": a.size,
724+
"url": a.url,
725+
"content_type": a.content_type,
726+
}
727+
for a in m.attachments
728+
],
729+
"timestamp": m.created_at,
730+
"editedTimestamp": m.edited_at,
731+
}
732+
for m in message.message_snapshots
733+
],
707734
}
708735

709736
return await self.logs.find_one_and_update(

core/thread.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
truncate,
3535
)
3636

37+
if typing.TYPE_CHECKING:
38+
from bot import ModmailBot
39+
3740
logger = getLogger(__name__)
3841

3942

@@ -44,8 +47,8 @@ def __init__(
4447
self,
4548
manager: "ThreadManager",
4649
recipient: typing.Union[discord.Member, discord.User, int],
47-
channel: typing.Union[discord.DMChannel, discord.TextChannel] = None,
48-
other_recipients: typing.List[typing.Union[discord.Member, discord.User]] = None,
50+
channel: discord.DMChannel | discord.TextChannel | None = None,
51+
other_recipients: typing.List[typing.Union[discord.Member, discord.User]] | None = None,
4952
):
5053
self.manager = manager
5154
self.bot = manager.bot
@@ -1747,13 +1750,14 @@ async def reply(
17471750
guild.id if hasattr(guild, "id") else guild,
17481751
)
17491752
else:
1750-
return await message.channel.send(
1753+
await message.channel.send(
17511754
embed=discord.Embed(
17521755
color=self.bot.error_color,
17531756
description="Your message could not be delivered since "
17541757
"the recipient shares no servers with the bot.",
17551758
)
17561759
)
1760+
return
17571761

17581762
user_msg_tasks = []
17591763
tasks = []
@@ -2447,7 +2451,7 @@ class ThreadManager:
24472451
"""Class that handles storing, finding and creating Modmail threads."""
24482452

24492453
def __init__(self, bot):
2450-
self.bot = bot
2454+
self.bot: "ModmailBot" = bot
24512455
self.cache = {}
24522456
self.closing = set()
24532457

0 commit comments

Comments
 (0)