From 8e85ed5d0f3cf2713bd6816c7ebfd087c9684cb8 Mon Sep 17 00:00:00 2001 From: Giovani Finazzi <53719063+GiovaniFZ@users.noreply.github.com> Date: Tue, 21 Jan 2025 23:32:04 -0300 Subject: [PATCH] feat: Show the weather according to the countrycode of the first country instead of the userlang (#30) --- src/commands/weather.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/commands/weather.js b/src/commands/weather.js index f3e9922..42c62bd 100644 --- a/src/commands/weather.js +++ b/src/commands/weather.js @@ -19,12 +19,10 @@ const statusEmojis = { const getStatusEmoji = (statusCode) => statusEmojis[statusCode] || 'n/a'; -function getLocaleUnit(userLang) { +function getLocaleUnit(countryCode) { const fahrenheitCountries = ['US', 'BS', 'BZ', 'KY', 'LR']; - const languagePrefix = userLang.split('-')[0]; - const countryCode = userLang.split('-')[1]; - if (languagePrefix === 'en' || (countryCode && fahrenheitCountries.includes(countryCode))) { + if (fahrenheitCountries.includes(countryCode)) { return { temperatureUnit: 'F', speedUnit: 'mph', apiUnit: 'e' }; } else { return { temperatureUnit: 'C', speedUnit: 'km/h', apiUnit: 'm' }; @@ -68,7 +66,8 @@ module.exports = (bot) => { const addressFirst = locationData.address[0]; const latFirst = locationData.latitude[0]; const lonFirst = locationData.longitude[0]; - const { temperatureUnit, speedUnit, apiUnit } = getLocaleUnit(userLang); + const countryCode = locationData.countryCode[0]; + const { temperatureUnit, speedUnit, apiUnit } = getLocaleUnit(countryCode); const weatherResponse = await axios.get('https://api.weather.com/v3/aggcommon/v3-wx-observations-current', { params: {