Skip to content

Commit

Permalink
Merge pull request #84 from berkingurcan/fix-survey-to-text
Browse files Browse the repository at this point in the history
Fix survey to text
  • Loading branch information
berkingurcan authored Oct 17, 2024
2 parents c177122 + 9dacb63 commit f9005ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "discord-bot",
"type": "module",
"version": "0.3.7",
"version": "0.3.8",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
19 changes: 8 additions & 11 deletions src/lib/surveyToText.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,11 @@ export default async function surveyToText(

if (subtopic.responses != null && subtopic.responses.length > 0) {
let i = 0
const responseMessages = subtopic.responses.map((response, i) => {
i++
const responseMessages = subtopic.responses.map((response) => {
summarizedResponses.push(response);
return formatResponse(surveyType, response, responses, i-1);
return formatResponse(surveyType, response, responses);
});


const title = `${index + 1}${number_to_letter[subindex]} ${topic.topicName}${subtopic.subtopicName}`;

Expand Down Expand Up @@ -495,16 +495,13 @@ export default async function surveyToText(
return [msg, files];
}

function formatResponse(surveyType, response, responses, i) {
const responsesKeys = Object.keys(responses)
const responsesValues = Object.values(responses)

function formatResponse(surveyType, response, responses) {
let responseIsLatest;
if (surveyType == "single") {
const latestResponse = responsesValues[i];
const latestResponse = responses[response.username];
responseIsLatest = latestResponse == response.response;
} else {
const baseUsername = responsesKeys[i];
const baseUsername = response.username;
let userResponses;
try {
userResponses = JSON.parse(responses[baseUsername]);
Expand All @@ -515,10 +512,10 @@ export default async function surveyToText(
responseIsLatest = userResponses.some((r) => r == response.response);
}
if (responseIsLatest) {
return responsesKeys[i] + ' said "' + response.response + '"';
return response.username + ' said "' + response.response + '"';
} else {
return (
responsesKeys[i] +
response.username +
' previously said "' +
response.response +
'". The next update will include their latest response.'
Expand Down

0 comments on commit f9005ce

Please sign in to comment.