@@ -7,11 +7,11 @@ const CODEBLOCK_REGEX = /```(?:ts|typescript)?\n([\s\S]+)```/;
7
7
export const PLAYGROUND_REGEX = / h t t p s ? : \/ \/ (?: w w w \. ) ? (?: t y p e s c r i p t l a n g | s t a g i n g - t y p e s c r i p t ) \. o r g \/ (?: p l a y | d e v \/ b u g - w o r k b e n c h ) (?: \/ i n d e x \. h t m l ) ? \/ ? ( \? ? (?: \w + = [ ^ \s # & ] + ) ? (?: \& \w + = [ ^ \s # & ] + ) * ) # c o d e \/ ( [ \w \- % + _ ] + = { 0 , 4 } ) / ;
8
8
9
9
export async function findCode ( message : Message , ignoreLinks = false ) {
10
- const codeInMessage = findCodeInMessage ( message , ignoreLinks ) ;
10
+ const codeInMessage = await findCodeInMessage ( message , ignoreLinks ) ;
11
11
if ( codeInMessage ) return codeInMessage ;
12
12
const referencedMessage = await getReferencedMessage ( message ) ;
13
13
if ( referencedMessage ) {
14
- const codeInReferencedMessage = findCodeInMessage (
14
+ const codeInReferencedMessage = await findCodeInMessage (
15
15
referencedMessage ,
16
16
ignoreLinks ,
17
17
) ;
@@ -20,7 +20,7 @@ export async function findCode(message: Message, ignoreLinks = false) {
20
20
const msgs = await message . channel . messages . fetch ( { limit : 10 } ) ;
21
21
22
22
for ( const msg of msgs . values ( ) ) {
23
- const code = findCodeInMessage ( msg , ignoreLinks ) ;
23
+ const code = await findCodeInMessage ( msg , ignoreLinks ) ;
24
24
if ( code ) return code ;
25
25
}
26
26
}
@@ -29,10 +29,11 @@ export async function findCode(message: Message, ignoreLinks = false) {
29
29
// 1: Normal code block annotated with ts from a non-bot
30
30
// 2: Link to TS playground. This can be either from a bot or a normal user
31
31
// since we shorten playground links on their own and delete the message.
32
- function findCodeInMessage (
33
- { author, content, embeds } : Message ,
34
- ignoreLinks = false ,
35
- ) {
32
+ async function findCodeInMessage ( msg : Message , ignoreLinks = false ) {
33
+ if ( msg . type === 'THREAD_STARTER_MESSAGE' ) {
34
+ msg = await msg . fetchReference ( ) ;
35
+ }
36
+ const { author, content, embeds } = msg ;
36
37
if ( ! author . bot ) {
37
38
const match = content . match ( CODEBLOCK_REGEX ) ;
38
39
if ( match && match [ 1 ] . length ) {
0 commit comments