From 3c0af53836c5f2157722260ddf47bea10aa1fd84 Mon Sep 17 00:00:00 2001 From: Mayur Virendra Date: Tue, 9 Apr 2024 14:04:22 +0530 Subject: [PATCH] Fixed lint issues --- controllers/Bot.js | 2 +- utils/language.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/controllers/Bot.js b/controllers/Bot.js index a6fbd77..82f0474 100644 --- a/controllers/Bot.js +++ b/controllers/Bot.js @@ -172,7 +172,7 @@ async function process_text(req, res) { } else if(ai.action?.action === 'clear_all'){ session = EMPTY_SESSION; - response.formatted = get_text_by_key(session_and_profile_cleared); + response.formatted = get_text_by_key('session_and_profile_cleared'); } else if(ai.action?.action === 'get_routes'){ const routes = await mapService.generate_routes(message, session.text, session.avoid_point|| []); diff --git a/utils/language.js b/utils/language.js index ea282ab..fd072f7 100644 --- a/utils/language.js +++ b/utils/language.js @@ -5,8 +5,9 @@ const language = JSON.parse(readFileSync('./config/language.json')) function get_text_by_key(key, variables = {}, category='ALL_MESSAGES'){ let text = language[category][key] || null; if (text) { - text = text.replace(/\$\{(\w+)\}/g, (match, variableName) => { - return variables.hasOwnProperty(variableName) ? variables[variableName] : match; + Object.keys(variables).forEach(variable => { + /* eslint no-useless-escape: "off" */ + text = text.replace(new RegExp(`\\$\{${variable}\}`, 'g'), variables[variable]); }); } return text;