@@ -390,6 +390,94 @@ class ControlMobileViewButton extends Button {
390390 if ( ! interaction . message ) return ;
391391
392392 const originalMessageEmbed = interaction . message . embeds [ 0 ] ;
393+ const bookmarkIsEmbed = interaction . message . embeds . length > 1 ;
394+ if ( bookmarkIsEmbed ) {
395+ const extractAllContentFromEmbeds = interaction . message . embeds
396+ . map ( ( embed , _index ) => {
397+ let content = "" ;
398+
399+ if ( embed . title ) {
400+ content += `**${ embed . title } **\n` ;
401+ }
402+ if ( embed . description ) {
403+ content += `${ embed . description } \n` ;
404+ }
405+ if ( embed . fields && embed . fields . length > 0 ) {
406+ content += "\n" ;
407+ embed . fields . forEach ( ( field ) => {
408+ content += `**${ field . name } **\n${ field . value } \n\n` ;
409+ } ) ;
410+ }
411+ if ( embed . footer ) {
412+ content += `*${ embed . footer . text } *\n` ;
413+ }
414+
415+ return content . trim ( ) ;
416+ } )
417+ . filter ( ( content ) => content . length > 0 )
418+ . join ( "\n\n---\n\n" ) ;
419+
420+ const maxLength = 2000 ;
421+ const content =
422+ extractAllContentFromEmbeds || "No content available for mobile view." ;
423+
424+ if ( content . length <= maxLength ) {
425+ return interaction
426+ . reply ( {
427+ content,
428+ flags : MessageFlags . Ephemeral ,
429+ } )
430+ . catch ( ( e ) => {
431+ console . error ( e ) ;
432+ return interaction . reply ( {
433+ content : "Failed to extract content for mobile view." ,
434+ flags : MessageFlags . Ephemeral ,
435+ } ) ;
436+ } ) ;
437+ }
438+
439+ const chunks : string [ ] = [ ] ;
440+ let currentChunk = "" ;
441+ const lines = content . split ( "\n" ) ;
442+
443+ for ( const line of lines ) {
444+ if ( currentChunk . length + line . length + 1 > maxLength ) {
445+ if ( currentChunk . trim ( ) ) {
446+ chunks . push ( currentChunk . trim ( ) ) ;
447+ }
448+ currentChunk = line ;
449+ } else {
450+ currentChunk += ( currentChunk ? "\n" : "" ) + line ;
451+ }
452+ }
453+
454+ if ( currentChunk . trim ( ) ) {
455+ chunks . push ( currentChunk . trim ( ) ) ;
456+ }
457+
458+ return interaction
459+ . reply ( {
460+ content : chunks [ 0 ] ,
461+ flags : MessageFlags . Ephemeral ,
462+ } )
463+ . then ( async ( ) => {
464+ for ( let i = 1 ; i < chunks . length ; i ++ ) {
465+ await interaction
466+ . followUp ( {
467+ content : chunks [ i ] ,
468+ flags : MessageFlags . Ephemeral ,
469+ } )
470+ . catch ( console . error ) ;
471+ }
472+ } )
473+ . catch ( ( e ) => {
474+ console . error ( e ) ;
475+ return interaction . reply ( {
476+ content : "Failed to extract content for mobile view." ,
477+ flags : MessageFlags . Ephemeral ,
478+ } ) ;
479+ } ) ;
480+ }
393481 if ( ! originalMessageEmbed ) return ;
394482
395483 return interaction
0 commit comments