1
1
import { type Message , ThreadAutoArchiveDuration } from 'discord.js' ;
2
2
import ogs from 'open-graph-scraper' ;
3
+ import { getVideoSummary } from './summarize-cool-videos' ;
3
4
4
5
const getThreadNameFromOpenGraph = async ( url : string ) : Promise < string | null > => {
5
6
try {
@@ -24,6 +25,8 @@ const getThreadNameFromOpenGraph = async (url: string): Promise<string | null> =
24
25
return null ;
25
26
} ;
26
27
28
+ const youtubeUrlRegex = new RegExp ( '^(https?)?(://)?(www.)?(m.)?((youtube.com)|(youtu.be))' ) ;
29
+
27
30
export const coolLinksManagement = async ( message : Message ) => {
28
31
const urlRegex = / ( ( ( h t t p s ? : \/ \/ ) | ( w w w \. ) ) [ ^ \s ] + ) / g;
29
32
const detectedURLs = message . content . match ( urlRegex ) ;
@@ -36,9 +39,18 @@ export const coolLinksManagement = async (message: Message) => {
36
39
await message . react ( '✅' ) ;
37
40
await message . react ( '❌' ) ;
38
41
39
- const threadName = await getThreadNameFromOpenGraph ( detectedURLs [ 0 ] ) ;
40
- await message . startThread ( {
42
+ const url = detectedURLs [ 0 ] ;
43
+ const threadName = await getThreadNameFromOpenGraph ( url ) ;
44
+ const thread = await message . startThread ( {
41
45
name : threadName ?? message . content ,
42
46
autoArchiveDuration : ThreadAutoArchiveDuration . ThreeDays ,
43
47
} ) ;
48
+ if ( thread . joinable ) await thread . join ( ) ;
49
+
50
+ if ( youtubeUrlRegex . test ( url ) ) {
51
+ const summary = await getVideoSummary ( url ) ;
52
+ if ( ! summary ) return ;
53
+
54
+ await thread . send ( summary ) ;
55
+ }
44
56
} ;
0 commit comments