fixing order

This commit is contained in:
Cedric Hoelzl 2020-07-03 11:19:19 +02:00
parent 0411a48371
commit cfb9d7fd35

View File

@ -13,9 +13,11 @@ var db = new db_js("rss_chan");
//=== TOOL FUNCTIONS //=== TOOL FUNCTIONS
const get_rss = function(url,min_id){ const get_rss = function(url,min_id){
return parser.parseURL(url).then(feed=>feed.items return parser.parseURL(url).then(feed=>{
.sort((a, b)=>(parseInt(a.guid)-parseInt(b.guid))) let idx = feed.findIndex(i => i.prop_1 === min_id);
.filter((v)=>(parseInt(v.guid)>min_id))); if(idx>=0) return feed.items.slice(0,idx);
else return feed.items;
});
} }
const article_to_mess = function(art){ const article_to_mess = function(art){
@ -58,10 +60,10 @@ module.exports = function(rssi){
return Promise.all(this.rssi.map(entry=> return Promise.all(this.rssi.map(entry=>
db.get_v(entry.chat).then(v=> db.get_v(entry.chat).then(v=>
get_rss(entry.url,v).then(articles=> get_rss(entry.url,v).then(articles=>
articles.forEach(art=> Promise.all(articles.map(art=>
db.set_v(entry.chat,parseInt(art.guid)).then(rr=>
this.bot.telegram.sendMessage(entry.chat,article_to_mess(art),{"parse_mode":"Markdown"}) this.bot.telegram.sendMessage(entry.chat,article_to_mess(art),{"parse_mode":"Markdown"})
) )).then(rr=>
db.set_v(entry.chat,parseInt(articles.pop().guid))
) )
) )
) )
@ -93,10 +95,10 @@ module.exports = function(rssi){
return Promise.all(this.rssi.map(entry=> return Promise.all(this.rssi.map(entry=>
db.get_v(entry.chat).then(v=> db.get_v(entry.chat).then(v=>
get_rss(entry.url,v).then(articles=> get_rss(entry.url,v).then(articles=>
articles.forEach(art=> Promise.all(articles.map(art=>
db.set_v(entry.chat,parseInt(art.guid)).then(rr=>
this.bot.telegram.sendMessage(entry.chat,article_to_mess(art),{"parse_mode":"Markdown"}) this.bot.telegram.sendMessage(entry.chat,article_to_mess(art),{"parse_mode":"Markdown"})
) )).then(rr=>
db.set_v(entry.chat,parseInt(articles.pop().guid))
) )
) )
) )