forked from rjindael/ca-dmv-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (49 loc) · 1.3 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
55
56
57
58
59
60
61
62
63
const dotenv = require("dotenv")
const discord = require("./discord")
const twitter = require("./twitter")
const dmv = require("./dmv")
dotenv.config()
dmv.initialize()
discord.initialize(process.env.DISCORD_TOKEN)
twitter.initialize({
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
access_token: process.env.TWITTER_ACCESS_TOKEN,
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
})
function verify(tweet) {
return new Promise((resolve) => {
if (tweet === false) {
resolve(false)
}
discord.verify(tweet).then((approved) => {
resolve(approved)
})
})
}
async function post() {
let tweet
let valid = false
while (!valid) {
tweet = twitter.format(await dmv.generate())
if (tweet === false) {
dmv.remove(tweet.plate)
continue
}
valid = await verify(tweet)
if (!valid) {
dmv.remove(tweet.plate)
}
}
let link = await twitter.post(tweet)
await discord.notify(link)
dmv.remove(tweet.plate)
}
var working = false
setInterval(async () => {
if (!working) {
working = true
await post()
working = false
}
}, process.env.TIMEOUT * 1000)