dos2unix
This commit is contained in:
parent
da6d35b2e7
commit
0b8719e262
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"clientID": "701077243652341762",
|
"clientID": "701077243652341762",
|
||||||
"token": "NzAxMDc3MjQzNjUyMzQxNzYy.XpsPmw.luwV8qmRlYwibpA3hzT9SnN5mvk",
|
"token": "NzAxMDc3MjQzNjUyMzQxNzYy.XpsPmw.luwV8qmRlYwibpA3hzT9SnN5mvk",
|
||||||
"secret": "oxiy0FoaI2e4ni0lkK6B9yqaS5IOJ2e1"
|
"secret": "oxiy0FoaI2e4ni0lkK6B9yqaS5IOJ2e1"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
{
|
{
|
||||||
"discordBot": {},
|
"discordBot": {},
|
||||||
"rss-youtube": {
|
"rss-youtube": {
|
||||||
"discord": {
|
"discord": {
|
||||||
"channel": "701093105864147024",
|
"channel": "701093105864147024",
|
||||||
"color": "#FF0000",
|
"color": "#FF0000",
|
||||||
"style": "tinyEmbed",
|
"style": "tinyEmbed",
|
||||||
"footer": {
|
"footer": {
|
||||||
"text": "vidéo Youtube",
|
"text": "vidéo Youtube",
|
||||||
"icon_url": "https://data.kataku.in/cdn/youtube_social.png"
|
"icon_url": "https://data.kataku.in/cdn/youtube_social.png"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"rss-skeptikon": {
|
"rss-skeptikon": {
|
||||||
"discord": {
|
"discord": {
|
||||||
"channel": "701093136713252925",
|
"channel": "701093136713252925",
|
||||||
"color": "#F1680D",
|
"color": "#F1680D",
|
||||||
"style": "embed",
|
"style": "embed",
|
||||||
"footer": {
|
"footer": {
|
||||||
"text": "vidéo Peertube",
|
"text": "vidéo Peertube",
|
||||||
"icon_url": "https://data.kataku.in/cdn/skeptikon_social.png"
|
"icon_url": "https://data.kataku.in/cdn/skeptikon_social.png"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
{
|
{
|
||||||
"services" : [
|
"services" : [
|
||||||
"logs",
|
"logs",
|
||||||
"discord",
|
"discord",
|
||||||
"rss-skeptikon",
|
"rss-skeptikon",
|
||||||
"rss-youtube"
|
"rss-youtube"
|
||||||
],
|
],
|
||||||
"pm2": {
|
"pm2": {
|
||||||
"prefix": "skp_",
|
"prefix": "skp_",
|
||||||
"mode": "cluster"
|
"mode": "cluster"
|
||||||
},
|
},
|
||||||
"logs": {
|
"logs": {
|
||||||
"path": "./logs"
|
"path": "./logs"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,41 +1,41 @@
|
||||||
/*
|
/*
|
||||||
SkeptCOM [Discord] | Pour envoyer des notifications sur un serveur Discord
|
SkeptCOM [Discord] | Pour envoyer des notifications sur un serveur Discord
|
||||||
*/
|
*/
|
||||||
// LOAD configFiles
|
// LOAD configFiles
|
||||||
const discordConf = require('../conf/discord.json')
|
const discordConf = require('../conf/discord.json')
|
||||||
const routage = require('../modules/routage')('discordBot')
|
const routage = require('../modules/routage')('discordBot')
|
||||||
|
|
||||||
// REQUIRE, CONST, VARIABLES
|
// REQUIRE, CONST, VARIABLES
|
||||||
const Discord = require('discord.js')
|
const Discord = require('discord.js')
|
||||||
const client = new Discord.Client()
|
const client = new Discord.Client()
|
||||||
|
|
||||||
|
|
||||||
// FUNCTIONS
|
// FUNCTIONS
|
||||||
const myDiscord = {
|
const myDiscord = {
|
||||||
send: function() {}
|
send: function() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// INIT
|
// INIT
|
||||||
client.on('ready', () => {
|
client.on('ready', () => {
|
||||||
console.log(` --- [Discord] Logged in as ${client.user.tag}!`)
|
console.log(` --- [Discord] Logged in as ${client.user.tag}!`)
|
||||||
routage.send(` --- [Discord] Logged in as ${client.user.tag}!`)
|
routage.send(` --- [Discord] Logged in as ${client.user.tag}!`)
|
||||||
|
|
||||||
myDiscord.send = (channel, msg) => {
|
myDiscord.send = (channel, msg) => {
|
||||||
client.channels.fetch(channel)
|
client.channels.fetch(channel)
|
||||||
.then(channel => channel.send(msg))
|
.then(channel => channel.send(msg))
|
||||||
.catch(console.error)
|
.catch(console.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// client.on('message', message => {
|
// client.on('message', message => {
|
||||||
// if (message.content.startsWith('!ping')) {
|
// if (message.content.startsWith('!ping')) {
|
||||||
// console.log(`on a un ping`)
|
// console.log(`on a un ping`)
|
||||||
// routage.send(message.content)
|
// routage.send(message.content)
|
||||||
// }
|
// }
|
||||||
// })
|
// })
|
||||||
|
|
||||||
|
|
||||||
client.login(discordConf.token)
|
client.login(discordConf.token)
|
||||||
|
|
||||||
module.exports = myDiscord
|
module.exports = myDiscord
|
||||||
|
|
|
@ -1,30 +1,30 @@
|
||||||
/*
|
/*
|
||||||
SkeptCOM [IO] | Via un json, on va rediriger qui envoye a quoi
|
SkeptCOM [IO] | Via un json, on va rediriger qui envoye a quoi
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const routes = require('../conf/routes.json')
|
const routes = require('../conf/routes.json')
|
||||||
const skepticonf = require('../conf/skepticom.json')
|
const skepticonf = require('../conf/skepticom.json')
|
||||||
const services = {}
|
const services = {}
|
||||||
|
|
||||||
module.exports = (who) => {
|
module.exports = (who) => {
|
||||||
|
|
||||||
if (!who || !routes[who]) return console.error(`ERROR routage`)
|
if (!who || !routes[who]) return console.error(`ERROR routage`)
|
||||||
|
|
||||||
services[who] = require('./skeptIO')(who)
|
services[who] = require('./skeptIO')(who)
|
||||||
|
|
||||||
function send(data) {
|
function send(data) {
|
||||||
services[who].send('logs', '', data)
|
services[who].send('logs', '', data)
|
||||||
for (let i in routes[who]) {
|
for (let i in routes[who]) {
|
||||||
services[who].send(i, routes[who][i], data)
|
services[who].send(i, routes[who][i], data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function log(data) {
|
function log(data) {
|
||||||
services[who].send('logs', '', data)
|
services[who].send('logs', '', data)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
send,
|
send,
|
||||||
log
|
log
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,40 +1,40 @@
|
||||||
/*
|
/*
|
||||||
SkeptIO | Gestionnaire des services
|
SkeptIO | Gestionnaire des services
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const pm2 = require('pm2')
|
const pm2 = require('pm2')
|
||||||
|
|
||||||
module.exports = (who) => {
|
module.exports = (who) => {
|
||||||
|
|
||||||
function sendMSG(to, conf, data) {
|
function sendMSG(to, conf, data) {
|
||||||
if (!who) return console.error(`ERROR skeptIO ${to}`)
|
if (!who) return console.error(`ERROR skeptIO ${to}`)
|
||||||
|
|
||||||
let dataMSG = {
|
let dataMSG = {
|
||||||
topic: to,
|
topic: to,
|
||||||
from: 'skp_' + who,
|
from: 'skp_' + who,
|
||||||
conf,
|
conf,
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
|
|
||||||
pm2.list( (err, list) => { // on check la liste des process pm2
|
pm2.list( (err, list) => { // on check la liste des process pm2
|
||||||
for (let i in list) {
|
for (let i in list) {
|
||||||
if (list[i].name === 'skp_' + to) { // on verif que le process exite bien
|
if (list[i].name === 'skp_' + to) { // on verif que le process exite bien
|
||||||
pm2.sendDataToProcessId(list[i].pm_id, dataMSG, (err, res) => { // et on send
|
pm2.sendDataToProcessId(list[i].pm_id, dataMSG, (err, res) => { // et on send
|
||||||
if (err) return console.error(` <-- [${list[i].pm_id}:${list[i].name}] error`, err)
|
if (err) return console.error(` <-- [${list[i].pm_id}:${list[i].name}] error`, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function receiveMSG(res) {
|
function receiveMSG(res) {
|
||||||
process.on('message', data => {
|
process.on('message', data => {
|
||||||
res(data)
|
res(data)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
send: sendMSG,
|
send: sendMSG,
|
||||||
receive: receiveMSG
|
receive: receiveMSG
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,54 +1,54 @@
|
||||||
/*
|
/*
|
||||||
SkeptCOM [Discord] | Pour envoyer des notifications sur un serveur Discord
|
SkeptCOM [Discord] | Pour envoyer des notifications sur un serveur Discord
|
||||||
|
|
||||||
exemple pour injecter depuis un routage :
|
exemple pour injecter depuis un routage :
|
||||||
routage.send({
|
routage.send({
|
||||||
author: "",
|
author: "",
|
||||||
title: "",
|
title: "",
|
||||||
url : "",
|
url : "",
|
||||||
image: "",
|
image: "",
|
||||||
desc: ""
|
desc: ""
|
||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// REQUIRE, CONST, VARIABLES
|
// REQUIRE, CONST, VARIABLES
|
||||||
const discordBot = require('../modules/discordBot')
|
const discordBot = require('../modules/discordBot')
|
||||||
const skeptIO = require('../modules/skeptIO')('discord')
|
const skeptIO = require('../modules/skeptIO')('discord')
|
||||||
|
|
||||||
function embed(conf, data) {
|
function embed(conf, data) {
|
||||||
return {
|
return {
|
||||||
embed: {
|
embed: {
|
||||||
color: conf.color,
|
color: conf.color,
|
||||||
author: {name: data.author},
|
author: {name: data.author},
|
||||||
title: data.title,
|
title: data.title,
|
||||||
url: data.url,
|
url: data.url,
|
||||||
image: {url: data.image },
|
image: {url: data.image },
|
||||||
description: data.desc,
|
description: data.desc,
|
||||||
footer: conf.footer
|
footer: conf.footer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function tinyEmbed(conf, data) {
|
function tinyEmbed(conf, data) {
|
||||||
return {
|
return {
|
||||||
embed: {
|
embed: {
|
||||||
color: conf.color,
|
color: conf.color,
|
||||||
author: {name: data.author},
|
author: {name: data.author},
|
||||||
title: data.title,
|
title: data.title,
|
||||||
url: data.url,
|
url: data.url,
|
||||||
thumbnail: {url: data.image},
|
thumbnail: {url: data.image},
|
||||||
description: data.desc,
|
description: data.desc,
|
||||||
footer: conf.footer
|
footer: conf.footer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// INIT
|
// INIT
|
||||||
skeptIO.receive( obj => {
|
skeptIO.receive( obj => {
|
||||||
console.log(` --> [Discord] message from [${obj.from}]`)
|
console.log(` --> [Discord] message from [${obj.from}]`)
|
||||||
|
|
||||||
if (obj.conf.style === "msg") discordBot.send(obj.conf.channel, obj.data.desc)
|
if (obj.conf.style === "msg") discordBot.send(obj.conf.channel, obj.data.desc)
|
||||||
if (obj.conf.style === "embed") discordBot.send(obj.conf.channel, embed(obj.conf, obj.data))
|
if (obj.conf.style === "embed") discordBot.send(obj.conf.channel, embed(obj.conf, obj.data))
|
||||||
if (obj.conf.style === "tinyEmbed") discordBot.send(obj.conf.channel, tinyEmbed(obj.conf, obj.data))
|
if (obj.conf.style === "tinyEmbed") discordBot.send(obj.conf.channel, tinyEmbed(obj.conf, obj.data))
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,35 +1,35 @@
|
||||||
/*
|
/*
|
||||||
SkeptCOM [logs] | on va log les choses, c'est mieux quand on a un problème ... 'fin, les gens bons le fond souvent ♥
|
SkeptCOM [logs] | on va log les choses, c'est mieux quand on a un problème ... 'fin, les gens bons le fond souvent ♥
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// REQUIRE, CONST, VARIABLES
|
// REQUIRE, CONST, VARIABLES
|
||||||
const dateFormat = require('dateformat')
|
const dateFormat = require('dateformat')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const fse = require('fs-extra')
|
const fse = require('fs-extra')
|
||||||
const colors = require('colors')
|
const colors = require('colors')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
const skepticonf = require('../conf/skepticom.json')
|
const skepticonf = require('../conf/skepticom.json')
|
||||||
const skeptIO = require('../modules/skeptIO')('logs')
|
const skeptIO = require('../modules/skeptIO')('logs')
|
||||||
const logConf = {}
|
const logConf = {}
|
||||||
|
|
||||||
// INIT
|
// INIT
|
||||||
if (!skepticonf.logs) return console.log(` [ERROR || LOGS] no configuration for logs.js in ./conf/skepticom.json`)
|
if (!skepticonf.logs) return console.log(` [ERROR || LOGS] no configuration for logs.js in ./conf/skepticom.json`)
|
||||||
if (skepticonf.logs.path) {
|
if (skepticonf.logs.path) {
|
||||||
logConf.path = path.resolve(skepticonf.logs.path)
|
logConf.path = path.resolve(skepticonf.logs.path)
|
||||||
} else {
|
} else {
|
||||||
logConf.path = path.resolve('./_logs')
|
logConf.path = path.resolve('./_logs')
|
||||||
}
|
}
|
||||||
fse.ensureDirSync(logConf.path)
|
fse.ensureDirSync(logConf.path)
|
||||||
|
|
||||||
skeptIO.receive( obj => {
|
skeptIO.receive( obj => {
|
||||||
let rtn = `[${dateFormat("yyyy-mm-dd HH:MM")}] ${obj.from.replace(skepticonf.pm2.prefix, '')}\n ${JSON.stringify(obj.data)}`
|
let rtn = `[${dateFormat("yyyy-mm-dd HH:MM")}] ${obj.from.replace(skepticonf.pm2.prefix, '')}\n ${JSON.stringify(obj.data)}`
|
||||||
|
|
||||||
console.log(rtn.magenta)
|
console.log(rtn.magenta)
|
||||||
fs.appendFile(logConf.path + '/' + dateFormat("yyyy-W") + '.log', rtn + '\n', 'utf8', function(err) {
|
fs.appendFile(logConf.path + '/' + dateFormat("yyyy-W") + '.log', rtn + '\n', 'utf8', function(err) {
|
||||||
if (err) return console.error(err)
|
if (err) return console.error(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(` --- [LOGS] Load`)
|
console.log(` --- [LOGS] Load`)
|
||||||
|
|
|
@ -1,87 +1,87 @@
|
||||||
/*
|
/*
|
||||||
SkeptCOM [RSS-Youtube] | Détecte les nouvelles vidéos YT via RSS
|
SkeptCOM [RSS-Youtube] | Détecte les nouvelles vidéos YT via RSS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// REQUIRE, CONST, VARIABLES
|
// REQUIRE, CONST, VARIABLES
|
||||||
const jsonfile = require('jsonfile')
|
const jsonfile = require('jsonfile')
|
||||||
const Parser = require('rss-parser')
|
const Parser = require('rss-parser')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
const routage = require('../modules/routage')('rss-skeptikon')
|
const routage = require('../modules/routage')('rss-skeptikon')
|
||||||
let parser = new Parser({
|
let parser = new Parser({
|
||||||
headers: {
|
headers: {
|
||||||
Accept: 'application/rss+xml, application/xml',
|
Accept: 'application/rss+xml, application/xml',
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const db = require('../db/rss-skeptikon.json')
|
const db = require('../db/rss-skeptikon.json')
|
||||||
|
|
||||||
// FUNCTIONS
|
// FUNCTIONS
|
||||||
// et on output ! YOLO !
|
// et on output ! YOLO !
|
||||||
function output(data) {
|
function output(data) {
|
||||||
console.log(` --> [RSS-Skeptikon | NV] ${data.author} | ${data.title}`)
|
console.log(` --> [RSS-Skeptikon | NV] ${data.author} | ${data.title}`)
|
||||||
if (routage && routage.send) routage.send(data)
|
if (routage && routage.send) routage.send(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// bon, on a besoin de recup le RSS, normol
|
// bon, on a besoin de recup le RSS, normol
|
||||||
async function getFeed(url) {
|
async function getFeed(url) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
parser.parseURL(url, (err, res) => {
|
parser.parseURL(url, (err, res) => {
|
||||||
if (err) return reject(err)
|
if (err) return reject(err)
|
||||||
resolve(res)
|
resolve(res)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// on filtre un peu, puis en fonction on output
|
// on filtre un peu, puis en fonction on output
|
||||||
async function parseRSS(feed) {
|
async function parseRSS(feed) {
|
||||||
|
|
||||||
for (let n in feed.items) {
|
for (let n in feed.items) {
|
||||||
let i = feed.items.length-n-1 // on check en décroissant
|
let i = feed.items.length-n-1 // on check en décroissant
|
||||||
if (feed.items[i].isoDate > db.lastCheck || feed.items[i].isoDate > db.latest) {
|
if (feed.items[i].isoDate > db.lastCheck || feed.items[i].isoDate > db.latest) {
|
||||||
db.latest = feed.items[i].isoDate
|
db.latest = feed.items[i].isoDate
|
||||||
let id = feed.items[i].link.split('/')[feed.items[i].link.split('/').length-1]
|
let id = feed.items[i].link.split('/')[feed.items[i].link.split('/').length-1]
|
||||||
let c = {
|
let c = {
|
||||||
author: feed.items[i].creator,
|
author: feed.items[i].creator,
|
||||||
title: feed.items[i].title,
|
title: feed.items[i].title,
|
||||||
url: feed.items[i].link,
|
url: feed.items[i].link,
|
||||||
id: id,
|
id: id,
|
||||||
image: "https://skeptikon.fr/static/previews/" + id + ".jpg",
|
image: "https://skeptikon.fr/static/previews/" + id + ".jpg",
|
||||||
desc: feed.items[i].content.slice(0, db.config.sliceDescription) + " [...]",
|
desc: feed.items[i].content.slice(0, db.config.sliceDescription) + " [...]",
|
||||||
isoDate: feed.items[i].isoDate
|
isoDate: feed.items[i].isoDate
|
||||||
}
|
}
|
||||||
output(c)
|
output(c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// on check l'ensemble de feeds
|
// on check l'ensemble de feeds
|
||||||
async function checkFeeds(feeds) {
|
async function checkFeeds(feeds) {
|
||||||
console.log(` --- [RSS-Skeptikon] check @${db.lastCheck}`)
|
console.log(` --- [RSS-Skeptikon] check @${db.lastCheck}`)
|
||||||
routage.log(`check @${db.lastCheck}`)
|
routage.log(`check @${db.lastCheck}`)
|
||||||
|
|
||||||
let feed = await getFeed(feeds)
|
let feed = await getFeed(feeds)
|
||||||
await parseRSS(feed)
|
await parseRSS(feed)
|
||||||
|
|
||||||
let dateObj = new Date()
|
let dateObj = new Date()
|
||||||
db.lastCheck = dateObj.toISOString()
|
db.lastCheck = dateObj.toISOString()
|
||||||
|
|
||||||
// et on externalise la nouvelle date. Youpi !
|
// et on externalise la nouvelle date. Youpi !
|
||||||
jsonfile.writeFile(path.resolve('./db/rss-skeptikon.json'), db, {spaces: 2}, (err) => {
|
jsonfile.writeFile(path.resolve('./db/rss-skeptikon.json'), db, {spaces: 2}, (err) => {
|
||||||
if (err) console.error(err)
|
if (err) console.error(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function rssLoop(time) {
|
function rssLoop(time) {
|
||||||
checkFeeds(db.config.urlFeeds)
|
checkFeeds(db.config.urlFeeds)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
rssLoop(time)
|
rssLoop(time)
|
||||||
}, time)
|
}, time)
|
||||||
}
|
}
|
||||||
|
|
||||||
// INIT
|
// INIT
|
||||||
console.log(` --- [RSS-Skeptikon] Load`)
|
console.log(` --- [RSS-Skeptikon] Load`)
|
||||||
routage.log(`Load`)
|
routage.log(`Load`)
|
||||||
rssLoop(db.config.timeLoop*60*1000)
|
rssLoop(db.config.timeLoop*60*1000)
|
||||||
|
|
|
@ -1,91 +1,91 @@
|
||||||
/*
|
/*
|
||||||
SkeptCOM [RSS-Youtube] | Détecte les nouvelles vidéos YT via RSS
|
SkeptCOM [RSS-Youtube] | Détecte les nouvelles vidéos YT via RSS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// REQUIRE, CONST, VARIABLES
|
// REQUIRE, CONST, VARIABLES
|
||||||
const jsonfile = require('jsonfile')
|
const jsonfile = require('jsonfile')
|
||||||
const Parser = require('rss-parser')
|
const Parser = require('rss-parser')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
const routage = require('../modules/routage')('rss-youtube')
|
const routage = require('../modules/routage')('rss-youtube')
|
||||||
let parser = new Parser({
|
let parser = new Parser({
|
||||||
customFields: {
|
customFields: {
|
||||||
item: [ 'author', 'media:group' ]
|
item: [ 'author', 'media:group' ]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const db = require('../db/rss-youtube.json')
|
const db = require('../db/rss-youtube.json')
|
||||||
|
|
||||||
|
|
||||||
// FUNCTIONS
|
// FUNCTIONS
|
||||||
// et on output ! YOLO !
|
// et on output ! YOLO !
|
||||||
function output(data) {
|
function output(data) {
|
||||||
console.log(` --> [RSS-Youtube | NV] ${data.author} | ${data.title}`)
|
console.log(` --> [RSS-Youtube | NV] ${data.author} | ${data.title}`)
|
||||||
if (routage && routage.send) routage.send(data)
|
if (routage && routage.send) routage.send(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// bon, on a besoin de recup le RSS, normol
|
// bon, on a besoin de recup le RSS, normol
|
||||||
async function getFeed(url) {
|
async function getFeed(url) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
parser.parseURL(url, (err, res) => {
|
parser.parseURL(url, (err, res) => {
|
||||||
if (err) return reject(err)
|
if (err) return reject(err)
|
||||||
resolve(res)
|
resolve(res)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// on filtre un peu, puis en fonction on output
|
// on filtre un peu, puis en fonction on output
|
||||||
async function parseRSS(feed, owner) {
|
async function parseRSS(feed, owner) {
|
||||||
if (!db.timecode[owner]) db.timecode[owner] = db.timecode.lastCheck
|
if (!db.timecode[owner]) db.timecode[owner] = db.timecode.lastCheck
|
||||||
let cLastCheck = db.timecode[owner]
|
let cLastCheck = db.timecode[owner]
|
||||||
for (let i in feed.items) {
|
for (let i in feed.items) {
|
||||||
if (feed.items[i].isoDate > db.timecode.lastCheck || feed.items[i].isoDate > cLastCheck) {
|
if (feed.items[i].isoDate > db.timecode.lastCheck || feed.items[i].isoDate > cLastCheck) {
|
||||||
if (feed.items[i].isoDate > cLastCheck) cLastCheck = feed.items[i].isoDate
|
if (feed.items[i].isoDate > cLastCheck) cLastCheck = feed.items[i].isoDate
|
||||||
let c = feed.items[i]
|
let c = feed.items[i]
|
||||||
c.desc = feed.items[i]['media:group']['media:description'][0].slice(0, db.config.sliceDescription) + " [...]"
|
c.desc = feed.items[i]['media:group']['media:description'][0].slice(0, db.config.sliceDescription) + " [...]"
|
||||||
c.image = "http://i3.ytimg.com/vi/" + c.id.split(':')[2] + "/maxresdefault.jpg"
|
c.image = "http://i3.ytimg.com/vi/" + c.id.split(':')[2] + "/maxresdefault.jpg"
|
||||||
c.url = c.link
|
c.url = c.link
|
||||||
delete c.link
|
delete c.link
|
||||||
delete c['media:group']
|
delete c['media:group']
|
||||||
if (c.isoDate > cLastCheck) cLastCheck = feed.items[i].isoDate
|
if (c.isoDate > cLastCheck) cLastCheck = feed.items[i].isoDate
|
||||||
output(c)
|
output(c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
db.timecode[owner] = cLastCheck
|
db.timecode[owner] = cLastCheck
|
||||||
}
|
}
|
||||||
|
|
||||||
// on check l'ensemble de feeds
|
// on check l'ensemble de feeds
|
||||||
async function checkFeeds(feeds) {
|
async function checkFeeds(feeds) {
|
||||||
console.log(` --- [RSS-Youtube] check @${db.timecode.lastCheck}`)
|
console.log(` --- [RSS-Youtube] check @${db.timecode.lastCheck}`)
|
||||||
routage.log(`check @${db.timecode.lastCheck}`)
|
routage.log(`check @${db.timecode.lastCheck}`)
|
||||||
for (let i in feeds) {
|
for (let i in feeds) {
|
||||||
let feed = await getFeed(db.config.urlFeeds + feeds[i])
|
let feed = await getFeed(db.config.urlFeeds + feeds[i])
|
||||||
try {
|
try {
|
||||||
await parseRSS(feed, i)
|
await parseRSS(feed, i)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("error while parsing feed %s", feed, e);
|
console.error("error while parsing feed %s", feed, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let dateObj = new Date()
|
let dateObj = new Date()
|
||||||
db.timecode.lastCheck = dateObj.toISOString()
|
db.timecode.lastCheck = dateObj.toISOString()
|
||||||
|
|
||||||
// et on externalise la nouvelle date. Youpi !
|
// et on externalise la nouvelle date. Youpi !
|
||||||
jsonfile.writeFile(path.resolve('./db/rss-youtube.json'), db, {spaces: 2}, (err) => {
|
jsonfile.writeFile(path.resolve('./db/rss-youtube.json'), db, {spaces: 2}, (err) => {
|
||||||
console.log()
|
console.log()
|
||||||
if (err) console.error(err)
|
if (err) console.error(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function rssLoop(time) {
|
function rssLoop(time) {
|
||||||
checkFeeds(db.feeds)
|
checkFeeds(db.feeds)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
rssLoop(time)
|
rssLoop(time)
|
||||||
}, time)
|
}, time)
|
||||||
}
|
}
|
||||||
|
|
||||||
// INIT
|
// INIT
|
||||||
console.log(` --- [RSS-Youtube] Load`)
|
console.log(` --- [RSS-Youtube] Load`)
|
||||||
routage.log(`Load`)
|
routage.log(`Load`)
|
||||||
rssLoop(db.config.timeLoop*60*1000)
|
rssLoop(db.config.timeLoop*60*1000)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user