first commit

This commit is contained in:
peertube
2020-12-09 21:19:58 +01:00
commit da6d35b2e7
17 changed files with 2442 additions and 0 deletions

41
modules/discordBot.js Normal file
View File

@ -0,0 +1,41 @@
/*
SkeptCOM [Discord] | Pour envoyer des notifications sur un serveur Discord
*/
// LOAD configFiles
const discordConf = require('../conf/discord.json')
const routage = require('../modules/routage')('discordBot')
// REQUIRE, CONST, VARIABLES
const Discord = require('discord.js')
const client = new Discord.Client()
// FUNCTIONS
const myDiscord = {
send: function() {}
}
// INIT
client.on('ready', () => {
console.log(` --- [Discord] Logged in as ${client.user.tag}!`)
routage.send(` --- [Discord] Logged in as ${client.user.tag}!`)
myDiscord.send = (channel, msg) => {
client.channels.fetch(channel)
.then(channel => channel.send(msg))
.catch(console.error)
}
})
// client.on('message', message => {
// if (message.content.startsWith('!ping')) {
// console.log(`on a un ping`)
// routage.send(message.content)
// }
// })
client.login(discordConf.token)
module.exports = myDiscord

30
modules/routage.js Normal file
View File

@ -0,0 +1,30 @@
/*
SkeptCOM [IO] | Via un json, on va rediriger qui envoye a quoi
*/
const routes = require('../conf/routes.json')
const skepticonf = require('../conf/skepticom.json')
const services = {}
module.exports = (who) => {
if (!who || !routes[who]) return console.error(`ERROR routage`)
services[who] = require('./skeptIO')(who)
function send(data) {
services[who].send('logs', '', data)
for (let i in routes[who]) {
services[who].send(i, routes[who][i], data)
}
}
function log(data) {
services[who].send('logs', '', data)
}
return {
send,
log
}
}

40
modules/skeptIO.js Normal file
View File

@ -0,0 +1,40 @@
/*
SkeptIO | Gestionnaire des services
*/
const pm2 = require('pm2')
module.exports = (who) => {
function sendMSG(to, conf, data) {
if (!who) return console.error(`ERROR skeptIO ${to}`)
let dataMSG = {
topic: to,
from: 'skp_' + who,
conf,
data
}
pm2.list( (err, list) => { // on check la liste des process pm2
for (let i in list) {
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
if (err) return console.error(` <-- [${list[i].pm_id}:${list[i].name}] error`, err)
})
}
}
})
}
function receiveMSG(res) {
process.on('message', data => {
res(data)
})
}
return {
send: sendMSG,
receive: receiveMSG
}
}