KOW-7 fix: better validation

This commit is contained in:
Aidan 2025-06-27 18:19:30 -04:00
parent 88e1f9fb42
commit ea0ae1a47d
3 changed files with 30 additions and 0 deletions

View file

@ -74,6 +74,15 @@ export default (bot: Telegraf<Context>) => {
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 apiUrl = `${Resources.ponyApi}/character/${capitalizedInput}`;
@ -148,6 +157,14 @@ export default (bot: Telegraf<Context>) => {
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}`;
try {
@ -218,6 +235,15 @@ export default (bot: Telegraf<Context>) => {
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}`;
try {

View file

@ -84,6 +84,8 @@
"catImgErr": "Sorry, but I couldn't get the cat photo 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.",
"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}`",
"duckApiErr": "An error occurred while fetching data from the API.\n\n`{error}`",
"httpCodes": {

View file

@ -84,6 +84,8 @@
"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.",
"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}`",
"duckApiErr": "Ocorreu um erro ao buscar dados da API.\n\n`{error}`",
"httpCodes": {