-
Notifications
You must be signed in to change notification settings - Fork 12
/
app.js
86 lines (67 loc) · 2.22 KB
/
app.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import fs from "fs-extra"
import schedule from "node-schedule"
import dotenv from "dotenv"
import bot from "./bot.js"
import moderation from "./moderation.js"
var queue = []
async function run() {
while (queue.length == 0) {
addPlatesToQueue(await moderation.process())
}
await bot.post(queue.pop())
fs.writeFileSync("./data/queue.json", JSON.stringify(queue))
moderation.updateStatus(queue.length)
await moderation.notifyQueueAmount(queue.length)
}
async function initialize() {
dotenv.config()
await moderation.initialize({
token: process.env.DISCORD_TOKEN,
channelId: process.env.DISCORD_CHANNEL_ID,
moderatorRoleId: process.env.DISCORD_MODERATOR_ROLE_ID,
ownerUserId: process.env.DISCORD_OWNER_USER_ID
})
await bot.initialize({
twitter: {
appKey: process.env.TWITTER_CONSUMER_KEY,
appSecret: process.env.TWITTER_CONSUMER_SECRET,
accessToken: process.env.TWITTER_ACCESS_TOKEN,
accessSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET
},
mastodon: {
url: process.env.MASTODON_URL,
accessToken: process.env.MASTODON_ACCESS_TOKEN
},
tumblr: {
consumerKey: process.env.TUMBLR_CONSUMER_KEY,
consumerSecret: process.env.TUMBLR_CONSUMER_SECRET,
accessToken: process.env.TUMBLR_TOKEN,
accessTokenSecret: process.env.TUMBLR_TOKEN_SECRET
},
bluesky: {
service: process.env.BLUESKY_SERVICE,
identifier: process.env.BLUESKY_IDENTIFIER,
password: process.env.BLUESKY_PASSWORD
}
})
// Hourly
schedule.scheduleJob("0 * * * *", async () => {
await run()
})
// Daily (at 0:00)
schedule.scheduleJob("0 0 * * *", async () => {
await bot.updateBio()
})
queue = JSON.parse(fs.readFileSync("./data/queue.json"))
moderation.updateStatus(queue.length)
await bot.updateBio()
}
function getQueue() {
return queue
}
function addPlatesToQueue(plates) {
queue = plates.reverse().concat(queue)
fs.writeFileSync("./data/queue.json", JSON.stringify(queue))
}
initialize()
export default { getQueue, addPlatesToQueue }