@@ -6,6 +6,7 @@ import type { AlgoliaHit } from '../types/algolia.js';
66import { expandAlgoliaObjectId } from '../util/compactAlgoliaId.js' ;
77import { API_BASE_ALGOLIA } from '../util/constants.js' ;
88import { fetchDocsBody } from '../util/discordDocs.js' ;
9+ import { noCodeLines } from '../util/djsguide.js' ;
910import { prepareResponse , prepareErrorResponse } from '../util/respond.js' ;
1011import { truncate } from '../util/truncate.js' ;
1112import { resolveHitToNamestring } from './autocomplete/algoliaAutoComplete.js' ;
@@ -45,9 +46,28 @@ export async function algoliaResponse(
4546
4647 const contentParts = [
4748 `<:${ emojiName } :${ emojiId } > ${ bold ( resolveHitToNamestring ( hit ) ) } ${ headlineSuffix ? ` ${ headlineSuffix } ` : '' } ` ,
48- hit . content ?. length ? `${ truncate ( decode ( hit . content ) , 300 ) } ` : docsSection ?. lines . at ( 0 ) ,
49- `${ hyperlink ( 'read more' , hideLinkEmbed ( hit . url ) ) } ` ,
50- ] . filter ( Boolean ) as string [ ] ;
49+ ] ;
50+
51+ if ( hit . content ?. length ) {
52+ contentParts . push ( `${ truncate ( decode ( hit . content ) , 300 ) } ` ) ;
53+ } else {
54+ const descriptionParts = [ ] ;
55+ let descriptionLength = 0 ;
56+ const relevantLines = noCodeLines ( docsSection ?. lines ?? [ ] ) ;
57+
58+ if ( relevantLines . length ) {
59+ for ( const line of relevantLines ) {
60+ if ( descriptionLength + line . length < 500 ) {
61+ descriptionParts . push ( line ) ;
62+ descriptionLength += line . length ;
63+ }
64+ }
65+
66+ contentParts . push ( descriptionParts . join ( ' ' ) ) ;
67+ }
68+ }
69+
70+ contentParts . push ( `${ hyperlink ( 'read more' , hideLinkEmbed ( hit . url ) ) } ` ) ;
5171
5272 prepareResponse ( res , contentParts . join ( '\n' ) , {
5373 ephemeral,
0 commit comments