@@ -69,6 +69,7 @@ def __init__(
69
69
# --- SNOOZE STATE ---
70
70
self .snoozed = False # True if thread is snoozed
71
71
self .snooze_data = None # Dict with channel/category/position/messages for restoration
72
+ self .log_key = None # Unique log key for this thread
72
73
73
74
def __repr__ (self ):
74
75
return f'Thread(recipient="{ self .recipient or self .id } ", channel={ self .channel .id } , other_recipients={ len (self ._other_recipients )} )'
@@ -342,11 +343,11 @@ async def setup(self, *, creator=None, category=None, initial_message=None):
342
343
self ._channel = channel
343
344
344
345
try :
345
- log_url , log_data = await asyncio . gather (
346
- self .bot .api .create_log_entry (recipient , channel , creator or recipient ),
347
- self . bot . api . get_user_logs ( recipient . id ),
348
- )
349
-
346
+ # create_log_entry now returns the log key (URL)
347
+ log_url = await self .bot .api .create_log_entry (recipient , channel , creator or recipient )
348
+ # Extract the log key from the URL
349
+ self . log_key = log_url . rstrip ( "/" ). split ( "/" )[ - 1 ]
350
+ log_data = await self . bot . api . get_user_logs ( recipient . id )
350
351
log_count = sum (1 for log in log_data if not log ["open" ])
351
352
except Exception :
352
353
logger .error ("An error occurred while posting logs to the database." , exc_info = True )
@@ -583,7 +584,25 @@ async def _close(self, closer, silent=False, delete_channel=True, message=None,
583
584
self .bot .config ["notification_squad" ].pop (str (self .id ), None )
584
585
585
586
# Logging
586
- if self .channel :
587
+ if self .log_key :
588
+ log_data = await self .bot .api .post_log (
589
+ log_key = self .log_key ,
590
+ data = {
591
+ "open" : False ,
592
+ "title" : match_title (self .channel .topic ) if self .channel else None ,
593
+ "closed_at" : str (discord .utils .utcnow ()),
594
+ "nsfw" : self .channel .nsfw if self .channel else None ,
595
+ "close_message" : message ,
596
+ "closer" : {
597
+ "id" : str (closer .id ),
598
+ "name" : closer .name ,
599
+ "discriminator" : closer .discriminator ,
600
+ "avatar_url" : closer .display_avatar .url ,
601
+ "mod" : True ,
602
+ },
603
+ },
604
+ )
605
+ elif self .channel :
587
606
log_data = await self .bot .api .post_log (
588
607
self .channel .id ,
589
608
{
@@ -608,9 +627,8 @@ async def _close(self, closer, silent=False, delete_channel=True, message=None,
608
627
prefix = self .bot .config ["log_url_prefix" ].strip ("/" )
609
628
if prefix == "NONE" :
610
629
prefix = ""
611
- log_url = (
612
- f"{ self .bot .config ['log_url' ].strip ('/' )} { '/' + prefix if prefix else '' } /{ log_data ['key' ]} "
613
- )
630
+ log_key = log_data .get ("key" ) or self .log_key
631
+ log_url = f"{ self .bot .config ['log_url' ].strip ('/' )} { '/' + prefix if prefix else '' } /{ log_key } "
614
632
615
633
if log_data ["title" ]:
616
634
sneak_peak = log_data ["title" ]
@@ -967,7 +985,9 @@ async def note(
967
985
968
986
# Log as 'internal' type for logviewer visibility
969
987
self .bot .loop .create_task (
970
- self .bot .api .append_log (message , message_id = msg .id , channel_id = self .channel .id , type_ = "internal" )
988
+ self .bot .api .append_log (
989
+ message , message_id = msg .id , log_key = self .log_key , channel_id = self .channel .id , type_ = "internal"
990
+ )
971
991
)
972
992
973
993
return msg
@@ -1041,6 +1061,7 @@ async def reply(
1041
1061
self .bot .api .append_log (
1042
1062
message ,
1043
1063
message_id = msg .id ,
1064
+ log_key = self .log_key ,
1044
1065
channel_id = self .channel .id ,
1045
1066
type_ = "anonymous" if anonymous else "thread_message" ,
1046
1067
)
@@ -1094,7 +1115,9 @@ async def send(
1094
1115
await self .wait_until_ready ()
1095
1116
1096
1117
if not from_mod and not note :
1097
- self .bot .loop .create_task (self .bot .api .append_log (message , channel_id = self .channel .id ))
1118
+ self .bot .loop .create_task (
1119
+ self .bot .api .append_log (message , log_key = self .log_key , channel_id = self .channel .id )
1120
+ )
1098
1121
1099
1122
destination = destination or self .channel
1100
1123
0 commit comments