Skip to content

Commit

Permalink
Merge pull request #49 from iluxonchik/feature/govbot-0.0.17
Browse files Browse the repository at this point in the history
Feature/govbot 0.0.17 - Community Deliberation Votes Display
  • Loading branch information
iluxonchik authored Sep 19, 2024
2 parents d71f3c4 + 08fd677 commit b235e3d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mina-govbot",
"version": "0.0.16",
"version": "0.0.17",
"description": "Discord bot for collective decision making for Mina Protocol",
"main": "index.js",
"directories": {
Expand Down
50 changes: 47 additions & 3 deletions src/logic/VoteCountingLogic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FundingRound, Proposal, SMEConsiderationVoteLog, CommitteeDeliberationVoteLog } from '../models';
import { FundingRound, Proposal, SMEConsiderationVoteLog, CommitteeDeliberationVoteLog, GPTSummarizerVoteLog } from '../models';
import { EndUserError } from '../Errors';
import { CommitteeDeliberationVoteChoice } from '../types';
import { TrackedInteraction } from '../core/BaseClasses';
Expand Down Expand Up @@ -29,6 +29,11 @@ interface VoteResultWithReasoning extends VoteResult {
isPass: boolean;
reason: string | null;
}[];
communityFeedback?: {
voterUsername: string;
feedback: string;
reason: string | null;
}[];
}

export class VoteCountingLogic {
Expand Down Expand Up @@ -334,6 +339,8 @@ export class VoteCountingLogic {

const proposerUsername = await this.getUsername(trackedInteraction, proposal.proposerDuid);

const communityFeedback = await this.getCommunityFeedback(proposal.id, trackedInteraction);

return {
projectId: proposal.id,
projectName: proposal.name,
Expand All @@ -346,17 +353,44 @@ export class VoteCountingLogic {
approvedModifiedVoters: approvedModifiedVoterUsernames,
deliberationVotes,
considerationVotes: [],
communityFeedback,
};
}),
);
}

private static async getCommunityFeedback(proposalId: number, trackedInteraction: TrackedInteraction) {
const feedbackLogs = await GPTSummarizerVoteLog.findAll({
where: { proposalId },
order: [['createdAt', 'DESC']],
});

const latestFeedback = new Map<string, { feedback: string; reason: string | null }>();
for (const log of feedbackLogs) {
if (!latestFeedback.has(log.duid)) {
latestFeedback.set(log.duid, { feedback: log.why, reason: log.reason });
}
}

const communityFeedback = [];
for (const [duid, { feedback, reason }] of latestFeedback) {
const voterUsername = await this.getUsername(trackedInteraction, duid);
communityFeedback.push({ voterUsername, feedback, reason });
}

return communityFeedback;
}

public static formatVoteReasoningMessage(voteResults: VoteResultWithReasoning[]): EmbedBuilder[] {
const embeds: EmbedBuilder[] = [];

for (const result of voteResults) {
if (result.deliberationVotes.length === 0 && result.considerationVotes.length === 0) {
continue; // Skip projects with no votes
if (
result.deliberationVotes.length === 0 &&
result.considerationVotes.length === 0 &&
(!result.communityFeedback || result.communityFeedback.length === 0)
) {
continue; // Skip projects with no votes or feedback
}

const embed = new EmbedBuilder()
Expand All @@ -382,6 +416,16 @@ export class VoteCountingLogic {
embed.addFields({ name: 'Consideration Phase Votes', value: considerationField.trim() });
}

if (result.communityFeedback && result.communityFeedback.length > 0) {
let feedbackField = '';
for (const feedback of result.communityFeedback) {
feedbackField += `**${feedback.voterUsername}**\n`;
feedbackField += `Feedback: ${feedback.feedback}\n`;
feedbackField += `Reason for Change: ${feedback.reason || 'No reason provided'}\n\n`;
}
embed.addFields({ name: 'Community Feedback', value: feedbackField.trim() });
}

embeds.push(embed);
}

Expand Down

0 comments on commit b235e3d

Please sign in to comment.