@@ -14,6 +14,24 @@ const instagramOptions = {
1414 } ,
1515} as const ;
1616
17+ const FALLBACK_EMBED_WAIT_MS = 5000 ;
18+
19+ async function replyWithFallback ( message : Message < true > , fallbackUrl : string ) {
20+ const reply = await message . reply ( {
21+ content : fallbackUrl ,
22+ allowedMentions : { repliedUser : false } ,
23+ } ) ;
24+
25+ await new Promise ( resolve => setTimeout ( resolve , FALLBACK_EMBED_WAIT_MS ) ) ;
26+ const fetched = await reply . fetch ( ) ;
27+
28+ if ( fetched . embeds . length > 0 ) {
29+ await message . suppressEmbeds ( true ) ;
30+ } else {
31+ await fetched . delete ( ) ;
32+ }
33+ }
34+
1735export default class InstagramLink implements SpecialCommand {
1836 name = "Instagram" ;
1937 description = "Embedded Instagram Links" ;
@@ -61,32 +79,35 @@ export default class InstagramLink implements SpecialCommand {
6179 await message . channel . sendTyping ( ) ;
6280
6381 for ( const postUri of urisToProcess ) {
64- const result = await instagramService . downloadInstagramContent ( context , postUri ) ;
65- if ( ! result . success ) {
66- const failureReaction = message . guild ?. emojis . cache . find ( e => e . name === "sadge" ) ;
67- if ( failureReaction ) {
68- await message . react ( failureReaction ) ;
82+ const fallbackUrl = postUri . replace (
83+ / ^ h t t p s ? : \/ \/ (?: w w w \. ) ? i n s t a g r a m \. c o m / ,
84+ "https://kkinstagram.com" ,
85+ ) ;
86+
87+ try {
88+ const result = await instagramService . downloadInstagramContent ( context , postUri ) ;
89+ if ( ! result . success ) {
90+ await replyWithFallback ( message , fallbackUrl ) ;
91+ return ;
6992 }
70- return ;
71- }
7293
73- const videoFiles = result . videoUrls . map ( ( url , idx ) => ( {
74- attachment : url ,
75- name : `Drecksvideo_${ idx } .mp4` ,
76- } ) ) ;
77- const imageFiles = result . imageUrls . map ( ( url , idx ) => ( {
78- attachment : url ,
79- name : `Drecksbild_${ idx } .jpg` ,
80- } ) ) ;
81- const files = [ ... imageFiles , ... videoFiles ] ;
82-
83- // We need to reply, since we cannot edit a message created by a different user (only remove embeds)
84- await message . reply ( {
85- files ,
86- allowedMentions : {
87- repliedUser : false ,
88- } ,
89- } ) ;
94+ const videoFiles = result . videoUrls . map ( ( url , idx ) => ( {
95+ attachment : url ,
96+ name : `Drecksvideo_${ idx } .mp4` ,
97+ } ) ) ;
98+ const imageFiles = result . imageUrls . map ( ( url , idx ) => ( {
99+ attachment : url ,
100+ name : `Drecksbild_${ idx } .jpg` ,
101+ } ) ) ;
102+
103+ // We need to reply, since we cannot edit a message created by a different user (only remove embeds)
104+ await message . reply ( {
105+ files : [ ... imageFiles , ... videoFiles ] ,
106+ allowedMentions : { repliedUser : false } ,
107+ } ) ;
108+ } catch {
109+ await replyWithFallback ( message , fallbackUrl ) ;
110+ }
90111 }
91112 await message . suppressEmbeds ( true ) ;
92113 }
0 commit comments