From 629401dee88eab8c8ec3030a364d43b0a6b6b255 Mon Sep 17 00:00:00 2001 From: Luquinhas Date: Fri, 10 Jan 2025 11:18:52 -0300 Subject: [PATCH] Put all strings of /weather on another JSON object --- src/commands/weather.js | 14 +++++++------- src/locales/english.json | 10 ++++++---- src/locales/portuguese.json | 10 ++++++---- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/commands/weather.js b/src/commands/weather.js index 9b00dcd..f3e9922 100644 --- a/src/commands/weather.js +++ b/src/commands/weather.js @@ -35,16 +35,16 @@ module.exports = (bot) => { bot.command(['clima', 'weather'], spamwatchMiddleware, async (ctx) => { const userLang = ctx.from.language_code || "en-US"; const Strings = getStrings(userLang); - const args = ctx.message.text; + const userInput = ctx.message.text.split(' ').slice(1).join(' '); - if (args.length < 9) { - return ctx.reply(Strings.weatherProvideLocation, { + if (!userInput) { + return ctx.reply(Strings.weatherStatus.provideLocation, { parse_mode: "Markdown", reply_to_message_id: ctx.message.message_id }); } - const location = args.slice(9); + const location = userInput; const apiKey = process.env.weatherKey; try { @@ -59,7 +59,7 @@ module.exports = (bot) => { const locationData = locationResponse.data.location; if (!locationData || !locationData.address) { - return ctx.reply(Strings.weatherInvalidLocation, { + return ctx.reply(Strings.weatherStatus.invalidLocation, { parse_mode: "Markdown", reply_to_message_id: ctx.message.message_id }); @@ -83,7 +83,7 @@ module.exports = (bot) => { const weatherData = weatherResponse.data['v3-wx-observations-current']; const { temperature, temperatureFeelsLike, relativeHumidity, windSpeed, iconCode, wxPhraseLong } = weatherData; - const weatherMessage = Strings.weatherStatus + const weatherMessage = Strings.weatherStatus.resultMsg .replace('{addressFirst}', addressFirst) .replace('{getStatusEmoji(iconCode)}', getStatusEmoji(iconCode)) .replace('{wxPhraseLong}', wxPhraseLong) @@ -100,7 +100,7 @@ module.exports = (bot) => { reply_to_message_id: ctx.message.message_id }); } catch (error) { - const message = Strings.weatherErr.replace('{error}', error.message); + const message = Strings.weatherStatus.apiErr.replace('{error}', error.message); ctx.reply(message, { parse_mode: "Markdown", reply_to_message_id: ctx.message.message_id diff --git a/src/locales/english.json b/src/locales/english.json index 5b8ecfb..71f2b99 100644 --- a/src/locales/english.json +++ b/src/locales/english.json @@ -47,10 +47,12 @@ "lastFmErr": "*Error retrieving data for Last.fm user* {lastfmUser}.\n\n`{err}`", "gitCurrentCommit": "*Current commit:* `{commitHash}`", "gitErrRetrievingCommit": "*Error retrieving commit:* {error}", - "weatherProvideLocation": "*Please provide a location.*", - "weatherInvalidLocation": "*Invalid location. Try again.*", - "weatherStatus": "*Weather in {addressFirst}:*\n\n*Status:* `{getStatusEmoji(iconCode)} {wxPhraseLong}`\n*Temperature:* `{temperature} °{temperatureUnit}`\n*Feels like:* `{temperatureFeelsLike} °{temperatureUnit2}`\n*Humidity:* `{relativeHumidity}%`\n*Wind speed:* `{windSpeed} {speedUnit}`", - "weatherErr": "*An error occurred while retrieving the weather. Please try again later.*\n\n`{error}`", + "weatherStatus": { + "provideLocation": "*Please provide a location.*", + "invalidLocation": "*Invalid location. Try again.*", + "resultMsg": "*Weather in {addressFirst}:*\n\n*Status:* `{getStatusEmoji(iconCode)} {wxPhraseLong}`\n*Temperature:* `{temperature} °{temperatureUnit}`\n*Feels like:* `{temperatureFeelsLike} °{temperatureUnit2}`\n*Humidity:* `{relativeHumidity}%`\n*Wind speed:* `{windSpeed} {speedUnit}`", + "apiErr": "*An error occurred while retrieving the weather. Please try again later.*\n\n`{error}`" + }, "mainCommands": "Main commands", "mainCommandsDesc": "*Main commands*\n\n- /help: Show bot's help\n- /start: Start the bot\n- /privacy: Read the bot's Privacy Policy", "usefulCommands": "Useful commands", diff --git a/src/locales/portuguese.json b/src/locales/portuguese.json index c4eea7c..9ac23cb 100644 --- a/src/locales/portuguese.json +++ b/src/locales/portuguese.json @@ -47,10 +47,12 @@ "lastFmErr": "*Erro ao recuperar dados para o usuário do Last.fm* {lastfmUser}.\n\n`{err}`", "gitCurrentCommit": "*Commit atual:* `{commitHash}`", "gitErrRetrievingCommit": "*Erro ao obter o commit:*\n\n`{error}`", - "weatherProvideLocation": "*Por favor, forneça uma localização.*", - "weatherInvalidLocation": "*Localização inválida. Tente novamente.*", - "weatherStatus": "*Clima em {addressFirst}:*\n\n*Estado:* `{getStatusEmoji(iconCode)} {wxPhraseLong}`\n*Temperatura:* `{temperature} °{temperatureUnit}`\n*Sensação térmica:* `{temperatureFeelsLike} °{temperatureUnit2}`\n*Umidade:* `{relativeHumidity}%`\n*Velocidade do vento:* `{windSpeed} {speedUnit}`", - "weatherErr": "*Ocorreu um erro ao obter o clima. Tente novamente mais tarde.*\n\n`{error}`", + "weatherStatus": { + "provideLocation": "*Por favor, forneça uma localização.*", + "invalidLocation": "*Localização inválida. Tente novamente.*", + "resultMsg": "*Clima em {addressFirst}:*\n\n*Estado:* `{getStatusEmoji(iconCode)} {wxPhraseLong}`\n*Temperatura:* `{temperature} °{temperatureUnit}`\n*Sensação térmica:* `{temperatureFeelsLike} °{temperatureUnit2}`\n*Umidade:* `{relativeHumidity}%`\n*Velocidade do vento:* `{windSpeed} {speedUnit}`", + "apiErr": "*Ocorreu um erro ao obter o clima. Tente novamente mais tarde.*\n\n`{error}`" + }, "mainCommands": "Comandos principais", "mainCommandsDesc": "*Comandos principais*\n\n- /help: Exibe a ajuda do bot\n- /start: Inicia o bot\n- /privacy: Leia a política de privacidade do bot", "usefulCommands": "Comandos úteis",