@@ -89,18 +89,44 @@ export class LookupCommand implements Command {
8989 0
9090 ) ;
9191
92- // :tf:
93- const message =
92+ const messageHeader =
9493 '```md\n' +
9594 `| CID | IP | ${ ' ' . repeat ( Math . max ( Math . floor ( longestCkey / 2 ) - 2 , 0 ) ) } CKEY${ ' ' . repeat ( Math . max ( Math . ceil ( longestCkey / 2 ) - 2 , 0 ) ) } |\n` +
96- `|------------|-----------------|-${ '-' . repeat ( longestCkey ) } -|\n` +
97- rows
98- . map (
99- ( [ cid , ip , ckey ] ) =>
100- `| ${ cid } | ${ ip . padEnd ( 15 , ' ' ) } | ${ ckey . padEnd ( longestCkey , ' ' ) } |\n`
101- )
102- . join ( '' ) +
103- '```' ;
95+ `|------------|-----------------|-${ '-' . repeat ( longestCkey ) } -|\n` ;
96+ const messageBody = rows
97+ . map (
98+ ( [ cid , ip , ckey ] ) =>
99+ `| ${ cid } | ${ ip . padEnd ( 15 , ' ' ) } | ${ ckey . padEnd ( longestCkey , ' ' ) } |\n`
100+ )
101+ . join ( '' ) ;
102+ const messageFooter = '```' ;
103+
104+ const message = messageHeader + messageBody + messageFooter ;
105+
106+ if ( message . length > 2000 ) {
107+ const messageParts = [ ] ;
108+ let currentPart = messageHeader ;
109+
110+ for ( const line of messageBody . split ( '\n' ) ) {
111+ if ( currentPart . length + line . length + messageFooter . length > 1999 ) {
112+ messageParts . push ( currentPart + messageFooter ) ;
113+ currentPart = messageHeader + line + '\n' ;
114+ } else {
115+ currentPart += line + '\n' ;
116+ }
117+ }
118+
119+ currentPart += messageFooter ;
120+ messageParts . push ( currentPart ) ;
121+
122+ await interaction . reply ( messageParts [ 0 ] ) ;
123+
124+ for ( let i = 1 ; i < messageParts . length ; i ++ ) {
125+ await interaction . followUp ( messageParts [ i ] ) ;
126+ }
127+
128+ return ;
129+ }
104130
105131 await interaction . reply ( message ) ;
106132 }
0 commit comments