KOW-7 fix: better validation
This commit is contained in:
parent
88e1f9fb42
commit
ea0ae1a47d
3 changed files with 30 additions and 0 deletions
|
@ -74,6 +74,15 @@ export default (bot: Telegraf<Context>) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if special characters or numbers (max 30 characters)
|
||||||
|
if (/[^a-zA-Z\s]/.test(userInput) || userInput.length > 30) {
|
||||||
|
ctx.reply(Strings.mlpInvalidCharacter, {
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
...({ reply_to_message_id })
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const capitalizedInput = capitalizeFirstLetter(userInput);
|
const capitalizedInput = capitalizeFirstLetter(userInput);
|
||||||
const apiUrl = `${Resources.ponyApi}/character/${capitalizedInput}`;
|
const apiUrl = `${Resources.ponyApi}/character/${capitalizedInput}`;
|
||||||
|
|
||||||
|
@ -148,6 +157,14 @@ export default (bot: Telegraf<Context>) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Number(userInput) > 100) {
|
||||||
|
ctx.reply(Strings.mlpInvalidEpisode, {
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
...({ reply_to_message_id })
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const apiUrl = `${Resources.ponyApi}/episode/by-overall/${userInput}`;
|
const apiUrl = `${Resources.ponyApi}/episode/by-overall/${userInput}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -218,6 +235,15 @@ export default (bot: Telegraf<Context>) => {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// if special characters or numbers (max 30 characters)
|
||||||
|
if (/[^a-zA-Z\s]/.test(userInput) || userInput.length > 30) {
|
||||||
|
ctx.reply(Strings.mlpInvalidCharacter, {
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
...({ reply_to_message_id })
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const apiUrl = `${Resources.ponyApi}/comics-story/${userInput}`;
|
const apiUrl = `${Resources.ponyApi}/comics-story/${userInput}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -84,6 +84,8 @@
|
||||||
"catImgErr": "Sorry, but I couldn't get the cat photo you wanted.",
|
"catImgErr": "Sorry, but I couldn't get the cat photo you wanted.",
|
||||||
"catGifErr": "Sorry, but I couldn't get the cat GIF you wanted.",
|
"catGifErr": "Sorry, but I couldn't get the cat GIF you wanted.",
|
||||||
"dogImgErr": "Sorry, but I couldn't get the dog photo you wanted.",
|
"dogImgErr": "Sorry, but I couldn't get the dog photo you wanted.",
|
||||||
|
"mlpInvalidCharacter": "Please provide a valid character name.",
|
||||||
|
"mlpInvalidEpisode": "Please provide a valid episode number.",
|
||||||
"foxApiErr": "An error occurred while fetching data from the API.\n\n`{error}`",
|
"foxApiErr": "An error occurred while fetching data from the API.\n\n`{error}`",
|
||||||
"duckApiErr": "An error occurred while fetching data from the API.\n\n`{error}`",
|
"duckApiErr": "An error occurred while fetching data from the API.\n\n`{error}`",
|
||||||
"httpCodes": {
|
"httpCodes": {
|
||||||
|
|
|
@ -84,6 +84,8 @@
|
||||||
"catImgErr": "Desculpe, mas não consegui obter a foto do gato que você queria.",
|
"catImgErr": "Desculpe, mas não consegui obter a foto do gato que você queria.",
|
||||||
"catGifErr": "Desculpe, mas não consegui obter o GIF do gato que você queria.",
|
"catGifErr": "Desculpe, mas não consegui obter o GIF do gato que você queria.",
|
||||||
"dogImgErr": "Desculpe, mas não consegui obter a foto do cacbhorro que você queria.",
|
"dogImgErr": "Desculpe, mas não consegui obter a foto do cacbhorro que você queria.",
|
||||||
|
"mlpInvalidCharacter": "Por favor, forneça um nome de personagem válido.",
|
||||||
|
"mlpInvalidEpisode": "Por favor, forneça um número de episódio válido.",
|
||||||
"foxApiErr": "Ocorreu um erro ao buscar dados da API.\n\n`{error}`",
|
"foxApiErr": "Ocorreu um erro ao buscar dados da API.\n\n`{error}`",
|
||||||
"duckApiErr": "Ocorreu um erro ao buscar dados da API.\n\n`{error}`",
|
"duckApiErr": "Ocorreu um erro ao buscar dados da API.\n\n`{error}`",
|
||||||
"httpCodes": {
|
"httpCodes": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue