Skip to content

Commit 1a5a2bd

Browse files
committed
fix: show who send which internal message.
1 parent 97d0e8d commit 1a5a2bd

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ LOG_URL=https://logviewername.herokuapp.com/
33
GUILD_ID=1234567890
44
OWNERS=Owner1ID,Owner2ID,Owner3ID
55
CONNECTION_URI=mongodb+srv://mongodburi
6+
DISABLE_AUTOUPDATES=true

core/thread.py

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,16 @@ async def restore_from_snooze(self):
259259
# Only send if there is content, embeds, or attachments
260260
if not content and not embeds and not attachments:
261261
continue # Skip empty messages
262-
# Format internal/system/mod-only messages as 'username: textcontent'
263-
if msg_type in ("internal", "note", "system", "mod_only"):
262+
author_is_mod = msg["author_id"] not in [r.id for r in self.recipients]
263+
if author_is_mod:
264264
username = msg.get("author_name") or (getattr(author, "name", None)) or "Unknown"
265-
formatted = f"{username}: {content}" if content else username
266-
await channel.send(formatted)
265+
user_id = msg.get("author_id")
266+
if embeds:
267+
embeds[0].set_author(name=f"{username} ({user_id})", icon_url=author.display_avatar.url if author and hasattr(author, "display_avatar") else None)
268+
await channel.send(embeds=embeds)
269+
else:
270+
formatted = f"**{username} ({user_id})**: {content}" if content else f"**{username} ({user_id})**"
271+
await channel.send(formatted)
267272
else:
268273
await channel.send(content=content or None, embeds=embeds or None)
269274
self.snoozed = False
@@ -596,6 +601,8 @@ async def close(
596601
await self._close(closer, silent, delete_channel, message)
597602

598603
async def _close(self, closer, silent=False, delete_channel=True, message=None, scheduled=False):
604+
if self.channel:
605+
self.manager.closing.add(self.channel.id)
599606
try:
600607
self.manager.cache.pop(self.id)
601608
except KeyError as e:
@@ -722,10 +729,15 @@ async def _close(self, closer, silent=False, delete_channel=True, message=None,
722729
if user is not None:
723730
tasks.append(user.send(embed=embed))
724731

725-
if delete_channel:
732+
if delete_channel and self.channel:
726733
tasks.append(self.channel.delete())
727734

728-
await asyncio.gather(*tasks)
735+
try:
736+
await asyncio.gather(*tasks)
737+
finally:
738+
if self.channel:
739+
self.manager.closing.discard(self.channel.id)
740+
729741
self.bot.dispatch("thread_close", self, closer, silent, delete_channel, message, scheduled)
730742

731743
async def cancel_closure(self, auto_close: bool = False, all: bool = False) -> None:
@@ -801,10 +813,7 @@ async def find_linked_messages(
801813
):
802814
raise ValueError("Thread message not found.")
803815

804-
if message1.embeds[0].color.value == self.bot.main_color and (
805-
message1.embeds[0].author.name.startswith("Note")
806-
or message1.embeds[0].author.name.startswith("Persistent Note")
807-
):
816+
if message1.embeds[0].footer and "Internal Message" in message1.embeds[0].footer.text:
808817
if not note:
809818
raise ValueError("Thread message not found.")
810819
return message1, None
@@ -867,7 +876,7 @@ async def edit_message(self, message_id: typing.Optional[int], message: str) ->
867876
embed1.description = message
868877

869878
tasks = [self.bot.api.edit_message(message1.id, message), message1.edit(embed=embed1)]
870-
if message1.embeds[0].author.name.startswith("Persistent Note"):
879+
if message1.embeds[0].footer and "Persistent Internal Message" in message1.embeds[0].footer.text:
871880
tasks += [self.bot.api.edit_note(message1.id, message)]
872881
else:
873882
for m2 in message2:
@@ -894,7 +903,7 @@ async def delete_message(
894903
if m2 is not None:
895904
tasks += [m2.delete()]
896905

897-
if message1.embeds[0].author.name.startswith("Persistent Note"):
906+
if message1.embeds[0].footer and "Persistent Internal Message" in message1.embeds[0].footer.text:
898907
tasks += [self.bot.api.delete_note(message1.id)]
899908

900909
if tasks:
@@ -992,9 +1001,9 @@ async def note(
9921001
thread_creation=thread_creation,
9931002
)
9941003

995-
# Log as 'internal' type for logviewer visibility
1004+
# Log as 'system' type for logviewer visibility
9961005
self.bot.loop.create_task(
997-
self.bot.api.append_log(message, message_id=msg.id, channel_id=self.channel.id, type_="internal")
1006+
self.bot.api.append_log(message, message_id=msg.id, channel_id=self.channel.id, type_="system")
9981007
)
9991008

10001009
return msg
@@ -1194,10 +1203,10 @@ async def send(
11941203
url=f"https://discordapp.com/users/{author.id}#{message.id}",
11951204
)
11961205
else:
1197-
# Special note messages
1206+
# Notes are just replies with a different footer and color
11981207
embed.set_author(
1199-
name=f"{'Persistent' if persistent_note else ''} Note ({author.name})",
1200-
icon_url=system_avatar_url,
1208+
name=str(author),
1209+
icon_url=avatar_url,
12011210
url=f"https://discordapp.com/users/{author.id}#{message.id}",
12021211
)
12031212

@@ -1325,8 +1334,10 @@ def lottie_to_png(data):
13251334

13261335
if from_mod:
13271336
embed.colour = self.bot.mod_color
1337+
if note:
1338+
embed.set_footer(text=f"{'Persistent' if persistent_note else ''} Internal Message")
13281339
# Anonymous reply sent in thread channel
1329-
if anonymous and isinstance(destination, discord.TextChannel):
1340+
elif anonymous and isinstance(destination, discord.TextChannel):
13301341
embed.set_footer(text="Anonymous Reply")
13311342
# Normal messages
13321343
elif not anonymous:
@@ -1336,8 +1347,6 @@ def lottie_to_png(data):
13361347
embed.set_footer(text=mod_tag) # Normal messages
13371348
else:
13381349
embed.set_footer(text=self.bot.config["anon_tag"])
1339-
elif note:
1340-
embed.colour = self.bot.main_color
13411350
else:
13421351
embed.set_footer(text=f"Message ID: {message.id}")
13431352
embed.colour = self.bot.recipient_color
@@ -1489,6 +1498,7 @@ class ThreadManager:
14891498
def __init__(self, bot):
14901499
self.bot = bot
14911500
self.cache = {}
1501+
self.closing = set()
14921502

14931503
async def populate_cache(self) -> None:
14941504
for channel in self.bot.modmail_guild.text_channels:
@@ -1512,6 +1522,8 @@ async def find(
15121522
) -> typing.Optional[Thread]:
15131523
"""Finds a thread from cache or from discord channel topics."""
15141524
if recipient is None and channel is not None and isinstance(channel, discord.TextChannel):
1525+
if channel.id in self.closing:
1526+
return None
15151527
thread = await self._find_from_channel(channel)
15161528
if thread is None:
15171529
user_id, thread = next(

0 commit comments

Comments
 (0)