From 48ef9fc634655bfe103d50962d42a6a8895c4978 Mon Sep 17 00:00:00 2001 From: Eric Raio Date: Fri, 28 Oct 2022 06:29:51 -0700 Subject: [PATCH] prevent graph crash if text based --- worker.js | 16 ++++++++++++++++ worker.ts | 21 +++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/worker.js b/worker.js index 07550cd..bfb9221 100644 --- a/worker.js +++ b/worker.js @@ -420,6 +420,22 @@ function initBot() { return; } var key = ctx.match[1]; + var question = null; + Object.keys(config.userConfig).forEach(function (key) { + var survey = config.userConfig[key]; + for (var i = 0; i < survey.questions.length; i++) { + var currentQuestion = survey.questions[i]; + if (currentQuestion.key == key) { + question = currentQuestion; + return; + } + } + }); + if (question.type == "text" || question.type == "location") { + ctx + .reply("Sorry, the key " + key + " is a " + question.type + " based question and unable to graph it out."); + return; + } console.log("User wants to graph a specific value " + key); printGraph(key, ctx, 100, null, false); }); diff --git a/worker.ts b/worker.ts index e0c3e61..c7b4e31 100644 --- a/worker.ts +++ b/worker.ts @@ -593,6 +593,27 @@ function initBot() { } let key = ctx.match[1]; + let question: QuestionToAsk = null; + + Object.keys(config.userConfig).forEach(function(key) { + var survey = config.userConfig[key]; + for (let i = 0; i < survey.questions.length; i++) { + let currentQuestion = survey.questions[i]; + if (currentQuestion.key == key) { + question = currentQuestion; + return; + } + } + }); + + if (question.type == "text" || question.type == "location") { + ctx + .reply( + `Sorry, the key ${key} is a ${question.type} based question and unable to graph it out.` + ) + return; + } + console.log("User wants to graph a specific value " + key); printGraph(key, ctx, 100, null, false);