-
Notifications
You must be signed in to change notification settings - Fork 14
/
dispatcher-discord.js
48 lines (42 loc) · 1.52 KB
/
dispatcher-discord.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
require('dotenv').config()
const {
loadData,
updateData,
} = require('./util')
const webhook = require("webhook-discord")
const webhookURL = process.env.DC_WEBHOOK_URL;
const Hook = new webhook.Webhook(webhookURL)
const metadataStory = loadData("./metadata-story.json");
metadataStory
.map(story => {
if (story.send_discord) return
if (story.mediaType == 1) { // Image
const msg = new webhook.MessageBuilder()
.setName("SnapgramLord")
.setColor("#aabbcc")
.setImage(story.url)
.setDescription(
`Timestamp : ${story.timestamp}\n`
)
Hook.send(msg)
.then((data) => {
updateData("./metadata-story.json", story.id, true, "discord")
}).catch((error) => {
console.log("failed to send: " + story.id)
})
} else if (story.mediaType == 2) { // Videos
const msg = new webhook.MessageBuilder()
.setName("SnapgramLord")
.setColor("#aabbcc")
.setURL(story.url)
.setDescription(
`Timestamp : ${story.timestamp}\n`
)
Hook.send(msg)
.then((data) => {
updateData("./metadata-story.json", story.id, true, "discord")
}).catch((error) => {
console.log("failed to send: " + story.id)
})
}
})