Slimbot('');
// Register listeners
slimbot.on('message', message => {
if (message.text.startsWith("/start")) {
slimbot.sendMessage(message.chat.id, "Hello! This bot helps with finding pictures on gelbooru, try \"gelbooru [tags]\"");
}
if (message.text.startsWith("/help")) {
slimbot.sendMessage(message.chat.id, "To search pictures on gelbooru.com enter \"gelbooru [tags]\"");
};
if (message.text.startsWith("/gelbooru")) {
try {
var tags = message.text.match("/gelbooru (.*)")[1].replace(" ", "%20");
}
catch {
var tags = "";
}
https.get(`https://api.rule34.xxx/index.php?page=dapi&s=post&q=index&tags=${tags}&json=1`, (response) => {
let posts = "";
// called when a data chunk is received.
response.on("data", (chunk) => {
posts += chunk;
});
// called when the complete response is received.
response.on("end", () => {
for (post in JSON.parse(posts)) {
try {
if (post.file_url.includes("animation") || post.file_url.includes("animated") || post.file_url.includes("video") || post.file_url.includes("webm")) {
slimbot.sendVideo(message.chat.id, post.file_url, post.tags);
}
else {
slimbot.sendPhoto(message.chat.id, post.file_url, post.tags);
}
}
catch {
slimbot.sendMessage(message.chat.id, post.file_url);
}
finally {
sleep(delayTime in milliseconds).then(() => {});
}
}
});
}).on("error", (error) => {
console.log("Error: " + error.message);
});
};
});
});
// Call API
slimbot.startPolling();
Запустился, спасибо за помощь :)
Лучше на F# писать
Могу поспорить но мне лень
Обсуждают сегодня