2017-11-07 17:22:41 +00:00
|
|
|
import sql from './sql.js';
|
|
|
|
|
|
|
|
let cfg = {
|
|
|
|
irc: {},
|
|
|
|
main: {},
|
|
|
|
websrv: {},
|
|
|
|
trigger: {}
|
|
|
|
};
|
|
|
|
|
|
|
|
const read = () => new Promise((resolve, reject) => {
|
|
|
|
sql.exec("select * from `cfg`", (err, rows) => {
|
|
|
|
if(err || rows.length < 1)
|
|
|
|
reject({ error: "no cfg" });
|
|
|
|
else {
|
|
|
|
for(let row in rows) {
|
|
|
|
cfg[rows[row].class ][ rows[row].key] = ((type, value) => {
|
|
|
|
switch(type) {
|
|
|
|
case 'string':
|
|
|
|
return value;
|
|
|
|
break;
|
|
|
|
case 'int':
|
|
|
|
return parseInt(value);
|
|
|
|
break;
|
|
|
|
case 'bool':
|
2017-11-08 11:56:04 +00:00
|
|
|
return value === 'true';
|
2017-11-07 17:22:41 +00:00
|
|
|
break;
|
|
|
|
case 'json':
|
|
|
|
return JSON.parse(value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
})(rows[row].type, rows[row].value);
|
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
export { cfg, read };
|