34 lines
766 B
JavaScript
34 lines
766 B
JavaScript
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
|
|
if (!(cmd in cmds)) return null
|
|
let result = await cmds[cmd](txt, source)
|
|
return result.reply
|
|
}
|
|
|
|
module.exports = runAct
|