modify opay check condition

This commit is contained in:
Jay 2018-09-12 20:30:42 +08:00
parent a8a3f595ec
commit 10c3e09014
1 changed files with 12 additions and 10 deletions

View File

@ -242,11 +242,11 @@ new cron.CronJob({ //eslint-disable-line
let db = await DB.connect()
try {
let text = `select "name", "id", "opayid" from "public"."twitch_channel" where "opayid" != '' and "join" = true`
let text = `select "name", "id", "opayid", "join" from "public"."twitch_channel" where "opayid" != ''`
let result = await db.query({ text })
if (result.rowCount > 0) {
result.rows.forEach(t => {
checkDonate(t.name, t.opayid).then(() => {}).catch(() => {})
checkDonate(t.name, t.opayid, t.join).then(() => {}).catch(() => {})
})
}
} catch (err) {
@ -260,7 +260,7 @@ new cron.CronJob({ //eslint-disable-line
timeZone: 'Asia/Taipei'
})
const checkDonate = async (loginName = null, opayid = null) => {
const checkDonate = async (loginName = null, opayid = null, join = false) => {
if (typeof loginName !== 'string' || loginName.trim().length === 0) return null
if (typeof opayid !== 'string' || opayid.trim().length === 0) return null
let url = `https://payment.opay.tw/Broadcaster/CheckDonate/${opayid}`
@ -308,13 +308,15 @@ const checkDonate = async (loginName = null, opayid = null) => {
text,
values
})
let msg = `/me 感謝 ${i.name} 贊助了 ${i.amount} 元, ${i.msg}`
process.send({
type: 'twitchSend',
data: {
msg, channel: loginName
}
})
if (join) {
let msg = `/me 感謝 ${i.name} 贊助了 ${i.amount} 元, ${i.msg}`
process.send({
type: 'twitchSend',
data: {
msg, channel: loginName
}
})
}
} catch (err) {
console.log(err)
}