@@ -3,6 +3,7 @@ import type { Message } from "discord.js";
33import type { SpecialCommand } from "#/commands/command.ts" ;
44import type { BotContext } from "#/context.ts" ;
55import * as instagramService from "#/service/instagram.ts" ;
6+ import { replyWithFallbackEmbed } from "#/utils/embedUtils.ts" ;
67
78const instagramOptions = {
89 uriPattern :
@@ -14,24 +15,6 @@ const instagramOptions = {
1415 } ,
1516} as const ;
1617
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-
3518export default class InstagramLink implements SpecialCommand {
3619 name = "Instagram" ;
3720 description = "Embedded Instagram Links" ;
@@ -87,7 +70,7 @@ export default class InstagramLink implements SpecialCommand {
8770 try {
8871 const result = await instagramService . downloadInstagramContent ( context , postUri ) ;
8972 if ( ! result . success ) {
90- await replyWithFallback ( message , fallbackUrl ) ;
73+ await replyWithFallbackEmbed ( message , fallbackUrl ) ;
9174 return ;
9275 }
9376
@@ -106,7 +89,7 @@ export default class InstagramLink implements SpecialCommand {
10689 allowedMentions : { repliedUser : false } ,
10790 } ) ;
10891 } catch {
109- await replyWithFallback ( message , fallbackUrl ) ;
92+ await replyWithFallbackEmbed ( message , fallbackUrl ) ;
11093 }
11194 }
11295 await message . suppressEmbeds ( true ) ;
0 commit comments