hearManager.hear(/^(?:test)$/i, async (context) => {
const builder = context.pageBuilder();
limit = 50
const anime_list = [];
request.get(`https://shikimori.one/api/animes?limit=${limit}&score=5`, async function(err, response, body) {
const anime = JSON.parse(body);
for (var i = 0; i < 49; i++) {
status = ``
if(anime[i].status === 'released') { status = `вышло` }
if(anime[i].status === 'ongoing') { status = `онгоинг` }
if(anime[i].status === 'anons') { status = `анонс` }
kind = ``
if((anime[i].kind === 'tv') || (anime[i].kind === 'tv_13') || (anime[i].kind === 'tv_24') || (anime[i].kind === 'tv_48')) { kind = `TV сериал` }
if(anime[i].kind === 'movie') { kind = `кино` }
if(anime[i].kind === 'ova') { kind = `OVA` }
if(anime[i].kind === 'ona') { kind = `ONA` }
if(anime[i].kind === 'special') { kind = `спешл` }
if(anime[i].kind === 'music') { kind = `музыка` }
aired_on = ``
released = ``
if(anime[i].aired_on !== null) { released += `c ${anime[i].aired_on}` }
if(anime[i].released_on !== null) { released += ` по ${anime[i].released_on}` }
anime_list.push({
id: anime[i].id,
uid: i,
name: `${anime[i].russian} | ${anime[i].name}`,
img: `https://shikimori.one${anime[i].image.original}`,
url: `https://shikimori.one${anime[i].url}`,
kind: kind,
episodes: anime[i].episodes,
status: status,
released: released,
score: anime[i].score
})
}
try {
for (var i = 0; i < 48; i++) {
if(!photodata.find(x=> x.id === anime_list[i].id))
{
await saveImage(`./photo/${anime_list[i].id}.png`, anime_list[i].img);
const loader = await user.api.photos.getUploadServer({ album_id: 282291620, group_id: 209655789 });
request.post({
url: loader.upload_url,
formData: {
photo: fs.createReadStream(`./photo/${anime_list[i].id}.png`)
}
},
async function(err, response, body) {
const data = JSON.parse(body)
const photos = await user.api.photos.save({
album_id: data.aid,
group_id: data.gid,
server: data.server,
photos_list: data.photos_list,
hash: data.hash
})
await photodata.push({
id: anime_list[i].id,
photos: `photo${photos[0].owner_id}_${photos[0].id}`
})
})
}
}
for (var i = 0; i < 45; i++) {
photo = photodata.find(x=> x.id === anime_list[i].id)
builder.addPages({
message: `Название: ${anime_list[i].name}\nСтатус: ${anime_list[i].status} ${released}\nЭпизоды: ${anime_list[i].episodes}\nРейтинг: ${anime_list[i].score}\nТип: ${anime_list[i].kind}\nСмотреть: ${anime_list[i].url}`,
attachment: `${photo.photos}`
})
.setDefaultButtons({ buttons: ["back", "next"] })
}
return builder.build();
} catch (e) {
console.log(e)
}
})
});
vk.api.photos.getMessagesUploadServer({
peer_id: message.peerId
}).then((resp) => {
re.post({
url: resp.upload_url,
formData: {
photo: fs.createReadStream('./file.png')
}
}, function(err, response, body) {
i = JSON.parse(body)
vk.api.photos.saveMessagesPhoto({
photo: i.photo,
server: i.server,
hash: i.hash
}).then((respon) => {
console.log(respon)
})
});
})