-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
79 lines (70 loc) · 2.89 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const dotenv = require('dotenv');
dotenv.config();
const { Client, GatewayIntentBits } = require('discord.js'),
discordClient = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.MessageContent ]}),
messageHandler = require('./messageHandler.js'),
RssFeedEmitter = require('rss-feed-emitter'),
settings = {
botId : "", //LISTED IN DISCORD AS APPLICATION ID
botName : "Elihu's RSS Bot",
discordToken : process.env.DISCORD_TOKEN,
guildID : process.env.GUILD_ID,
guildChannel : process.env.GUILD_CHANNEL_ID,
messageColor : "#bb0000",
refreshInterval : 30000, //IN MS - FOR MORE INFO SEE https://github.com/filipedeschamps/rss-feed-emitter
//WARNING - POLLING TOO OFTEN MAY LEAD TO YOU BEING BLOCKED FROM SOME SITES/SERVICES.
}
// START'ER UP
discordClient.login(settings.discordToken)
discordClient.on('ready', () => {
console.log(`Logged into Discord as ${settings.botName}`);
rssListener1(
{
img: "https://i.picsum.photos/id/237/200/300.jpg?hmac=TmmQSbShHz9CdQm0NkEjx1Dyh_Y984R9LpNrpvH2D_U",
url: 'https://lorem-rss.herokuapp.com/feed'
}
)
// DUPLICATE RSS FEED SETUP, READY FOR YOUR USE
// rssListener2(
// {
// img: "https://i.picsum.photos/id/1012/3973/2639.jpg?hmac=s2eybz51lnKy2ZHkE2wsgc6S81fVD1W2NKYOSh8bzDc",
// url: 'https://lorem-rss.herokuapp.com/feed'
// }
// )
});
// RSS FEED
const rssListener1 = (rssData) => {
let getRSS = new RssFeedEmitter({ skipFirstLoad: true })
console.log("Listening for RSS Updates!")
getRSS.add({
url: rssData.url,
refresh: settings.refreshInterval
});
getRSS.on('new-item', item => {
let postDetails = {
date : item.date.toDateString(),
img : rssData.img,
link : item.link,
title : item.title
}
messageHandler.discordMessage(discordClient, postDetails, settings)
})
};
// DUPLICATE RSS FEED SETUP, READY FOR YOUR USE
// const rssListener2 = (rssData) => {
// let getRSS = new RssFeedEmitter({ skipFirstLoad: true })
// console.log("Listening for RSS Updates on feed two!")
// getRSS.add({
// url: rssData.url,
// refresh: settings.refreshInterval
// });
// getRSS.on('new-item', item => {
// let mappedItem = {
// date : item.date.toDateString(),
// img : rssData.img,
// link : item.link,
// title : item.title
// }
// messageHandler.discordMessage(mappedItem)
// })
// };