mirror of
https://github.com/abocn/TelegramBot.git
synced 2025-03-10 04:39:57 +00:00
feat: Show the weather according to the countrycode of the first country instead of the userlang (#30)
This commit is contained in:
parent
4a645cc85b
commit
8e85ed5d0f
@ -19,12 +19,10 @@ const statusEmojis = {
|
|||||||
|
|
||||||
const getStatusEmoji = (statusCode) => statusEmojis[statusCode] || 'n/a';
|
const getStatusEmoji = (statusCode) => statusEmojis[statusCode] || 'n/a';
|
||||||
|
|
||||||
function getLocaleUnit(userLang) {
|
function getLocaleUnit(countryCode) {
|
||||||
const fahrenheitCountries = ['US', 'BS', 'BZ', 'KY', 'LR'];
|
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' };
|
return { temperatureUnit: 'F', speedUnit: 'mph', apiUnit: 'e' };
|
||||||
} else {
|
} else {
|
||||||
return { temperatureUnit: 'C', speedUnit: 'km/h', apiUnit: 'm' };
|
return { temperatureUnit: 'C', speedUnit: 'km/h', apiUnit: 'm' };
|
||||||
@ -68,7 +66,8 @@ module.exports = (bot) => {
|
|||||||
const addressFirst = locationData.address[0];
|
const addressFirst = locationData.address[0];
|
||||||
const latFirst = locationData.latitude[0];
|
const latFirst = locationData.latitude[0];
|
||||||
const lonFirst = locationData.longitude[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', {
|
const weatherResponse = await axios.get('https://api.weather.com/v3/aggcommon/v3-wx-observations-current', {
|
||||||
params: {
|
params: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user