-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (49 loc) · 1.79 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
64
65
//Settings
var mangadex_token = "YOUR_MANGADEX_TOKEN";
var discord_webhook = "YOUR_DISCORD_WEBOOK_URL";
var discord_thumbnail = "IMAGE_URL_FOR_THUMBNAIL";
var prefix_filter = "Ijiranaide, Nagatoro-san - "; // example prefix filter
var timeout = 60;
var mysql_host = "localhost";
var mysql_user = "";
var mysql_pass = "";
var mysql_db = "mangadex";
//Imports
const feed = require('feed-read');
const mysql = require('mysql');
const { Webhook, MessageBuilder } = require("discord-webhook-node");
const hook = new Webhook(discord_webhook);
var con = mysql.createConnection({host: mysql_host, user: mysql_user, database: mysql_db });
function requestFeed() {
feed("https://mangadex.org/rss/follows/" + mangadex_token, onRssFetched);
}
function onRssFetched(err, articles) {
if(err) throw err;
con.query("SELECT * FROM announced", function (err, result) {
if(err) throw err;
var list = [];
for (i = 0; i < result.length; i++) {
if(!list.includes(result[i].title)) list.push(result[i].title);
}
for (i = 0; i < articles.length; i++) {
if(!list.includes(articles[i].title)){
list.push(articles[i].title);
con.query("INSERT INTO announced (title) VALUES ('" + articles[i].title + "')");
var filterd = articles[i].title;
filterd = filterd.replace(prefix_filter, "");
console.log("Manga " + filterd + " Has been added.");
const embed = new MessageBuilder()
.setTitle(filterd)
.setColor("#aabbcc")
.setDescription("New chapter just released!\nCheck it out in the link below:\n\n" + articles[i].link)
.setURL(articles[i].link)
.setFooter("Announcer developed by MVDW-Java on Github.")
.setThumbnail(discord_thumbnail)
.setTimestamp();
hook.send(embed);
}
}
});
}
setInterval(requestFeed, timeout * 1000);
requestFeed();