mirror of
https://github.com/abocn/TelegramBot.git
synced 2025-03-10 04:39:57 +00:00
Put all strings of /weather on another JSON object
This commit is contained in:
parent
39f22ccf96
commit
629401dee8
@ -35,16 +35,16 @@ module.exports = (bot) => {
|
|||||||
bot.command(['clima', 'weather'], spamwatchMiddleware, async (ctx) => {
|
bot.command(['clima', 'weather'], spamwatchMiddleware, async (ctx) => {
|
||||||
const userLang = ctx.from.language_code || "en-US";
|
const userLang = ctx.from.language_code || "en-US";
|
||||||
const Strings = getStrings(userLang);
|
const Strings = getStrings(userLang);
|
||||||
const args = ctx.message.text;
|
const userInput = ctx.message.text.split(' ').slice(1).join(' ');
|
||||||
|
|
||||||
if (args.length < 9) {
|
if (!userInput) {
|
||||||
return ctx.reply(Strings.weatherProvideLocation, {
|
return ctx.reply(Strings.weatherStatus.provideLocation, {
|
||||||
parse_mode: "Markdown",
|
parse_mode: "Markdown",
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const location = args.slice(9);
|
const location = userInput;
|
||||||
const apiKey = process.env.weatherKey;
|
const apiKey = process.env.weatherKey;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -59,7 +59,7 @@ module.exports = (bot) => {
|
|||||||
|
|
||||||
const locationData = locationResponse.data.location;
|
const locationData = locationResponse.data.location;
|
||||||
if (!locationData || !locationData.address) {
|
if (!locationData || !locationData.address) {
|
||||||
return ctx.reply(Strings.weatherInvalidLocation, {
|
return ctx.reply(Strings.weatherStatus.invalidLocation, {
|
||||||
parse_mode: "Markdown",
|
parse_mode: "Markdown",
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
});
|
});
|
||||||
@ -83,7 +83,7 @@ module.exports = (bot) => {
|
|||||||
const weatherData = weatherResponse.data['v3-wx-observations-current'];
|
const weatherData = weatherResponse.data['v3-wx-observations-current'];
|
||||||
const { temperature, temperatureFeelsLike, relativeHumidity, windSpeed, iconCode, wxPhraseLong } = weatherData;
|
const { temperature, temperatureFeelsLike, relativeHumidity, windSpeed, iconCode, wxPhraseLong } = weatherData;
|
||||||
|
|
||||||
const weatherMessage = Strings.weatherStatus
|
const weatherMessage = Strings.weatherStatus.resultMsg
|
||||||
.replace('{addressFirst}', addressFirst)
|
.replace('{addressFirst}', addressFirst)
|
||||||
.replace('{getStatusEmoji(iconCode)}', getStatusEmoji(iconCode))
|
.replace('{getStatusEmoji(iconCode)}', getStatusEmoji(iconCode))
|
||||||
.replace('{wxPhraseLong}', wxPhraseLong)
|
.replace('{wxPhraseLong}', wxPhraseLong)
|
||||||
@ -100,7 +100,7 @@ module.exports = (bot) => {
|
|||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = Strings.weatherErr.replace('{error}', error.message);
|
const message = Strings.weatherStatus.apiErr.replace('{error}', error.message);
|
||||||
ctx.reply(message, {
|
ctx.reply(message, {
|
||||||
parse_mode: "Markdown",
|
parse_mode: "Markdown",
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
|
@ -47,10 +47,12 @@
|
|||||||
"lastFmErr": "*Error retrieving data for Last.fm user* {lastfmUser}.\n\n`{err}`",
|
"lastFmErr": "*Error retrieving data for Last.fm user* {lastfmUser}.\n\n`{err}`",
|
||||||
"gitCurrentCommit": "*Current commit:* `{commitHash}`",
|
"gitCurrentCommit": "*Current commit:* `{commitHash}`",
|
||||||
"gitErrRetrievingCommit": "*Error retrieving commit:* {error}",
|
"gitErrRetrievingCommit": "*Error retrieving commit:* {error}",
|
||||||
"weatherProvideLocation": "*Please provide a location.*",
|
"weatherStatus": {
|
||||||
"weatherInvalidLocation": "*Invalid location. Try again.*",
|
"provideLocation": "*Please provide a location.*",
|
||||||
"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}`",
|
"invalidLocation": "*Invalid location. Try again.*",
|
||||||
"weatherErr": "*An error occurred while retrieving the weather. Please try again later.*\n\n`{error}`",
|
"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",
|
"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",
|
"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",
|
"usefulCommands": "Useful commands",
|
||||||
|
@ -47,10 +47,12 @@
|
|||||||
"lastFmErr": "*Erro ao recuperar dados para o usuário do Last.fm* {lastfmUser}.\n\n`{err}`",
|
"lastFmErr": "*Erro ao recuperar dados para o usuário do Last.fm* {lastfmUser}.\n\n`{err}`",
|
||||||
"gitCurrentCommit": "*Commit atual:* `{commitHash}`",
|
"gitCurrentCommit": "*Commit atual:* `{commitHash}`",
|
||||||
"gitErrRetrievingCommit": "*Erro ao obter o commit:*\n\n`{error}`",
|
"gitErrRetrievingCommit": "*Erro ao obter o commit:*\n\n`{error}`",
|
||||||
"weatherProvideLocation": "*Por favor, forneça uma localização.*",
|
"weatherStatus": {
|
||||||
"weatherInvalidLocation": "*Localização inválida. Tente novamente.*",
|
"provideLocation": "*Por favor, forneça uma localização.*",
|
||||||
"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}`",
|
"invalidLocation": "*Localização inválida. Tente novamente.*",
|
||||||
"weatherErr": "*Ocorreu um erro ao obter o clima. Tente novamente mais tarde.*\n\n`{error}`",
|
"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",
|
"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",
|
"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",
|
"usefulCommands": "Comandos úteis",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user