Added error handling for invalid RSS feed
This commit is contained in:
parent
fb129feb8f
commit
910c06415b
47
feed-bot.js
47
feed-bot.js
|
@ -26,27 +26,36 @@ bot.on("message", function (user, userID, channelID, message) {
|
|||
|
||||
function checkFeedAndPost() {
|
||||
//check the feed, with a callback
|
||||
FeedRead(Config.feedUrl, function (err, articles) {
|
||||
FeedRead(Config.feedUrl, function (err, articles){
|
||||
try{
|
||||
checkLinkAndPost(err, articles);
|
||||
}
|
||||
catch(ex){
|
||||
console.log("ERROR: " + (ex.message || ex));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function checkLinkAndPost(err, articles) {
|
||||
if (err) throw "Error reading RSS feed: " + (err.message || err);
|
||||
|
||||
var latestLink = articles[0].link;
|
||||
|
||||
//get the latest 100 messages (100 is the limit)
|
||||
bot.getMessages({
|
||||
channelID: Config.channelID,
|
||||
limit: 100
|
||||
}, function (err, messages) {
|
||||
if (err) throw err;
|
||||
|
||||
var latestLink = articles[0].link;
|
||||
//get an array of strings from the array of message objects
|
||||
var messageContents = messages.map((message) => { return message.content; });
|
||||
|
||||
//get the latest 100 messages (100 is the limit)
|
||||
bot.getMessages({
|
||||
channelID: Config.channelID,
|
||||
limit: 100
|
||||
}, function (err, messages) {
|
||||
if (err) throw err;
|
||||
|
||||
//get an array of strings from the array of message objects
|
||||
var messageContents = messages.map((message) => { return message.content; });
|
||||
|
||||
//if the messageContents array doesn't include the latest link, post it
|
||||
if (!messageContents.includes(latestLink))
|
||||
bot.sendMessage({
|
||||
to: Config.channelID,
|
||||
message: latestLink
|
||||
});
|
||||
});
|
||||
//if the messageContents array doesn't include the latest link, post it
|
||||
if (!messageContents.includes(latestLink))
|
||||
bot.sendMessage({
|
||||
to: Config.channelID,
|
||||
message: latestLink
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue