-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (46 loc) · 1.27 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
53
54
require("dotenv").config()
const playScraper = require("google-play-scraper")
const TelegramBot = require("node-telegram-bot-api")
const path = require("path")
const jsonfile = require("jsonfile")
const { promisify } = require("util")
const DATAFILE = path.resolve("./data.json")
const readJson = async (file = DATAFILE) => promisify(jsonfile.readFile)(file)
const writeJson = async (data, file = DATAFILE) =>
promisify(jsonfile.writeFile)(file, data)
const bot = new TelegramBot(process.env.BOT_TOKEN, { polling: true })
const TARGET_GROUP = "-1001146414818"
const getCurrentVersion = async () => {
const data = await playScraper.app({
appId: "com.tellm.android.app",
cache: false
})
return data.version
}
async function run() {
let data
try {
data = await readJson()
} catch (e) {
data = {
version: "",
lastChecked: 0
}
writeJson(data)
}
try {
let playVersion = await getCurrentVersion()
if (data.version !== playVersion) {
data.version = playVersion
await bot.sendMessage(
TARGET_GROUP,
`Jodel version ${playVersion} is now on Play Store`
)
}
data.lastChecked = Date.now()
await writeJson(data)
} catch (error) {
console.error(error)
}
}
run().then(()=>{process.exit(0)})