modify opay check condition

This commit is contained in:
Jay 2018-09-12 20:30:42 +08:00
parent a8a3f595ec
commit 10c3e09014

View File

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