telebot-rssfeed/config.js
2020-07-02 20:32:54 +02:00

109 lines
2.4 KiB
JavaScript

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_ex = [
{
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 : [
{
trigger : ["/refresh"],
public : false,
desc : {
0: "Force refresh the feeds",
},
requirements : (bot,event,message)=>{
return new Promise((resolve, reject)=>{
if(event.from && bot.admin.indexOf(event.from.id) == -1)
return reject(403);
return resolve(200);
});
},
action : (bot,event,message)=>{
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"})
)
)
)
)
)
}
}
],
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"})
)
)
)
)
)
};
}
}
]
}
}