mirror of
https://github.com/shanmiteko/LotteryAutoScript.git
synced 2026-06-04 21:01:17 +08:00
feat: 添加Gotify推送
This commit is contained in:
parent
201770573e
commit
69c297ecaa
@ -12,12 +12,12 @@ module.exports = Object.freeze({
|
||||
* ## 调试相关
|
||||
* - `LOTTERY_LOG_LEVEL` 输出日志等级 Error<Warn<Info<Debug 1<2<3<4
|
||||
* - `NOT_GO_LOTTERY` 关闭抽奖行为
|
||||
*
|
||||
*
|
||||
* ## 多账号
|
||||
* 1. 将 ENABLE_MULTIPLE_ACCOUNT 的值改为true
|
||||
* 2. 将账号信息依次填写于 multiple_account_parm 中, 参考例子类推
|
||||
* - `WAIT` 表示下一个账号运行等待时间(毫秒)
|
||||
*
|
||||
*
|
||||
* **按顺序依次执行, 防止访问频繁封禁IP**
|
||||
*/
|
||||
account_parm: {
|
||||
@ -37,7 +37,7 @@ module.exports = Object.freeze({
|
||||
/**
|
||||
* 为防止环境变量过长, 请将多账号填在此处
|
||||
* 以 **大括号内容** 为模板依次复制(包含大括号),逗号分割
|
||||
*
|
||||
*
|
||||
* ```txt
|
||||
* [
|
||||
* {
|
||||
@ -92,6 +92,8 @@ module.exports = Object.freeze({
|
||||
SMTP_PORT: "",
|
||||
SMTP_USER: "",
|
||||
SMTP_PASS: "",
|
||||
SMTP_TO_USER: ""
|
||||
SMTP_TO_USER: "",
|
||||
GOTIFY_URL: "",
|
||||
GOTIFY_APPKEY: ""
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@ -80,6 +80,13 @@ let SMTP_USER = '';
|
||||
let SMTP_PASS = '';
|
||||
let SMTP_TO_USER = '';
|
||||
|
||||
// ====================================Gotify======================================
|
||||
// 官方文档:https://gotify.net/docs/pushmsg
|
||||
// 此处填你的Gotify消息推送地址(例如:http://localhost/message)
|
||||
let GOTIFY_URL = '';
|
||||
// 此处填你想推送的Application的Token(不包含推送时额外添加的前缀 Bearer )
|
||||
let GOTIFY_APPKEY = '';
|
||||
|
||||
//==========================云端环境变量的判断与接收=========================
|
||||
if (process.env.SCKEY) {
|
||||
SCKEY = process.env.SCKEY;
|
||||
@ -190,6 +197,13 @@ if (process.env.SMTP_TO_USER) {
|
||||
SMTP_TO_USER = process.env.SMTP_TO_USER;
|
||||
}
|
||||
|
||||
if (process.env.GOTIFY_URL) {
|
||||
GOTIFY_URL = process.env.GOTIFY_URL;
|
||||
if (process.env.GOTIFY_APPKEY) {
|
||||
GOTIFY_APPKEY = process.env.GOTIFY_APPKEY
|
||||
}
|
||||
}
|
||||
|
||||
//==========================云端环境变量的判断与接收=========================
|
||||
|
||||
async function sendNotify(text, desp, params = {}) {
|
||||
@ -223,7 +237,9 @@ async function sendNotify(text, desp, params = {}) {
|
||||
// Qmsg
|
||||
qmsg(text, desp),
|
||||
//电子邮件
|
||||
email(text, desp)
|
||||
email(text, desp),
|
||||
// Gotify
|
||||
gotifyNotify(text, desp)
|
||||
])
|
||||
}
|
||||
|
||||
@ -820,6 +836,41 @@ function pushPlusNotify(text, desp) {
|
||||
})
|
||||
}
|
||||
|
||||
function gotifyNotify(test, desp) {
|
||||
return new Promise(resolve => {
|
||||
if (GOTIFY_APPKEY) {
|
||||
send({
|
||||
method: 'POST',
|
||||
url: GOTIFY_URL,
|
||||
contents: {
|
||||
title: test,
|
||||
message: desp,
|
||||
},
|
||||
config: {
|
||||
retry: false
|
||||
},
|
||||
headers: {
|
||||
accept: 'application/json, text/plain, */*',
|
||||
'content-type': 'application/json',
|
||||
'authorization': 'Bearer ' + GOTIFY_APPKEY
|
||||
},
|
||||
success: () => {
|
||||
// HTTP 响应码 200 就说明成功了
|
||||
log.info('发送通知', 'Gotify 发送通知消息成功')
|
||||
resolve();
|
||||
},
|
||||
failure: err => {
|
||||
log.error('发送通知', 'Gotify 发送通知调用API失败!!' + err)
|
||||
resolve();
|
||||
}
|
||||
})
|
||||
} else {
|
||||
log.debug('发送通知', '您未提供Gotify推送所需的GOTIFY_APPKEY,取消Gotify推送消息通知');
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function qmsg(text, desp) {
|
||||
return new Promise(resolve => {
|
||||
if (QMSG_KEY) {
|
||||
@ -889,4 +940,4 @@ async function email(text, desp) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { sendNotify }
|
||||
module.exports = { sendNotify }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user