1- import { hyperlink , inlineCode } from '@discordjs/builders' ;
1+ import { HeadingLevel , heading , hyperlink , inlineCode } from '@discordjs/builders' ;
22import type { Response } from 'polka' ;
33import type { ZendeskArticle , ZendeskEntity } from '../types/zendesk' ;
44import {
@@ -15,6 +15,7 @@ import {
1515import {
1616 SectionPartType ,
1717 findRelevantDocsSectionFuzzy ,
18+ findSectionFromAnchor ,
1819 parseGithubDocsSections ,
1920 sectionPartToText ,
2021} from '../util/discordDocs.js' ;
@@ -42,6 +43,15 @@ async function fetchHelpdeskArticle(id: number, autocompleteTimestamp: number, d
4243 ) ;
4344 return hit ;
4445 }
46+
47+ logger . debug (
48+ {
49+ id,
50+ autocompleteTimestamp,
51+ dev,
52+ } ,
53+ `cache hit but outdated for support article ${ id } . refreshing...` ,
54+ ) ;
4555 }
4656
4757 const base = dev ? DISCORD_HELPDESK_DEV_ARTICLES_BASE : DISCORD_HELPDESK_ARTICLES_BASE ;
@@ -61,12 +71,13 @@ export async function helpdeskResponse(
6171 ephemeral ?: boolean ,
6272 secondAttempt = false ,
6373) {
64- const [ articleId , timestampString , ...originalQuery ] = query . split ( DJS_QUERY_SEPARATOR ) ;
74+ const [ articleId , timestampString , ...originalQueryParts ] = query . split ( DJS_QUERY_SEPARATOR ) ;
75+ const originalQuery = originalQueryParts . join ( DJS_QUERY_SEPARATOR ) ;
6576
6677 const numberId = Number . parseInt ( articleId , 10 ) ;
6778 if ( Number . isNaN ( numberId ) ) {
6879 if ( secondAttempt ) {
69- prepareErrorResponse ( res , `No documentation found for ${ inlineCode ( originalQuery . join ( DJS_QUERY_SEPARATOR ) ) } .` ) ;
80+ prepareErrorResponse ( res , `No documentation found for ${ inlineCode ( originalQuery ) } .` ) ;
7081 return res ;
7182 }
7283
@@ -87,10 +98,13 @@ export async function helpdeskResponse(
8798 const bodyParts = [ '---' , `title: ${ article . title } ` , '---' , ...turnedDown . split ( / \n + / ) ] ;
8899
89100 const parsedSections = parseGithubDocsSections ( bodyParts ) ;
90- const relevantSection = findRelevantDocsSectionFuzzy ( parsedSections , originalQuery . join ( DJS_QUERY_SEPARATOR ) , true ) ;
101+
102+ const relevantSection = originalQuery . startsWith ( '#h' )
103+ ? findSectionFromAnchor ( parsedSections , originalQuery )
104+ : findRelevantDocsSectionFuzzy ( parsedSections , originalQuery , true ) ;
91105
92106 if ( ! relevantSection ) {
93- prepareErrorResponse ( res , `No documentation found for ${ inlineCode ( query ) } .` ) ;
107+ prepareErrorResponse ( res , `No documentation found for ${ inlineCode ( originalQuery ) } .` ) ;
94108 return res ;
95109 }
96110
0 commit comments