@@ -4,7 +4,7 @@ import { CommitteeDeliberationVoteChoice } from '../types';
4
4
import { TrackedInteraction } from '../core/BaseClasses' ;
5
5
import logger from '../logging' ;
6
6
import { Op } from 'sequelize' ;
7
- import { EmbedBuilder } from 'discord.js' ;
7
+ import { APIEmbedField , EmbedBuilder } from 'discord.js' ;
8
8
9
9
interface VoteResult {
10
10
projectId : number ;
@@ -381,6 +381,33 @@ export class VoteCountingLogic {
381
381
return communityFeedback ;
382
382
}
383
383
384
+ private static splitTextIntoChunks ( text : string , maxLength : number ) : string [ ] {
385
+ const chunks : string [ ] = [ ] ;
386
+ let currentChunk = '' ;
387
+
388
+ text . split ( '\n' ) . forEach ( ( line ) => {
389
+ if ( currentChunk . length + line . length + 1 > maxLength ) {
390
+ chunks . push ( currentChunk . trim ( ) ) ;
391
+ currentChunk = '' ;
392
+ }
393
+ currentChunk += line + '\n' ;
394
+ } ) ;
395
+
396
+ if ( currentChunk ) {
397
+ chunks . push ( currentChunk . trim ( ) ) ;
398
+ }
399
+
400
+ return chunks ;
401
+ }
402
+
403
+ private static createEmbedField ( name : string , value : string ) : APIEmbedField [ ] {
404
+ const chunks = this . splitTextIntoChunks ( value , 1024 ) ;
405
+ return chunks . map ( ( chunk , index ) => ( {
406
+ name : index === 0 ? name : `${ name } (continued)` ,
407
+ value : chunk ,
408
+ } ) ) ;
409
+ }
410
+
384
411
public static formatVoteReasoningMessage ( voteResults : VoteResultWithReasoning [ ] ) : EmbedBuilder [ ] {
385
412
const embeds : EmbedBuilder [ ] = [ ] ;
386
413
@@ -393,18 +420,28 @@ export class VoteCountingLogic {
393
420
continue ; // Skip projects with no votes or feedback
394
421
}
395
422
396
- const embed = new EmbedBuilder ( )
423
+ let currentEmbed = new EmbedBuilder ( )
397
424
. setColor ( '#0099ff' )
398
425
. setTitle ( `Vote Reasoning - ${ result . projectName } (ID: ${ result . projectId } )` )
399
426
. setDescription ( `Proposer: ${ result . proposerUsername } ` ) ;
400
427
428
+ const addFieldsToEmbed = ( fields : APIEmbedField [ ] ) => {
429
+ fields . forEach ( ( field ) => {
430
+ if ( currentEmbed . data . fields && currentEmbed . data . fields . length >= 25 ) {
431
+ embeds . push ( currentEmbed ) ;
432
+ currentEmbed = new EmbedBuilder ( ) . setColor ( '#0099ff' ) . setTitle ( `Vote Reasoning - ${ result . projectName } (Continued)` ) ;
433
+ }
434
+ currentEmbed . addFields ( field ) ;
435
+ } ) ;
436
+ } ;
437
+
401
438
if ( result . deliberationVotes . length > 0 ) {
402
439
let deliberationField = '' ;
403
440
for ( const vote of result . deliberationVotes ) {
404
441
deliberationField += `**${ vote . voterUsername } **: ${ vote . vote } \n` ;
405
442
deliberationField += `Reasoning: ${ vote . reason || 'No reason provided' } \n\n` ;
406
443
}
407
- embed . addFields ( { name : 'Deliberation Phase Votes' , value : deliberationField . trim ( ) } ) ;
444
+ addFieldsToEmbed ( this . createEmbedField ( 'Deliberation Phase Votes' , deliberationField . trim ( ) ) ) ;
408
445
}
409
446
410
447
if ( result . considerationVotes . length > 0 ) {
@@ -413,7 +450,7 @@ export class VoteCountingLogic {
413
450
considerationField += `**${ vote . voterUsername } **: ${ vote . isPass ? 'Yes' : 'No' } \n` ;
414
451
considerationField += `Reasoning: ${ vote . reason || 'No reason provided' } \n\n` ;
415
452
}
416
- embed . addFields ( { name : 'Consideration Phase Votes' , value : considerationField . trim ( ) } ) ;
453
+ addFieldsToEmbed ( this . createEmbedField ( 'Consideration Phase Votes' , considerationField . trim ( ) ) ) ;
417
454
}
418
455
419
456
if ( result . communityFeedback && result . communityFeedback . length > 0 ) {
@@ -423,10 +460,10 @@ export class VoteCountingLogic {
423
460
feedbackField += `Feedback: ${ feedback . feedback } \n` ;
424
461
feedbackField += `Reason for Change: ${ feedback . reason || 'No reason provided' } \n\n` ;
425
462
}
426
- embed . addFields ( { name : 'Community Feedback' , value : feedbackField . trim ( ) } ) ;
463
+ addFieldsToEmbed ( this . createEmbedField ( 'Community Feedback' , feedbackField . trim ( ) ) ) ;
427
464
}
428
465
429
- embeds . push ( embed ) ;
466
+ embeds . push ( currentEmbed ) ;
430
467
}
431
468
432
469
return embeds ;
0 commit comments