2424 message_content ,
2525 message_reference ,
2626 message_reference_unknown ,
27+ message_reference_forwarded ,
2728 message_interaction ,
2829 img_attachment ,
2930 start_message ,
@@ -84,6 +85,14 @@ def __init__(
8485
8586 self .message_created_at , self .message_edited_at = self .set_time ()
8687 self .meta_data = meta_data
88+ self .forwarded = False
89+
90+ def get_message_snapshots (self ):
91+ if hasattr (self .message , "message_snapshots" ):
92+ return self .message .message_snapshots
93+ elif hasattr (self .message , "snapshots" ):
94+ return self .message .snapshots
95+ return []
8796
8897 async def construct_message (
8998 self ,
@@ -149,17 +158,28 @@ async def build_meta_data(self):
149158 ]
150159
151160 async def build_content (self ):
152- if not self .message .content :
161+ if not self .message .content and not self . get_message_snapshots () :
153162 self .message .content = ""
154163 return
155164
156165 if self .message_edited_at :
157166 self .message_edited_at = _set_edit_at (self .message_edited_at )
158167
159- self .message .content = html .escape (self .message .content )
168+ snapshots = self .get_message_snapshots ()
169+ if snapshots :
170+ combined = f"{ self .message .content } { ' ' .join (s .content for s in snapshots if hasattr (s , 'content' ))} "
171+ self .forwarded = True
172+ else :
173+ combined = self .message .content
174+
175+ combined = html .escape (combined or "" )
176+
177+ if self .forwarded :
178+ combined = f'<div class="quote">{ combined } </div>'
179+
160180 self .message .content = await fill_out (self .guild , message_content , [
161- ("MESSAGE_CONTENT" , self . message . content , PARSE_MODE_MARKDOWN ),
162- ("EDIT" , self .message_edited_at , PARSE_MODE_NONE )
181+ ("MESSAGE_CONTENT" , combined , PARSE_MODE_MARKDOWN ),
182+ ("EDIT" , self .message_edited_at , PARSE_MODE_NONE ),
163183 ])
164184
165185 async def build_reference (self ):
@@ -174,6 +194,9 @@ async def build_reference(self):
174194 message : discord .Message = await self .message .channel .fetch_message (self .message .reference .message_id )
175195 except (discord .NotFound , discord .HTTPException ) as e :
176196 self .message .reference = ""
197+ if self .forwarded :
198+ self .message .reference = message_reference_forwarded
199+ return
177200 if isinstance (e , discord .NotFound ):
178201 self .message .reference = message_reference_unknown
179202 return
@@ -251,13 +274,30 @@ async def build_interaction(self):
251274 ])
252275
253276 async def build_sticker (self ):
254- if not self .message .stickers or not hasattr (self .message .stickers [0 ], "url" ):
277+ sticker = None
278+ sticker_image_url = None
279+
280+ if self .message .stickers and hasattr (self .message .stickers [0 ], "url" ):
281+ sticker_image_url = self .message .stickers [0 ].url
282+ if not sticker_image_url :
283+ for snapshot in self .get_message_snapshots ():
284+ if hasattr (snapshot , "stickers" ) and snapshot .stickers and hasattr (snapshot .stickers [0 ], "url" ):
285+ sticker_image_url = snapshot .stickers [0 ].url
286+ self .message .reference = message_reference_forwarded
287+ break
288+
289+ if not sticker_image_url :
255290 return
256-
257- sticker_image_url = self .message .stickers [0 ].url
291+
258292
259293 if sticker_image_url .endswith (".json" ):
260- sticker = await self .message .stickers [0 ].fetch ()
294+ try :
295+ sticker = await self .message .stickers [0 ].fetch ()
296+ except :
297+ for snapshot in self .get_message_snapshots ():
298+ if hasattr (snapshot , "stickers" ) and snapshot .stickers and hasattr (snapshot .stickers [0 ], "url" ):
299+ sticker = await snapshot .stickers [0 ].fetch ()
300+ break
261301 sticker_image_url = (
262302 f"https://cdn.jsdelivr.net/gh/mahtoid/DiscordUtils@master/stickers/{ sticker .pack_id } /{ sticker .id } .gif"
263303 )
@@ -271,14 +311,34 @@ async def build_assets(self):
271311 for e in self .message .embeds :
272312 self .embeds += await Embed (e , self .guild ).flow ()
273313
314+ for snapshot in self .get_message_snapshots ():
315+ if hasattr (snapshot , "embeds" ):
316+ for se in snapshot .embeds :
317+ self .embeds += await Embed (se , self .guild ).flow ()
318+ self .message .reference = message_reference_forwarded
319+
274320 for a in self .message .attachments :
275321 if self .attachment_handler and isinstance (self .attachment_handler , AttachmentHandler ):
276322 a = await self .attachment_handler .process_asset (a )
277323 self .attachments += await Attachment (a , self .guild ).flow ()
324+
325+ for snapshot in self .get_message_snapshots ():
326+ if hasattr (snapshot , "attachments" ):
327+ for sa in snapshot .attachments :
328+ if self .attachment_handler :
329+ sa = await self .attachment_handler .process_asset (sa )
330+ self .attachments += await Attachment (sa ,self .guild ).flow ()
331+ self .message .reference = message_reference_forwarded
278332
279333 for c in self .message .components :
280334 self .components += await Component (c , self .guild ).flow ()
281335
336+ for snapshot in self .get_message_snapshots ():
337+ if hasattr (snapshot , "components" ):
338+ for ac in snapshot .components :
339+ self .components += await Component (ac ,self .guild ).flow ()
340+ self .message .reference = message_reference_forwarded
341+
282342 for r in self .message .reactions :
283343 self .reactions += await Reaction (r , self .guild ).flow ()
284344
@@ -497,4 +557,4 @@ async def gather_messages(
497557 previous_message = message
498558
499559 message_html += "</div>"
500- return message_html , meta_data
560+ return message_html , meta_data
0 commit comments