This commit is contained in:
Jay
2018-06-28 21:26:44 +08:00
parent ce2b664c77
commit 1fdd26e27c
4 changed files with 41 additions and 7 deletions
+27 -5
View File
@@ -15,17 +15,39 @@ const parseCMD = async (text = '', source = {}) => {
if (arr.length === 0) return null
if (arr[0][0] !== '!') return null
let cmd = arr[0].replace(/^!/, '')
if (!(cmd in cmds)) return null
// find default command
if (cmd in cmds) {
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
}
let db = await DB.connect()
let result = null
try {
result = await cmds[cmd](arr.slice(1).join(' '), source, db)
let text = `select "mrssage" from "public"."commands" where cmd = $1`
let values = [cmd]
let result = await db.query({
text,
values
})
if (result.rowCount === 0) {
db.release()
return null
}
} catch (err) {
console.log(err)
db.release()
return null
}
// if (result === null) return null
db.release()
return result
}
module.exports = parseCMD