32 lines
827 B
JavaScript
32 lines
827 B
JavaScript
|
const DB = require('../../database')
|
||
|
const groupCMD = require('./group')
|
||
|
|
||
|
const cmds = {}
|
||
|
|
||
|
for (let i in groupCMD) {
|
||
|
cmds[i] = groupCMD[i]
|
||
|
}
|
||
|
|
||
|
const parseCMD = async (text = '', source = {}) => {
|
||
|
if (typeof text !== 'string' || text.trim().length === 0) return null
|
||
|
if (!source || typeof source !== 'object' || !('type' in source)) return null
|
||
|
let txt = text.trim()
|
||
|
let arr = txt.split(' ').map(t => t.trim())
|
||
|
if (arr.length === 0) return null
|
||
|
if (arr[0][0] !== '!') return null
|
||
|
let cmd = arr[0].replace(/^!/, '')
|
||
|
if (!(cmd in cmds)) return null
|
||
|
let db = await DB.connect()
|
||
|
let result = null
|
||
|
try {
|
||
|
result = await cmds[cmd](arr.slice(1).join(' '), source, db)
|
||
|
} catch (err) {
|
||
|
console.log(err)
|
||
|
}
|
||
|
// if (result === null) return null
|
||
|
db.release()
|
||
|
return result
|
||
|
}
|
||
|
|
||
|
module.exports = parseCMD
|