-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (39 loc) · 1.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const Telegraf = require('telegraf');
const { Extra, Markup } = require('telegraf');
const CronJob = require('cron').CronJob;
const low = require('lowdb');
const is = require('is');
const db = low('db.json');
const app = new Telegraf(process.env.BOT_TOKEN);
new CronJob('00 8 * * *', function() {
const messages = db.get('messages')
.map('message')
.value();
const users = db.get('users')
.map('id')
.value();
users.forEach((user, key) => {
app.telegram.sendMessage(user, messages[Math.floor(Math.random() * messages.length)])
});
}, null, true, 'Europe/Kiev');
app.command('start', (ctx) => {
const { id } = ctx.message.from;
ctx.reply('В мєне є купа передбачень для тебе.',
Markup.inlineKeyboard([
Markup.callbackButton('Хочу отримувати передбачення', 'on'),
]).extra()
);
});
app.action('on', (ctx) => {
const { id } = ctx.update.callback_query.from;
if(
is.empty(
db.get('users').find({ id: id }).value())
) {
db.get('users')
.push({ id: id })
.write()
}
return ctx.answerCallbackQuery('Дякуємо :)')
})
app.startPolling()