mirror of
https://github.com/abocn/TelegramBot.git
synced 2025-03-10 12:49:57 +00:00
Pony API integration for My Little Pony information
This commit is contained in:
parent
ae9f92ae96
commit
4688c4af31
@ -11,7 +11,7 @@ async function sendHelpMessage(ctx, isEditing) {
|
|||||||
[{ text: Strings.mainCommands, callback_data: 'helpMain' }, { text: Strings.usefulCommands, callback_data: 'helpUseful' }],
|
[{ text: Strings.mainCommands, callback_data: 'helpMain' }, { text: Strings.usefulCommands, callback_data: 'helpUseful' }],
|
||||||
[{ text: Strings.interactiveEmojis, callback_data: 'helpInteractive' }, { text: Strings.funnyCommands, callback_data: 'helpFunny' }],
|
[{ text: Strings.interactiveEmojis, callback_data: 'helpInteractive' }, { text: Strings.funnyCommands, callback_data: 'helpFunny' }],
|
||||||
[{ text: Strings.lastFm, callback_data: 'helpLast' }, { text: Strings.animalCommands, callback_data: 'helpAnimals' }],
|
[{ text: Strings.lastFm, callback_data: 'helpLast' }, { text: Strings.animalCommands, callback_data: 'helpAnimals' }],
|
||||||
[{ text: Strings.ytDlp, callback_data: 'helpYouTube' }]
|
[{ text: Strings.ytDlp, callback_data: 'helpYouTube' }, { text: Strings.myLittlePony, callback_data: 'helpMLP' }]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -70,6 +70,10 @@ module.exports = (bot) => {
|
|||||||
await ctx.answerCbQuery();
|
await ctx.answerCbQuery();
|
||||||
await ctx.editMessageText(Strings.animalCommandsDesc, options);
|
await ctx.editMessageText(Strings.animalCommandsDesc, options);
|
||||||
break;
|
break;
|
||||||
|
case 'helpMLP':
|
||||||
|
await ctx.answerCbQuery();
|
||||||
|
await ctx.editMessageText(Strings.myLittlePonyDesc, options);
|
||||||
|
break;
|
||||||
case 'helpBack':
|
case 'helpBack':
|
||||||
await ctx.answerCbQuery();
|
await ctx.answerCbQuery();
|
||||||
await sendHelpMessage(ctx, true);
|
await sendHelpMessage(ctx, true);
|
||||||
|
152
commands/ponyapi.js
Normal file
152
commands/ponyapi.js
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
const { spawn } = require('child_process');
|
||||||
|
const { getStrings } = require('../plugins/checklang.js');
|
||||||
|
const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js');
|
||||||
|
const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch);
|
||||||
|
const axios = require("axios");
|
||||||
|
|
||||||
|
function capitalizeFirstLetter(string) {
|
||||||
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = (bot) => {
|
||||||
|
bot.command("mlp", spamwatchMiddleware, async (ctx) => {
|
||||||
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
|
|
||||||
|
ctx.reply(Strings.myLittlePonyDesc, {
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
disable_web_page_preview: true,
|
||||||
|
reply_to_message_id: ctx.message.message_id
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
bot.command("mlpchar", spamwatchMiddleware, async (ctx) => {
|
||||||
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
|
const userInput = ctx.message.text.split(' ').slice(1).join(' ');
|
||||||
|
|
||||||
|
if (!userInput) {
|
||||||
|
ctx.reply('Por favor, forneça o nome do personagem.');
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
const capitalizedInput = capitalizeFirstLetter(userInput);
|
||||||
|
const apiUrl = `https://ponyapi.net/v1/character/${capitalizedInput}`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios(apiUrl);
|
||||||
|
const charactersArray = [];
|
||||||
|
|
||||||
|
if (Array.isArray(response.data.data)) {
|
||||||
|
response.data.data.forEach(character => {
|
||||||
|
charactersArray.push({
|
||||||
|
name: character.name,
|
||||||
|
alias: character.alias ? character.alias.join(', ') : 'N/A',
|
||||||
|
url: character.url,
|
||||||
|
sex: character.sex,
|
||||||
|
residence: character.residence ? character.residence.replace(/\n/g, ' / ') : 'N/A',
|
||||||
|
occupation: character.occupation ? character.occupation.replace(/\n/g, ' / ') : 'N/A',
|
||||||
|
kind: character.kind ? character.kind.join(', ') : 'N/A',
|
||||||
|
image: character.image
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
if (charactersArray.length > 0) {
|
||||||
|
const result = Strings.ponyApiCharRes
|
||||||
|
.replace("{input}", userInput)
|
||||||
|
.replace("{name}", charactersArray[0].name)
|
||||||
|
.replace("{alias}", charactersArray[0].alias)
|
||||||
|
.replace("{url}", charactersArray[0].url)
|
||||||
|
.replace("{sex}", charactersArray[0].sex)
|
||||||
|
.replace("{residence}", charactersArray[0].residence)
|
||||||
|
.replace("{occupation}", charactersArray[0].occupation)
|
||||||
|
.replace("{kind}", charactersArray[0].kind);
|
||||||
|
|
||||||
|
ctx.replyWithPhoto(charactersArray[0].image[0], {
|
||||||
|
caption: `${result}`,
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
disable_web_page_preview: true,
|
||||||
|
reply_to_message_id: ctx.message.message_id
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
ctx.reply('Nenhum personagem encontrado.', {
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
reply_to_message_id: ctx.message.message_id
|
||||||
|
});
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
ctx.reply('Ocorreu um erro ao buscar os dados da API.', {
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
disable_web_page_preview: true,
|
||||||
|
reply_to_message_id: ctx.message.message_id
|
||||||
|
});
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
bot.command("mlpep", spamwatchMiddleware, async (ctx) => {
|
||||||
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
|
const userInput = ctx.message.text.split(' ').slice(1).join(' ');
|
||||||
|
|
||||||
|
if (!userInput) {
|
||||||
|
ctx.reply('Por favor, forneça o nome do personagem.');
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiUrl = `https://ponyapi.net/v1/comics-story/${userInput}`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios(apiUrl);
|
||||||
|
const episodeArray = [];
|
||||||
|
|
||||||
|
if (Array.isArray(response.data.data)) {
|
||||||
|
response.data.data.forEach(episode => {
|
||||||
|
episodeArray.push({
|
||||||
|
name: episode.name,
|
||||||
|
image: episode.image,
|
||||||
|
url: episode.url,
|
||||||
|
season: episode.season,
|
||||||
|
episode: episode.episode,
|
||||||
|
overall: episode.overall,
|
||||||
|
airdate: episode.airdate,
|
||||||
|
storyby: episode.storyby ? episode.storyby.replace(/\n/g, ' / ') : 'N/A',
|
||||||
|
writtenby: episode.writtenby ? episode.writtenby.replace(/\n/g, ' / ') : 'N/A',
|
||||||
|
storyboard: episode.storyboard ? episode.storyboard.replace(/\n/g, ' / ') : 'N/A',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
if (episodeArray.length > 0) {
|
||||||
|
const result = Strings.ponyApiEpRes
|
||||||
|
.replace("{input}", userInput)
|
||||||
|
.replace("{name}", episodeArray[0].name)
|
||||||
|
.replace("{url}", episodeArray[0].url)
|
||||||
|
.replace("{season}", episodeArray[0].season)
|
||||||
|
.replace("{episode}", episodeArray[0].episode)
|
||||||
|
.replace("{overall}", episodeArray[0].overall)
|
||||||
|
.replace("{airdate}", episodeArray[0].airdate)
|
||||||
|
.replace("{storyby}", episodeArray[0].storyby)
|
||||||
|
.replace("{writtenby}", episodeArray[0].writtenby)
|
||||||
|
.replace("{storyboard}", episodeArray[0].storyboard);
|
||||||
|
|
||||||
|
ctx.replyWithPhoto(episodeArray[0].image, {
|
||||||
|
caption: `${result}`,
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
disable_web_page_preview: true,
|
||||||
|
reply_to_message_id: ctx.message.message_id
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
ctx.reply('Nenhum personagem encontrado.', {
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
reply_to_message_id: ctx.message.message_id
|
||||||
|
});
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
ctx.reply('Ocorreu um erro ao buscar os dados da API.', {
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
disable_web_page_preview: true,
|
||||||
|
reply_to_message_id: ctx.message.message_id
|
||||||
|
});
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
@ -59,6 +59,8 @@
|
|||||||
"lastFmDesc": "*Last.fm*\n\n- /lt | /lmu | /last | /lfm: Shows the last song from your Last.fm profile + the number of plays.\n- /setuser `<user>`: Sets the user for the command above.",
|
"lastFmDesc": "*Last.fm*\n\n- /lt | /lmu | /last | /lfm: Shows the last song from your Last.fm profile + the number of plays.\n- /setuser `<user>`: Sets the user for the command above.",
|
||||||
"animalCommands": "Animals",
|
"animalCommands": "Animals",
|
||||||
"animalCommandsDesc": "*Animals*\n\n- /soggy `<1 | 2 | 3 | 4 | orig | thumb | sticker | alt>`: Sends the [Soggy cat meme](https://knowyourmeme.com/memes/soggy-cat)\n - /cat `<tags>`: Sends a random picture of a cat. You can specify some tags, separating each by a comma. Example: `/cat orange, cute`\n- /dog: Sends a random picture of a dog.\n- /httpcat `<http code>`: Send cat memes from http.cat with your specified HTTP code. Example: `/httpcat 404`",
|
"animalCommandsDesc": "*Animals*\n\n- /soggy `<1 | 2 | 3 | 4 | orig | thumb | sticker | alt>`: Sends the [Soggy cat meme](https://knowyourmeme.com/memes/soggy-cat)\n - /cat `<tags>`: Sends a random picture of a cat. You can specify some tags, separating each by a comma. Example: `/cat orange, cute`\n- /dog: Sends a random picture of a dog.\n- /httpcat `<http code>`: Send cat memes from http.cat with your specified HTTP code. Example: `/httpcat 404`",
|
||||||
|
"myLittlePony": "My Little Pony",
|
||||||
|
"myLittlePonyDesc": "*My Little Pony*\n\n- /mlp: Displays this help message.\n- /mlpchar `<character name>`: Shows specific information about a My Little Pony character. Example: `/mlpchar twilight`\n- /mlpep: Shows specific information about a My Little Pony episode. Example: `/mlpep 136`",
|
||||||
"goBack": "Back",
|
"goBack": "Back",
|
||||||
"maInvalidModule": "Please provide a valid module ID from The Mod Archive.\nExample: `/modarchive 81574`",
|
"maInvalidModule": "Please provide a valid module ID from The Mod Archive.\nExample: `/modarchive 81574`",
|
||||||
"maDownloadError": "Error downloading the file. Check the module ID and try again.",
|
"maDownloadError": "Error downloading the file. Check the module ID and try again.",
|
||||||
@ -81,5 +83,7 @@
|
|||||||
"httpCodeInvalid": "Please enter a valid HTTP code.",
|
"httpCodeInvalid": "Please enter a valid HTTP code.",
|
||||||
"httpCodeErr": "An error occurred while fetching the HTTP code.",
|
"httpCodeErr": "An error occurred while fetching the HTTP code.",
|
||||||
"httpCodeNotFound": "HTTP code not found.",
|
"httpCodeNotFound": "HTTP code not found.",
|
||||||
"httpCodeResult": "*HTTP Code*: {code}\n*Name*: `{message}`\n*Description*: {description}"
|
"httpCodeResult": "*HTTP Code*: {code}\n*Name*: `{message}`\n*Description*: {description}",
|
||||||
|
"ponyApiCharRes": "*MLP Character Information for* `{input}`*:*\n\n*Name:* `{name}`\n*Alias*: `{alias}`\n*Fandom URL:* [{url}]({url})\n*Sex:* `{sex}`\n*Residence:* `{residence}`\n*Occupation:* `{occupation}`\n*Kind:* `{kind}`",
|
||||||
|
"ponyApiEpRes": "*MLP Episode Information for* `{input}`*:*\n\n*Name:* `{name}`\n*Fandom URL:* [{url}]({url})\n*Season:* `{season}`\n*Episode:* `{episode}`\n*Overall Ep.:* `{overall}`\n*Release date:* `{airdate}`\n*Story by:* `{storyby}`\n*Written by:* `{writtenby}`\n*Storyboard:* `{storyboard}`"
|
||||||
}
|
}
|
@ -59,6 +59,8 @@
|
|||||||
"lastFmDesc": "*Last.fm*\n\n- /lt | /lmu | /last | /lfm: Mostra a última música do seu perfil no Last.fm + o número de reproduções.\n- /setuser `<usuário>`: Define o usuário para o comando acima.",
|
"lastFmDesc": "*Last.fm*\n\n- /lt | /lmu | /last | /lfm: Mostra a última música do seu perfil no Last.fm + o número de reproduções.\n- /setuser `<usuário>`: Define o usuário para o comando acima.",
|
||||||
"animalCommands": "Animais",
|
"animalCommands": "Animais",
|
||||||
"animalCommandsDesc": "*Animais*\n\n- /soggy `<1 | 2 | 3 | 4 | orig | thumb | sticker | alt>`: Envia o [meme do gato encharcado](https://knowyourmeme.com/memes/soggy-cat)\n- /cat `<tags>` - Envia uma foto aleatória de um gato. Você pode especificar algumas tags em inglês, separando cada uma por uma vírgula. Exemplo: `/cat orange, cute`\n- /dog - Envia uma imagem aleatória de um cachorro.\n- /httpcat `<código http>`: Envia memes de gato do http.cat com o código HTTP especificado. Exemplo: `/httpcat 404`",
|
"animalCommandsDesc": "*Animais*\n\n- /soggy `<1 | 2 | 3 | 4 | orig | thumb | sticker | alt>`: Envia o [meme do gato encharcado](https://knowyourmeme.com/memes/soggy-cat)\n- /cat `<tags>` - Envia uma foto aleatória de um gato. Você pode especificar algumas tags em inglês, separando cada uma por uma vírgula. Exemplo: `/cat orange, cute`\n- /dog - Envia uma imagem aleatória de um cachorro.\n- /httpcat `<código http>`: Envia memes de gato do http.cat com o código HTTP especificado. Exemplo: `/httpcat 404`",
|
||||||
|
"myLittlePony": "My Little Pony",
|
||||||
|
"myLittlePonyDesc": "*My Little Pony*\n\n- /mlp: Exibe esta mensagem de ajuda.\n- /mlpchar `<nome do personagem>`: Mostra informações específicas sobre um personagem de My Little Pony em inglês. Exemplo: `/mlpchar twilight`\n- /mlpep: Mostra informações específicas sobre um episódio de My Little Pony em inglês. Exemplo: `/mlpep 136`",
|
||||||
"goBack": "Voltar",
|
"goBack": "Voltar",
|
||||||
"maInvalidModule": "Por favor, forneça um ID de módulo válido do The Mod Archive.\nExemplo: `/modarchive 81574`",
|
"maInvalidModule": "Por favor, forneça um ID de módulo válido do The Mod Archive.\nExemplo: `/modarchive 81574`",
|
||||||
"maDownloadError": "Erro ao baixar o arquivo. Verifique o ID do módulo e tente novamente.",
|
"maDownloadError": "Erro ao baixar o arquivo. Verifique o ID do módulo e tente novamente.",
|
||||||
@ -81,5 +83,7 @@
|
|||||||
"httpCodeInvalid": "Por favor, insira um código HTTP válido.",
|
"httpCodeInvalid": "Por favor, insira um código HTTP válido.",
|
||||||
"httpCodeErr": "Ocorreu um erro ao buscar o código HTTP.",
|
"httpCodeErr": "Ocorreu um erro ao buscar o código HTTP.",
|
||||||
"httpCodeNotFound": "Código HTTP não encontrado.",
|
"httpCodeNotFound": "Código HTTP não encontrado.",
|
||||||
"httpCodeResult": "*Código HTTP*: `{code}`\n*Nome*: `{message}`\n*Descrição*: `{description}`"
|
"httpCodeResult": "*Código HTTP*: `{code}`\n*Nome*: `{message}`\n*Descrição*: `{description}`",
|
||||||
|
"ponyApiCharRes": "*Informações do Personagem de MLP para* `{input}`*:*\n\n*Nome:* `{name}`\n*Apelido:* `{alias}`\n*URL do Fandom:* [{url}]({url})\n*Sexo:* `{sex}`\n*Residência:* `{residence}`\n*Ocupação:* `{occupation}`\n*Tipo:* `{kind}`",
|
||||||
|
"ponyApiEpRes": "*Informações do Episódio de MLP para* `{input}`*:*\n\n*Nome:* `{name}`\n*URL do Fandom:* [{url}]({url})\n*Temporada:* `{season}`\n*Episódio:* `{episode}`\n*Episódio Geral:* `{overall}`\n*Data de Lançamento:* `{airdate}`\n*História por:* `{storyby}`\n*Escrito por:* `{writtenby}`\n*Storyboard:* `{storyboard}`"
|
||||||
}
|
}
|
@ -59,6 +59,8 @@
|
|||||||
"lastFmDesc": "*Last.fm*\n\n- /lt | /lmu | /last | /lfm: Muestra la última canción de tu perfil en Last.fm + el número de reproducciones.\n- /setuser `<usuario>`: Define el usuario para el comando anterior.",
|
"lastFmDesc": "*Last.fm*\n\n- /lt | /lmu | /last | /lfm: Muestra la última canción de tu perfil en Last.fm + el número de reproducciones.\n- /setuser `<usuario>`: Define el usuario para el comando anterior.",
|
||||||
"animalCommands": "Animales",
|
"animalCommands": "Animales",
|
||||||
"animalCommandsDesc": "*Animales*\n\n- /soggy `<1 | 2 | 3 | 4 | orig | thumb | sticker | alt>`: Envía el [meme del gato empapado](https://knowyourmeme.com/memes/soggy-cat)\n- /cat `<tags>` - Envía una foto aleatoria de un gato. Puedes especificar algunas tags en inglés, separando cada una por una coma. Ejemplo: `/cat orange, cute`\n- /dog - Envía una foto aleatoria de un perro.\n- /httpcat `<código http>`: Envía memes de gato de http.cat con tu código HTTP especificado. Ejemplo: `/httpcat 404`",
|
"animalCommandsDesc": "*Animales*\n\n- /soggy `<1 | 2 | 3 | 4 | orig | thumb | sticker | alt>`: Envía el [meme del gato empapado](https://knowyourmeme.com/memes/soggy-cat)\n- /cat `<tags>` - Envía una foto aleatoria de un gato. Puedes especificar algunas tags en inglés, separando cada una por una coma. Ejemplo: `/cat orange, cute`\n- /dog - Envía una foto aleatoria de un perro.\n- /httpcat `<código http>`: Envía memes de gato de http.cat con tu código HTTP especificado. Ejemplo: `/httpcat 404`",
|
||||||
|
"myLittlePony": "My Little Pony",
|
||||||
|
"myLittlePonyDesc": "*My Little Pony*\n\n- /mlp: Muestra este mensaje de ayuda.\n- /mlpchar `<nombre del personaje>`: Muestra información específica sobre un personaje de My Little Pony en inglés. Ejemplo: `/mlpchar twilight`\n- /mlpep: Muestra información específica sobre un episodio de My Little Pony en inglés. Ejemplo: `/mlpep 136`",
|
||||||
"goBack": "Volver",
|
"goBack": "Volver",
|
||||||
"maInvalidModule": "Por favor, proporciona un ID de módulo válido del The Mod Archive.\nEjemplo: `/modarchive 81574`",
|
"maInvalidModule": "Por favor, proporciona un ID de módulo válido del The Mod Archive.\nEjemplo: `/modarchive 81574`",
|
||||||
"maDownloadError": "Error al descargar el archivo. Verifica el ID del módulo e inténtalo de nuevo.",
|
"maDownloadError": "Error al descargar el archivo. Verifica el ID del módulo e inténtalo de nuevo.",
|
||||||
@ -81,5 +83,7 @@
|
|||||||
"httpCodeInvalid": "Por favor, ingrese un código HTTP válido.",
|
"httpCodeInvalid": "Por favor, ingrese un código HTTP válido.",
|
||||||
"httpCodeErr": "Ocurrió un error al buscar el código HTTP.",
|
"httpCodeErr": "Ocurrió un error al buscar el código HTTP.",
|
||||||
"httpCodeNotFound": "Código HTTP no encontrado.",
|
"httpCodeNotFound": "Código HTTP no encontrado.",
|
||||||
"httpCodeResult": "*Código HTTP*: {code}\n*Nombre*: `{message}`\n*Descripción*: {description}"
|
"httpCodeResult": "*Código HTTP*: {code}\n*Nombre*: `{message}`\n*Descripción*: {description}",
|
||||||
|
"ponyApiCharRes": "*Información del Personaje MLP para* `{input}`*:*\n\n*Nombre:* `{name}`\n*Alias:* `{alias}`\n*URL del Fandom:* [{url}]({url})\n*Sexo:* `{sex}`\n*Residencia:* `{residence}`\n*Ocupación:* `{occupation}`\n*Tipo:* `{kind}`",
|
||||||
|
"ponyApiEpRes": "*Información del Episodio MLP para* `{input}`*:*\n\n*Nombre:* `{name}`\n*URL del Fandom:* [{url}]({url})\n*Temporada:* `{season}`\n*Episodio:* `{episode}`\n*Episodio General:* `{overall}`\n*Fecha de Lanzamiento:* `{airdate}`\n*Historia por:* `{storyby}`\n*Escrito por:* `{writtenby}`\n*Storyboard:* `{storyboard}`"
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user