diff --git a/libs/line-message/commands/actions/group.js b/libs/line-message/commands/actions/group.js index ab6e0bc..e71faaf 100644 --- a/libs/line-message/commands/actions/group.js +++ b/libs/line-message/commands/actions/group.js @@ -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) } diff --git a/libs/line-message/commands/actions/index.js b/libs/line-message/commands/actions/index.js index 12ec612..51db6aa 100644 --- a/libs/line-message/commands/actions/index.js +++ b/libs/line-message/commands/actions/index.js @@ -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