Update feed error handling

This commit is contained in:
benji7425 2017-12-08 00:29:16 +00:00
parent da1edc57f0
commit 20fa9d09af
2 changed files with 15 additions and 16 deletions

View file

@ -3,7 +3,8 @@ const Camo = require("camo");
const Config = require("../config.json"); const Config = require("../config.json");
const Dns = require("dns"); //for host resolution checking const Dns = require("dns"); //for host resolution checking
const Url = require("url"); //for url parsing const Url = require("url"); //for url parsing
const FeedRead = require("feed-read"); //for extracing new links from RSS feeds const { promisify } = require("util");
const FeedReadPromise = promisify(require("feed-read")); //for extracing new links from RSS feeds
const GetUrls = require("get-urls"); //for extracting urls from messages const GetUrls = require("get-urls"); //for extracting urls from messages
module.exports = class FeedData extends Camo.EmbeddedDocument { module.exports = class FeedData extends Camo.EmbeddedDocument {
@ -63,23 +64,21 @@ module.exports = class FeedData extends Camo.EmbeddedDocument {
} }
_doFetchRSS(guild) { _doFetchRSS(guild) {
FeedRead(this.url, (err, articles) => { FeedReadPromise(this.url + "asdf")
if (err) .then(articles => {
return; if (articles.length > 0 && articles[0].link) {
const latest = normaliseUrl(articles[0].link);
if (articles.length > 0 && articles[0].link) { if (!this.cachedLinks.includes(latest)) {
const channel = guild.channels.get(this.channelID),
role = guild.roles.get(this.roleID);
const latest = normaliseUrl(articles[0].link); channel.send((role || "") + formatPost(articles[0]))
.catch(err => DiscordUtil.dateDebugError(`Error posting in ${channel.id}: ${err.message || err}`));
if (!this.cachedLinks.includes(latest)) { }
const channel = guild.channels.get(this.channelID),
role = guild.roles.get(this.roleID);
channel.send((role || "") + formatPost(articles[0]))
.catch(err => DiscordUtil.dateDebugError(`Error posting in ${channel.id}: ${err.message || err}`));
} }
} })
}); .catch(err => DiscordUtil.dateDebugError(`Error reading feed ${this.url}`, err));
} }
}; };

View file

@ -62,7 +62,7 @@ function formatArgs(args) {
} }
function formatArgsForFile(args) { function formatArgsForFile(args) {
return args.join("") + "\n"; return args.join(" ") + "\n";
} }
module.exports = { module.exports = {