get clients from config

This commit is contained in:
Flummi 2017-11-08 21:40:59 +01:00
parent 8190df87a2
commit fdea6de52c
2 changed files with 21 additions and 26 deletions

View File

@ -1,7 +1,7 @@
import sql from './sql.js'; import sql from './sql.js';
let cfg = { let cfg = {
irc: {}, client: {},
main: {}, main: {},
websrv: {}, websrv: {},
trigger: {} trigger: {}
@ -13,7 +13,7 @@ const read = () => new Promise((resolve, reject) => {
reject({ error: "no cfg" }); reject({ error: "no cfg" });
else { else {
for(let row in rows) { for(let row in rows) {
cfg[rows[row].class ][ rows[row].key] = ((type, value) => { cfg[rows[row].class][rows[row].key] = ((type, value) => {
switch(type) { switch(type) {
case 'string': case 'string':
return value; return value;

View File

@ -2,6 +2,7 @@ import { cfg, read } from './cfg.js';
import { loadEvents } from './lib.js'; import { loadEvents } from './lib.js';
let irclib = require('./irc/irc.js'); let irclib = require('./irc/irc.js');
let tglib = require('node-telegram-bot-api');
//const safeEval = require('safe-eval'); //const safeEval = require('safe-eval');
const util = require('util'); const util = require('util');
//const fs = require('fs'); //const fs = require('fs');
@ -11,30 +12,24 @@ var EventEmitter = require('events').EventEmitter;
let clients = []; let clients = [];
const wrapper = function() { const wrapper = function() {
clients.push({ for(let srv in cfg.client) {
name: "n0xy", switch(cfg.client[srv].type) {
type: "irc", case "irc":
client: new irclib({ clients.push({
network: "n0xy", name: cfg.client[srv].network,
host: "31.172.14.83", type: "irc",
port: 6669, //6669, client: new irclib(cfg.client[srv])
ssl: true, });
selfSigned: true, break;
nickname: "kbotv3", case "tg":
username: "kbotv2/n0xy", clients.push({
password: "blah", name: "tg",
realname: "kbotv3", type: "tg",
channels: [ client: new tglib(cfg.client[srv].token, { polling: cfg.client[srv].polling })
"#kbot-dev" });
] break;
}) }
}); }
clients.push({
name: "tg",
type: "tg",
client: new (require('node-telegram-bot-api'))('381368731:AAFalG-LknIbtBDuOvRXcxHUEK9Jg_o1UCw', { polling: true })
});
clients.forEach(client => { clients.forEach(client => {
client.client.on("message", e => { client.client.on("message", e => {