Merge pull request #6 from bluddy/master
Handle too long articles, convert html
This commit is contained in:
commit
098da23326
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"maxCacheSize": 100,
|
||||
"feedCheckInterval": 10000,
|
||||
"charLimit": 500,
|
||||
"charLimit": 1920,
|
||||
"viewFeedsPaginationLimit": 10
|
||||
}
|
|
@ -6,6 +6,7 @@ const Core = require("../../core");
|
|||
const DiscordUtil = require("../../core").util;
|
||||
const GetUrls = require("get-urls");
|
||||
const Url = require("url");
|
||||
const HtmlToText = require("html-to-text");
|
||||
|
||||
// @ts-ignore
|
||||
const readFeed = url => promisify(require("rss-parser").parseURL)(url);
|
||||
|
@ -109,10 +110,21 @@ module.exports = class FeedData extends Core.BaseEmbeddedData {
|
|||
|
||||
function formatPost(article) {
|
||||
let message = "";
|
||||
let link = "";
|
||||
let title = "";
|
||||
|
||||
if (article.title) message += `\n**${article.title}**`;
|
||||
if (article.content) message += article.content.length > Config.charLimit ? "\nArticle content too long for a single Discord message!" : `\n${article.content}`;
|
||||
if (article.link) message += `\n\n${normaliseUrlForDiscord(article.link)}`;
|
||||
if (article.title) title = `\n**${article.title}**`;
|
||||
if (article.link) link = `\n\n${normaliseUrlForDiscord(article.link)}`;
|
||||
|
||||
message += title;
|
||||
|
||||
if (article.content) {
|
||||
let maxLen = Config.charLimit - title.length - link.length - 4;
|
||||
let sanitized = HtmlToText.fromString(article.content);
|
||||
message += sanitized.length > maxLen ? `\n${sanitized.substr(0, maxLen)}...` : `\n${sanitized}`;
|
||||
}
|
||||
|
||||
message += link;
|
||||
|
||||
return message;
|
||||
}
|
||||
|
|
|
@ -8,11 +8,12 @@
|
|||
"dependencies": {
|
||||
"@types/node": "9.3.0",
|
||||
"discord.js": "11.2.0",
|
||||
"eslint": "4.16.0",
|
||||
"eslint": "4.19.1",
|
||||
"get-urls": "7.0.0",
|
||||
"jsonfile": "3.0.1",
|
||||
"rss-parser": "2.12.0",
|
||||
"shortid": "2.2.8"
|
||||
"shortid": "2.2.8",
|
||||
"html-to-text": "3.3.0"
|
||||
},
|
||||
"name": "discord-bot-rss-feed",
|
||||
"devDependencies": {},
|
||||
|
|
Loading…
Reference in New Issue