forked from LyoSU/quote-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-groups.js
30 lines (25 loc) · 817 Bytes
/
check-groups.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
require('dotenv').config({ path: './.env' })
const {
db
} = require('./database')
const Telegram = require('telegraf/telegram')
const telegram = new Telegram(process.env.BOT_TOKEN)
const checkGroup = async (group) => {
const result = await telegram.sendChatAction(group.group_id, 'typing').catch(error => {
return error.response
})
if (result) {
if (result.ok !== false) group.available.active = true
else group.available.active = false
group.available.check = true
await group.save()
}
return { group_id: group.group_id, result }
}
const checkGroups = async () => {
const groups = await db.Group.find({ 'available.check': { $ne: true } }).limit(100)
const checkArray = groups.map(checkGroup)
console.log(await Promise.all(checkArray))
await checkGroups()
}
checkGroups()