@@ -7,55 +7,42 @@ namespace NetCordBuddy.Modules;
77
88internal static class DocsHelper
99{
10- public static EmbedProperties CreateDocsEmbed ( string query , int page , DocsService docsService , Configuration config , ulong interactionId , User interactionUser , out bool more )
10+ public static IEnumerable < IComponentProperties > CreateDocsComponents ( string query , int page , DocsService docsService , Configuration config )
1111 {
12- var results = docsService . FindSymbols ( query , page * 5 , 5 , out more ) ;
13-
14- if ( results . Count == 0 )
15- throw new ( "No results found!" ) ;
16-
17- var embedTitle = "Results" ;
18- var footerText = interactionUser . Username ;
19-
20- int length = embedTitle . Length + footerText . Length ;
21-
22- var embedFields = results
23- . Select ( s => new EmbedFieldProperties ( )
24- {
25- Value = $ "```cs\n { s . Name } ```[Docs]({ s . DocsUrl } )",
26- } )
27- . Where ( f => f . Value ! . Length <= 1024 )
28- . TakeWhile ( f => ( length += f . Value ! . Length ) <= 6000 ) ;
29-
30- return new ( )
31- {
32- Title = embedTitle ,
33- Footer = new ( )
34- {
35- Text = footerText ,
36- IconUrl = ( interactionUser . HasAvatar ? interactionUser . GetAvatarUrl ( ) : interactionUser . DefaultAvatarUrl ) . ToString ( ) ,
37- } ,
38- Fields = embedFields ,
39- Timestamp = Snowflake . CreatedAt ( interactionId ) ,
40- Color = new ( config . PrimaryColor ) ,
41- } ;
42- }
12+ var results = docsService . FindSymbols ( query , page * 5 , 5 , out var more ) ;
13+
14+ var container = new ComponentContainerProperties ( )
15+ . WithAccentColor ( new ( config . PrimaryColor ) ) ;
16+
17+ if ( results . Count is 0 )
18+ return
19+ [
20+ container
21+ . AddComponents ( new TextDisplayProperties ( "# No symbols found!" ) )
22+ ] ;
23+
24+ var title = "# Symbols" ;
25+
26+ int length = title . Length ;
27+
28+ var sections = results
29+ . Select ( s => new ComponentSectionProperties ( new LinkButtonProperties ( s . DocsUrl , "Docs" ) )
30+ . AddComponents ( new TextDisplayProperties ( $ "```cs\n { s . Name } ```") ) )
31+ . TakeWhile ( s => ( length += s . Components . First ( ) . Content . Length ) <= 4000 ) ;
4332
44- public static IEnumerable < MessageComponentProperties > CreateDocsComponents ( string query , int page , bool more , Configuration config )
45- {
4633 return
4734 [
48- new ActionRowProperties (
49- [
50- new ButtonProperties ( $ "docs: { page - 1 } : { query } " , new EmojiProperties ( config . Emojis . Left ) , ButtonStyle . Primary )
51- {
52- Disabled = page < 1 ,
53- } ,
54- new ButtonProperties ( $ "docs: { page + 1 } : { query } " , new EmojiProperties ( config . Emojis . Right ) , ButtonStyle . Primary )
55- {
56- Disabled = ! more ,
57- } ,
58- ] ) ,
35+ container
36+ . AddComponents ( new TextDisplayProperties ( title ) )
37+ . AddComponents ( sections )
38+ . AddComponents ( new ActionRowProperties ( )
39+ . AddButtons (
40+ new ButtonProperties ( $ "docs: { page - 1 } : { query } " , new EmojiProperties ( config . Emojis . Left ) , ButtonStyle . Primary )
41+ . WithDisabled ( page < 1 ) ,
42+ new ButtonProperties ( $ "docs: { page + 1 } : { query } " , new EmojiProperties ( config . Emojis . Right ) , ButtonStyle . Primary )
43+ . WithDisabled ( ! more )
44+ )
45+ )
5946 ] ;
6047 }
6148}
0 commit comments