modify line command , not fin

This commit is contained in:
Jay 2018-06-29 17:59:48 +08:00
parent af3cb135bf
commit d6f1b81796
2 changed files with 24 additions and 6 deletions

View File

@ -1,4 +1,19 @@
const api = require('../../api-action')
const api = require('../../../api-action')
const DB = require('../../../database')
async function run (fn = null, txt, source) {
if (!fn || typeof fn !== 'function') return null
let res = null
let db = null
try {
db = await DB.connect()
res = await fn(txt, source, db)
} catch (err) {
console.log(err)
}
if (db !== null && 'release' in db) db.release()
return res
}
/**
* add group to database
* @param {string} txt command body format => groupName notifyEnable(0,1)
@ -361,9 +376,9 @@ const delTwitch = async (txt = '', source = {}, db) => {
}
module.exports = {
addgroup: addGroup,
addpage: addPage,
delpage: delPage,
addtwitch: addTwitch,
deltwitch: delTwitch
addgroup: run.bind(null, addGroup),
addpage: run.bind(null, addPage),
delpage: run.bind(null, delPage),
addtwitch: run.bind(null, addTwitch),
deltwitch: run.bind(null, delTwitch)
}

View File

@ -25,6 +25,9 @@ for (let i of actGrpFile) {
const runAct = async (cmd, txt = '', source = {}) => {
if (!cmd || typeof cmd !== 'string' || cmd.length === 0) return null
if (!(cmd in cmds)) return null
let result = await cmds[cmd](txt, source)
return result
}
module.exports = runAct