-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
34 lines (31 loc) · 1.36 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
const Discord = require("discord.js");
const client = new Discord.Client();
client.db = require("quick.db");
client.request = new (require("rss-parser"))();
client.config = require("./config.js");
client.on("ready", () => {
console.log("I'm ready!");
handleUploads();
});
function handleUploads() {
if (client.db.fetch(`postedVideos`) === null) client.db.set(`postedVideos`, []);
setInterval(() => {
client.request.parseURL(`https://www.youtube.com/feeds/videos.xml?channel_id=${client.config.channel_id}`)
.then(data => {
if (client.db.fetch(`postedVideos`).includes(data.items[0].link)) return;
else {
client.db.set(`videoData`, data.items[0]);
client.db.push("postedVideos", data.items[0].link);
let parsed = client.db.fetch(`videoData`);
let channel = client.channels.cache.get(client.config.channel);
if (!channel) return;
let message = client.config.messageTemplate
.replace(/{author}/g, parsed.author)
.replace(/{title}/g, Discord.Util.escapeMarkdown(parsed.title))
.replace(/{url}/g, parsed.link);
channel.send(message);
}
});
}, client.config.watchInterval);
}
client.login(client.config.token);