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({
|
let twch = await db.query({
|
||||||
text
|
text
|
||||||
})
|
})
|
||||||
console.log('check twitch channel number :::: ', twch.rowCount)
|
|
||||||
let ids = twch.rows.map(t => t.id)
|
let ids = twch.rows.map(t => t.id)
|
||||||
let streams = await api.twitch.getUserStream(ids)
|
let streams = await api.twitch.getUserStream(ids)
|
||||||
if (streams !== null && Array.isArray(streams)) {
|
if (streams !== null && Array.isArray(streams)) {
|
||||||
@ -124,7 +123,6 @@ new cron.CronJob({ //eslint-disable-line
|
|||||||
})
|
})
|
||||||
|
|
||||||
const sendStreamNotify = async (streamer = null) => {
|
const sendStreamNotify = async (streamer = null) => {
|
||||||
console.log(streamer)
|
|
||||||
if (streamer === null || typeof streamer !== 'object' || !('user_id' in streamer) || !('id' in streamer)) return null
|
if (streamer === null || typeof streamer !== 'object' || !('user_id' in streamer) || !('id' in streamer)) return null
|
||||||
let db = await DB.connect()
|
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 = '') => {
|
const pushMessage = async (target, message = '') => {
|
||||||
if (typeof target !== 'string' || target.trim().length === 0) return
|
if (typeof target !== 'string' || target.trim().length === 0) return
|
||||||
if (typeof message !== 'string' || message.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)
|
await client(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send reply message
|
||||||
|
* @param {string} replyToken line message reply token
|
||||||
|
* @param {string} message reply message
|
||||||
|
*/
|
||||||
const replyMessage = async (replyToken, message) => {
|
const replyMessage = async (replyToken, message) => {
|
||||||
let url = '/message/reply'
|
let url = '/message/reply'
|
||||||
let opts = {
|
let opts = {
|
||||||
|
@ -15,7 +15,9 @@ const parseCMD = async (text = '', source = {}) => {
|
|||||||
if (arr.length === 0) return null
|
if (arr.length === 0) return null
|
||||||
if (arr[0][0] !== '!') return null
|
if (arr[0][0] !== '!') return null
|
||||||
let cmd = arr[0].replace(/^!/, '')
|
let cmd = arr[0].replace(/^!/, '')
|
||||||
if (!(cmd in cmds)) return null
|
|
||||||
|
// find default command
|
||||||
|
if (cmd in cmds) {
|
||||||
let db = await DB.connect()
|
let db = await DB.connect()
|
||||||
let result = null
|
let result = null
|
||||||
try {
|
try {
|
||||||
@ -26,6 +28,26 @@ const parseCMD = async (text = '', source = {}) => {
|
|||||||
// if (result === null) return null
|
// if (result === null) return null
|
||||||
db.release()
|
db.release()
|
||||||
return result
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
let db = await DB.connect()
|
||||||
|
try {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
db.release()
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = parseCMD
|
module.exports = parseCMD
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
const commands = require('./commands')
|
const commands = require('./commands')
|
||||||
const api = require('../api-action')
|
const api = require('../api-action')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* parse text message object
|
||||||
|
* @param {object} evt line message event object
|
||||||
|
*/
|
||||||
const textMessage = async (evt) => {
|
const textMessage = async (evt) => {
|
||||||
let {replyToken, source, message} = evt
|
let {replyToken, source, message} = evt
|
||||||
if (!source || !('type' in source) || source.type !== 'group') return
|
if (!source || !('type' in source) || source.type !== 'group') return
|
||||||
|
Loading…
Reference in New Issue
Block a user