From cfb9d7fd3582f1591dda44bf5bfdc61bca76c410 Mon Sep 17 00:00:00 2001 From: Cedric Hoelzl Date: Fri, 3 Jul 2020 11:19:19 +0200 Subject: [PATCH] fixing order --- config.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/config.js b/config.js index 9266497..9236600 100644 --- a/config.js +++ b/config.js @@ -13,9 +13,11 @@ var db = new db_js("rss_chan"); //=== TOOL FUNCTIONS const get_rss = function(url,min_id){ - return parser.parseURL(url).then(feed=>feed.items - .sort((a, b)=>(parseInt(a.guid)-parseInt(b.guid))) - .filter((v)=>(parseInt(v.guid)>min_id))); + return parser.parseURL(url).then(feed=>{ + let idx = feed.findIndex(i => i.prop_1 === min_id); + if(idx>=0) return feed.items.slice(0,idx); + else return feed.items; + }); } const article_to_mess = function(art){ @@ -58,11 +60,11 @@ module.exports = function(rssi){ return Promise.all(this.rssi.map(entry=> db.get_v(entry.chat).then(v=> get_rss(entry.url,v).then(articles=> - articles.forEach(art=> - db.set_v(entry.chat,parseInt(art.guid)).then(rr=> - this.bot.telegram.sendMessage(entry.chat,article_to_mess(art),{"parse_mode":"Markdown"}) - ) - ) + Promise.all(articles.map(art=> + this.bot.telegram.sendMessage(entry.chat,article_to_mess(art),{"parse_mode":"Markdown"}) + )).then(rr=> + db.set_v(entry.chat,parseInt(articles.pop().guid)) + ) ) ) )).then(r=>event.reply("Refreshed all Feeds")); @@ -93,11 +95,11 @@ module.exports = function(rssi){ return Promise.all(this.rssi.map(entry=> db.get_v(entry.chat).then(v=> get_rss(entry.url,v).then(articles=> - articles.forEach(art=> - db.set_v(entry.chat,parseInt(art.guid)).then(rr=> - this.bot.telegram.sendMessage(entry.chat,article_to_mess(art),{"parse_mode":"Markdown"}) - ) - ) + Promise.all(articles.map(art=> + this.bot.telegram.sendMessage(entry.chat,article_to_mess(art),{"parse_mode":"Markdown"}) + )).then(rr=> + db.set_v(entry.chat,parseInt(articles.pop().guid)) + ) ) ) ));