Browse Source

Update feed error handling

master
benji7425 3 years ago
parent
commit
20fa9d09af
  1. 33
      app/models/feed-data.js
  2. 2
      discord-bot-core/Util.js

33
app/models/feed-data.js

@ -3,7 +3,8 @@ const Camo = require("camo");
const Config = require("../config.json");
const Dns = require("dns"); //for host resolution checking
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
module.exports = class FeedData extends Camo.EmbeddedDocument {
@ -63,23 +64,21 @@ module.exports = class FeedData extends Camo.EmbeddedDocument {
}
_doFetchRSS(guild) {
FeedRead(this.url, (err, articles) => {
if (err)
return;
if (articles.length > 0 && articles[0].link) {
const latest = normaliseUrl(articles[0].link);
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}`));
FeedReadPromise(this.url + "asdf")
.then(articles => {
if (articles.length > 0 && articles[0].link) {
const latest = normaliseUrl(articles[0].link);
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));
}
};

2
discord-bot-core/Util.js

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

Loading…
Cancel
Save