46 lines
2.2 KiB
JavaScript
46 lines
2.2 KiB
JavaScript
/*
|
||
* Хэндлинг команды anime (сказать, что я заебался делать эту команду - это ничего не сказать, но ебать она ахуенная. Я текуу-у-ууууу)
|
||
*/
|
||
const errorHandler = require("../utils/error-handler");
|
||
const functions = require("../utils/functions");
|
||
const keyboards = require("../utils/keyboards");
|
||
const api = require("../network/api");
|
||
|
||
module.exports = bot => async (msg, match) => {
|
||
try {
|
||
if(msg.text.startsWith(`/profile`) || msg.text.startsWith(`/account`)) return;
|
||
//если команда
|
||
let animeName = match.input.replace(`/anime`, ``)
|
||
if(animeName) {
|
||
animeName = await functions.deleteSymbols(animeName)
|
||
animeName = animeName.substr(1)
|
||
if (animeName.length > 2) {
|
||
let search_result = await api.getAnimeByName(animeName);
|
||
|
||
if(!search_result || search_result == null || search_result.code == 2 || search_result.content.length == 0) {
|
||
return bot.sendMessage(msg.chat.id, `🚫 Аниме по такому запросу не были найдены!`);
|
||
}
|
||
|
||
let maxPage = Math.ceil(search_result.total_count/5)
|
||
let getButtonMenu = await functions.getButtonMenu(search_result, 1)
|
||
let text = `*🔎 Anixart Anime Lists*\n\n*Список аниме:*\n- По запросу: \`${animeName}\`\n- Всего аниме в списке: ${search_result.total_count}\n- Страница: 1/${maxPage}\n\n~~~~~~~~~~~~~~~~~~\n`
|
||
text += getButtonMenu.text
|
||
|
||
return bot.sendMessage(msg.chat.id, text, {
|
||
parse_mode: 'Markdown',
|
||
reply_markup: await keyboards.searchAnime(msg.from.id, maxPage, 1, getButtonMenu.animeList, animeName)
|
||
});
|
||
} else {
|
||
return bot.sendMessage(msg.chat.id, `🚫 Название должно состоять минимум из 3 символов`);
|
||
}
|
||
}
|
||
|
||
const opts = { //Опции (клавиатура и т.д.)
|
||
parse_mode: 'Markdown', //Форматирование текста
|
||
reply_markup: await keyboards.animeMenu(msg.from.id)
|
||
};
|
||
bot.sendMessage(msg.chat.id, await functions.genAnimeMenuText(), opts);
|
||
} catch (error) {
|
||
errorHandler(bot, msg.chat.id, error);
|
||
}
|
||
}; |