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';
let cfg = {
irc: {},
client: {},
main: {},
websrv: {},
trigger: {}
@ -13,7 +13,7 @@ const read = () => new Promise((resolve, reject) => {
reject({ error: "no cfg" });
else {
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) {
case 'string':
return value;

View File

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