Skip to content

Commit 0ad4d88

Browse files
authored
Merge pull request #51 from iluxonchik/feature/govbot-0.0.19
Feature/govbot 0.0.19 - Deliberation Phase Community Feedback
2 parents 077ca41 + 05e185e commit 0ad4d88

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mina-govbot",
3-
"version": "0.0.18",
3+
"version": "0.0.19",
44
"description": "Discord bot for collective decision making for Mina Protocol",
55
"main": "index.js",
66
"directories": {

src/channels/admin/actions/CountVotesAction.ts

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { EndUserError } from '../../../Errors';
77
import { AnyModalMessageComponent } from '../../../types/common';
88
import { DiscordStatus } from '../../DiscordStatus';
99
import { Client } from 'discord.js';
10+
import logging from '../../../logging';
1011

1112
export class CountVotesAction extends Action {
1213
public allSubActions(): Action[] {
@@ -129,6 +130,7 @@ export class CountVotesAction extends Action {
129130
if (error instanceof EndUserError) {
130131
throw error;
131132
} else {
133+
logging.error(error);
132134
throw new EndUserError('An unexpected error occurred while counting votes.');
133135
}
134136
}

src/logic/VoteCountingLogic.ts

+43-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { CommitteeDeliberationVoteChoice } from '../types';
44
import { TrackedInteraction } from '../core/BaseClasses';
55
import logger from '../logging';
66
import { Op } from 'sequelize';
7-
import { EmbedBuilder } from 'discord.js';
7+
import { APIEmbedField, EmbedBuilder } from 'discord.js';
88

99
interface VoteResult {
1010
projectId: number;
@@ -381,6 +381,33 @@ export class VoteCountingLogic {
381381
return communityFeedback;
382382
}
383383

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+
384411
public static formatVoteReasoningMessage(voteResults: VoteResultWithReasoning[]): EmbedBuilder[] {
385412
const embeds: EmbedBuilder[] = [];
386413

@@ -393,18 +420,28 @@ export class VoteCountingLogic {
393420
continue; // Skip projects with no votes or feedback
394421
}
395422

396-
const embed = new EmbedBuilder()
423+
let currentEmbed = new EmbedBuilder()
397424
.setColor('#0099ff')
398425
.setTitle(`Vote Reasoning - ${result.projectName} (ID: ${result.projectId})`)
399426
.setDescription(`Proposer: ${result.proposerUsername}`);
400427

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+
401438
if (result.deliberationVotes.length > 0) {
402439
let deliberationField = '';
403440
for (const vote of result.deliberationVotes) {
404441
deliberationField += `**${vote.voterUsername}**: ${vote.vote}\n`;
405442
deliberationField += `Reasoning: ${vote.reason || 'No reason provided'}\n\n`;
406443
}
407-
embed.addFields({ name: 'Deliberation Phase Votes', value: deliberationField.trim() });
444+
addFieldsToEmbed(this.createEmbedField('Deliberation Phase Votes', deliberationField.trim()));
408445
}
409446

410447
if (result.considerationVotes.length > 0) {
@@ -413,7 +450,7 @@ export class VoteCountingLogic {
413450
considerationField += `**${vote.voterUsername}**: ${vote.isPass ? 'Yes' : 'No'}\n`;
414451
considerationField += `Reasoning: ${vote.reason || 'No reason provided'}\n\n`;
415452
}
416-
embed.addFields({ name: 'Consideration Phase Votes', value: considerationField.trim() });
453+
addFieldsToEmbed(this.createEmbedField('Consideration Phase Votes', considerationField.trim()));
417454
}
418455

419456
if (result.communityFeedback && result.communityFeedback.length > 0) {
@@ -423,10 +460,10 @@ export class VoteCountingLogic {
423460
feedbackField += `Feedback: ${feedback.feedback}\n`;
424461
feedbackField += `Reason for Change: ${feedback.reason || 'No reason provided'}\n\n`;
425462
}
426-
embed.addFields({ name: 'Community Feedback', value: feedbackField.trim() });
463+
addFieldsToEmbed(this.createEmbedField('Community Feedback', feedbackField.trim()));
427464
}
428465

429-
embeds.push(embed);
466+
embeds.push(currentEmbed);
430467
}
431468

432469
return embeds;

0 commit comments

Comments
 (0)