update
This commit is contained in:
parent
ce2b664c77
commit
1fdd26e27c
@ -103,7 +103,6 @@ new cron.CronJob({ //eslint-disable-line
|
||||
let twch = await db.query({
|
||||
text
|
||||
})
|
||||
console.log('check twitch channel number :::: ', twch.rowCount)
|
||||
let ids = twch.rows.map(t => t.id)
|
||||
let streams = await api.twitch.getUserStream(ids)
|
||||
if (streams !== null && Array.isArray(streams)) {
|
||||
@ -124,7 +123,6 @@ new cron.CronJob({ //eslint-disable-line
|
||||
})
|
||||
|
||||
const sendStreamNotify = async (streamer = null) => {
|
||||
console.log(streamer)
|
||||
if (streamer === null || typeof streamer !== 'object' || !('user_id' in streamer) || !('id' in streamer)) return null
|
||||
let db = await DB.connect()
|
||||
|
||||
|
@ -8,6 +8,11 @@ const client = axios.create({
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* push message to group or room or user
|
||||
* @param {string} target target id (groupid, userid, roomid)
|
||||
* @param {string} message push message
|
||||
*/
|
||||
const pushMessage = async (target, message = '') => {
|
||||
if (typeof target !== 'string' || target.trim().length === 0) return
|
||||
if (typeof message !== 'string' || message.trim().length === 0) return
|
||||
@ -31,6 +36,11 @@ const pushMessage = async (target, message = '') => {
|
||||
await client(opts)
|
||||
}
|
||||
|
||||
/**
|
||||
* send reply message
|
||||
* @param {string} replyToken line message reply token
|
||||
* @param {string} message reply message
|
||||
*/
|
||||
const replyMessage = async (replyToken, message) => {
|
||||
let url = '/message/reply'
|
||||
let opts = {
|
||||
|
@ -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
|
||||
|
@ -1,6 +1,10 @@
|
||||
const commands = require('./commands')
|
||||
const api = require('../api-action')
|
||||
|
||||
/**
|
||||
* parse text message object
|
||||
* @param {object} evt line message event object
|
||||
*/
|
||||
const textMessage = async (evt) => {
|
||||
let {replyToken, source, message} = evt
|
||||
if (!source || !('type' in source) || source.type !== 'group') return
|
||||
|
Loading…
Reference in New Issue
Block a user