Skip to content

Instantly share code, notes, and snippets.

@Holovin
Last active February 3, 2021 20:43
Show Gist options
  • Save Holovin/ed34ad092dc3bf15f7b1e4c87da0c6c6 to your computer and use it in GitHub Desktop.
Save Holovin/ed34ad092dc3bf15f7b1e4c87da0c6c6 to your computer and use it in GitHub Desktop.
// For use:
// 1) npm i telegraf got
// 2) replace TELEGRAM_BOT_TOKEN / YOUTUBE_TOKEN_API / YOUTUBE_VIDEO_ID / GROUP
const { Telegraf } = require('telegraf');
const got = require('got');
const URL = 'https://www.googleapis.com/youtube/v3/videos?id=YOUTUBE_VIDEO_ID&key=YOUTUBE_TOKEN_API&part=statistics';
const GROUP = -0; // telegram group ip, start with -, yes
const TOKEN = 'TELEGRAM_BOT_TOKEN';
async function main() {
const bot = new Telegraf(TOKEN);
let maxViews = 0;
do {
const ytJson = await got.get(URL).json();
const views = (ytJson.items && ytJson.items[0] && ytJson.items[0].statistics && ytJson.items[0].statistics.viewCount) || 0;
if (views) {
if (Math.floor(views / 1_000_000) > Math.floor(maxViews / 1_000_000)) {
maxViews = views;
await bot.telegram.sendMessage(GROUP, `Просмотры: ${views.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' ')}`);
}
}
else {
await bot.telegram.sendMessage(GROUP, `Оу-оу сломался :(`);
break;
}
await new Promise(resolve => setTimeout(resolve, 5 * 60 * 1000));
} while (true);
await bot.telegram.sendMessage(GROUP, `[выключился]`);
}
(async () => {
await main();
})();
process.once('SIGINT', () => bot.stop('SIGINT'));
process.once('SIGTERM', () => bot.stop('SIGTERM'));
@Cloddy
Copy link

Cloddy commented Jan 21, 2021

уважаю братка, но Лёха сломаться не может, ауф 😈😈👊🏻🤜🏻🤛🏻 ☝🏻☝🏻☝🏻

@crashmax-dev
Copy link

Вопрос, нахуя и нахуя?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment