telebot-rssfeed/config.js

83 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-07-02 20:04:32 +02:00
const fs = require('fs');
const Parser = require('rss-parser');
const parser = new Parser();
const Markup = require('telegraf/markup');
const Extra = require('telegraf/extra');
const db_js = require('./db.js');
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)));
}
const article_to_mess = function(art){
return `*${art.title.replace('\r\n','').trim()}*\n\n${art.content}\n\n[Read More](${art.link})`;
}
//=== MAIN MODULE CONFIG
const rssi = [
{
chat:'CHAT_ID',
url: 'RSS_URL',
}
];
module.exports = function(rssi){
this.rssi = rssi;
return {
name : "RSS-FEED",
key : "rssf",
version : 0.1,
requirements : {
gps : false,
},
text : [
],
reply : [],
regex : [],
media : [],
callback : [],
inline : [],
new_member : (bot,event)=>{},
weburl : [],
cron : [
{
cstr : '0 0,30 */1 * * *',
public : true,
desc: {
0: "Informs Group using RSS feed",
1: "Informe le Groupe avec le feed RSS",
4: "Informiert die Gruppe durch dem RSS feed",
},
params : [ null, true],
timezone : 'Europe/Zurich',
action : (bot)=> {
this.bot = bot;
return ()=>{
return this.rssi.forEach(entry=>
db.get_v(entry.chat).then(v=>
get_rss(entry.url,v).then(articles=>
articles.forEach(art=>
db.set_v(entry.url,parseInt(art.guid)).then(rr=>
this.bot.telegram.sendMessage(entry.chat,article_to_mess(art),{"parse_mode":"Markdown"})
)
)
)
)
)
};
}
}
]
}
}