mtfosbot/libs/line-message/commands/actions/index.js

34 lines
766 B
JavaScript
Raw Normal View History

2018-06-28 15:41:16 +00:00
const fs = require('fs')
const path = require('path')
const cmds = {}
let list = fs.readdirSync(path.resolve(__dirname))
let actGrpFile = list.filter(t => {
if (t.startsWith('index')) return false
let stat = fs.statSync(path.resolve(__dirname, t))
return stat.isFile
})
let allowExt = /^\.(js)$/i
for (let i of actGrpFile) {
let ext = path.extname(i)
let fp = path.resolve(__dirname, i)
if (!allowExt.test(ext)) continue
let tmp = require(fp)
for (let j in tmp) {
cmds[j] = tmp[j]
}
}
const runAct = async (cmd, txt = '', source = {}) => {
if (!cmd || typeof cmd !== 'string' || cmd.length === 0) return null
2018-06-29 09:59:48 +00:00
if (!(cmd in cmds)) return null
let result = await cmds[cmd](txt, source)
2018-07-10 15:48:26 +00:00
return result.reply
2018-06-28 15:41:16 +00:00
}
module.exports = runAct