Skip to content

Commit 9f94a8e

Browse files
committed
resolve thread start message content in \!ts and co
1 parent 714f404 commit 9f94a8e

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/util/codeBlocks.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const CODEBLOCK_REGEX = /```(?:ts|typescript)?\n([\s\S]+)```/;
77
export const PLAYGROUND_REGEX = /https?:\/\/(?:www\.)?(?:typescriptlang|staging-typescript)\.org\/(?:play|dev\/bug-workbench)(?:\/index\.html)?\/?(\??(?:\w+=[^\s#&]+)?(?:\&\w+=[^\s#&]+)*)#code\/([\w\-%+_]+={0,4})/;
88

99
export async function findCode(message: Message, ignoreLinks = false) {
10-
const codeInMessage = findCodeInMessage(message, ignoreLinks);
10+
const codeInMessage = await findCodeInMessage(message, ignoreLinks);
1111
if (codeInMessage) return codeInMessage;
1212
const referencedMessage = await getReferencedMessage(message);
1313
if (referencedMessage) {
14-
const codeInReferencedMessage = findCodeInMessage(
14+
const codeInReferencedMessage = await findCodeInMessage(
1515
referencedMessage,
1616
ignoreLinks,
1717
);
@@ -20,7 +20,7 @@ export async function findCode(message: Message, ignoreLinks = false) {
2020
const msgs = await message.channel.messages.fetch({ limit: 10 });
2121

2222
for (const msg of msgs.values()) {
23-
const code = findCodeInMessage(msg, ignoreLinks);
23+
const code = await findCodeInMessage(msg, ignoreLinks);
2424
if (code) return code;
2525
}
2626
}
@@ -29,10 +29,11 @@ export async function findCode(message: Message, ignoreLinks = false) {
2929
// 1: Normal code block annotated with ts from a non-bot
3030
// 2: Link to TS playground. This can be either from a bot or a normal user
3131
// 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;
3637
if (!author.bot) {
3738
const match = content.match(CODEBLOCK_REGEX);
3839
if (match && match[1].length) {

0 commit comments

Comments
 (0)