mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-24 15:43:24 +08:00
parent
95330e04a3
commit
c959cec738
|
@ -2,6 +2,7 @@ export enum NotificationMode {
|
||||||
'gotify' = 'gotify',
|
'gotify' = 'gotify',
|
||||||
'goCqHttpBot' = 'goCqHttpBot',
|
'goCqHttpBot' = 'goCqHttpBot',
|
||||||
'serverChan' = 'serverChan',
|
'serverChan' = 'serverChan',
|
||||||
|
'pushDeer' = 'pushDeer',
|
||||||
'bark' = 'bark',
|
'bark' = 'bark',
|
||||||
'telegramBot' = 'telegramBot',
|
'telegramBot' = 'telegramBot',
|
||||||
'dingtalkBot' = 'dingtalkBot',
|
'dingtalkBot' = 'dingtalkBot',
|
||||||
|
@ -32,6 +33,10 @@ export class ServerChanNotification extends NotificationBaseInfo {
|
||||||
public serverChanKey = '';
|
public serverChanKey = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class PushDeerNotification extends NotificationBaseInfo {
|
||||||
|
public pushDeerKey = '';
|
||||||
|
}
|
||||||
|
|
||||||
export class BarkNotification extends NotificationBaseInfo {
|
export class BarkNotification extends NotificationBaseInfo {
|
||||||
public barkPush = '';
|
public barkPush = '';
|
||||||
public barkIcon =
|
public barkIcon =
|
||||||
|
@ -81,6 +86,7 @@ export interface NotificationInfo
|
||||||
extends GoCqHttpBotNotification,
|
extends GoCqHttpBotNotification,
|
||||||
GotifyNotification,
|
GotifyNotification,
|
||||||
ServerChanNotification,
|
ServerChanNotification,
|
||||||
|
PushDeerNotification,
|
||||||
BarkNotification,
|
BarkNotification,
|
||||||
TelegramBotNotification,
|
TelegramBotNotification,
|
||||||
DingtalkBotNotification,
|
DingtalkBotNotification,
|
||||||
|
|
|
@ -16,6 +16,7 @@ export default class NotificationService {
|
||||||
['gotify', this.gotify],
|
['gotify', this.gotify],
|
||||||
['goCqHttpBot', this.goCqHttpBot],
|
['goCqHttpBot', this.goCqHttpBot],
|
||||||
['serverChan', this.serverChan],
|
['serverChan', this.serverChan],
|
||||||
|
['pushDeer', this.pushDeer],
|
||||||
['bark', this.bark],
|
['bark', this.bark],
|
||||||
['telegramBot', this.telegramBot],
|
['telegramBot', this.telegramBot],
|
||||||
['dingtalkBot', this.dingtalkBot],
|
['dingtalkBot', this.dingtalkBot],
|
||||||
|
@ -90,15 +91,12 @@ export default class NotificationService {
|
||||||
private async goCqHttpBot() {
|
private async goCqHttpBot() {
|
||||||
const { goCqHttpBotQq, goCqHttpBotToken, goCqHttpBotUrl } = this.params;
|
const { goCqHttpBotQq, goCqHttpBotToken, goCqHttpBotUrl } = this.params;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(
|
.post(`${goCqHttpBotUrl}?${goCqHttpBotQq}`, {
|
||||||
`${goCqHttpBotUrl}?${goCqHttpBotQq}`,
|
timeout: this.timeout,
|
||||||
{
|
retry: 0,
|
||||||
timeout: this.timeout,
|
json: { message: `${this.title}\n${this.content}` },
|
||||||
retry: 0,
|
headers: { Authorization: 'Bearer ' + goCqHttpBotToken },
|
||||||
json: { message: `${this.title}\n${this.content}` },
|
})
|
||||||
headers: { 'Authorization': 'Bearer '+goCqHttpBotToken },
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.json();
|
.json();
|
||||||
return res.retcode === 0;
|
return res.retcode === 0;
|
||||||
}
|
}
|
||||||
|
@ -119,6 +117,25 @@ export default class NotificationService {
|
||||||
return res.errno === 0 || res.data.errno === 0;
|
return res.errno === 0 || res.data.errno === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async pushDeer() {
|
||||||
|
const { pushDeerKey } = this.params;
|
||||||
|
// https://api2.pushdeer.com/message/push?pushkey=<key>&text=标题&desp=<markdown>&type=markdown
|
||||||
|
const url = `https://api2.pushdeer.com/message/push`;
|
||||||
|
const res: any = await got
|
||||||
|
.post(url, {
|
||||||
|
timeout: this.timeout,
|
||||||
|
retry: 0,
|
||||||
|
body: `pushkey=${pushDeerKey}&text=${
|
||||||
|
this.title
|
||||||
|
}&desp=${encodeURIComponent(this.content)}&type=markdown`,
|
||||||
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
|
})
|
||||||
|
.json();
|
||||||
|
return (
|
||||||
|
res.content.result.length !== undefined && res.content.result.length > 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private async bark() {
|
private async bark() {
|
||||||
let { barkPush, barkIcon, barkSound, barkGroup } = this.params;
|
let { barkPush, barkIcon, barkSound, barkGroup } = this.params;
|
||||||
if (!barkPush.startsWith('http') && !barkPush.startsWith('https')) {
|
if (!barkPush.startsWith('http') && !barkPush.startsWith('https')) {
|
||||||
|
|
|
@ -125,4 +125,8 @@ export GOTIFY_URL=""
|
||||||
export GOTIFY_TOKEN=""
|
export GOTIFY_TOKEN=""
|
||||||
export GOTIFY_PRIORITY=0
|
export GOTIFY_PRIORITY=0
|
||||||
|
|
||||||
|
## 11. PushDeer
|
||||||
|
## deer_key 填写PushDeer的key
|
||||||
|
export DEER_KEY=""
|
||||||
|
|
||||||
## 其他需要的变量,脚本中需要的变量使用 export 变量名= 声明即可
|
## 其他需要的变量,脚本中需要的变量使用 export 变量名= 声明即可
|
||||||
|
|
|
@ -34,6 +34,11 @@ let GOBOT_QQ = ''; // 如果GOBOT_URL设置 /send_private_msg 则需要填入 us
|
||||||
//(环境变量名 PUSH_KEY)
|
//(环境变量名 PUSH_KEY)
|
||||||
let SCKEY = '';
|
let SCKEY = '';
|
||||||
|
|
||||||
|
// =======================================PushDeer通知设置区域===========================================
|
||||||
|
//此处填你申请的PushDeer KEY.
|
||||||
|
//(环境变量名 DEER_KEY)
|
||||||
|
let PUSHDEER_KEY = '';
|
||||||
|
|
||||||
// =======================================Bark App通知设置区域===========================================
|
// =======================================Bark App通知设置区域===========================================
|
||||||
//此处填你BarkAPP的信息(IP/设备码,例如:https://api.day.app/XXXXXXXX)
|
//此处填你BarkAPP的信息(IP/设备码,例如:https://api.day.app/XXXXXXXX)
|
||||||
let BARK_PUSH = '';
|
let BARK_PUSH = '';
|
||||||
|
@ -118,6 +123,10 @@ if (process.env.PUSH_KEY) {
|
||||||
SCKEY = process.env.PUSH_KEY;
|
SCKEY = process.env.PUSH_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (process.env.DEER_KEY) {
|
||||||
|
PUSHDEER_KEY = process.env.DEER_KEY;
|
||||||
|
}
|
||||||
|
|
||||||
if (process.env.QQ_SKEY) {
|
if (process.env.QQ_SKEY) {
|
||||||
QQ_SKEY = process.env.QQ_SKEY;
|
QQ_SKEY = process.env.QQ_SKEY;
|
||||||
}
|
}
|
||||||
|
@ -354,6 +363,52 @@ function serverNotify(text, desp, time = 2100) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function PushDeerNotify(text, desp, time = 2100) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
if (PUSHDEER_KEY) {
|
||||||
|
// PushDeer 建议对消息内容进行 urlencode
|
||||||
|
desp = encodeURI(desp);
|
||||||
|
const options = {
|
||||||
|
url: `https://api2.pushdeer.com/message/push`,
|
||||||
|
body: `pushkey=${PUSHDEER_KEY}&text=${text}&desp=${desp}&type=markdown`,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
},
|
||||||
|
timeout,
|
||||||
|
};
|
||||||
|
setTimeout(() => {
|
||||||
|
$.post(options, (err, resp, data) => {
|
||||||
|
try {
|
||||||
|
if (err) {
|
||||||
|
console.log('发送通知调用API失败!!\n');
|
||||||
|
console.log(err);
|
||||||
|
} else {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
// 通过反悔的result的长度来判断是否成功
|
||||||
|
if (
|
||||||
|
data.content.result.length !== undefined &&
|
||||||
|
data.content.result.length > 0
|
||||||
|
) {
|
||||||
|
console.log('PushDeer发送通知消息成功🎉\n');
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
`PushDeer发送通知消息异常\n${JSON.stringify(data)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
$.logErr(e, resp);
|
||||||
|
} finally {
|
||||||
|
resolve(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, time);
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function CoolPush(text, desp) {
|
function CoolPush(text, desp) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
if (QQ_SKEY) {
|
if (QQ_SKEY) {
|
||||||
|
|
|
@ -60,6 +60,8 @@ push_config = {
|
||||||
|
|
||||||
'PUSH_KEY': '', # server 酱的 PUSH_KEY,兼容旧版与 Turbo 版
|
'PUSH_KEY': '', # server 酱的 PUSH_KEY,兼容旧版与 Turbo 版
|
||||||
|
|
||||||
|
'DEER_KEY': '', # PushDeer 的 PUSHDEER_KEY
|
||||||
|
|
||||||
'PUSH_PLUS_TOKEN': '', # push+ 微信推送的用户令牌
|
'PUSH_PLUS_TOKEN': '', # push+ 微信推送的用户令牌
|
||||||
'PUSH_PLUS_USER': '', # push+ 微信推送的群组编码
|
'PUSH_PLUS_USER': '', # push+ 微信推送的群组编码
|
||||||
|
|
||||||
|
@ -261,6 +263,24 @@ def serverJ(title: str, content: str) -> None:
|
||||||
print(f'serverJ 推送失败!错误码:{response["message"]}')
|
print(f'serverJ 推送失败!错误码:{response["message"]}')
|
||||||
|
|
||||||
|
|
||||||
|
def pushdeer(title: str, content: str) -> None:
|
||||||
|
"""
|
||||||
|
通过PushDeer 推送消息
|
||||||
|
"""
|
||||||
|
if not push_config.get("DEER_KEY"):
|
||||||
|
print("PushDeer 服务的 DEER_KEY 未设置!!\n取消推送")
|
||||||
|
return
|
||||||
|
print("PushDeer 服务启动")
|
||||||
|
data = {"text": title, "desp": urllib.parse.urlencode({"text": content})}
|
||||||
|
url = 'https://api2.pushdeer.com/message/push'
|
||||||
|
response = requests.post(url, data=data).json()
|
||||||
|
|
||||||
|
if len(response.get("content").get("result")) > 0:
|
||||||
|
print("PushDeer 推送成功!")
|
||||||
|
else:
|
||||||
|
print("PushDeer 推送失败!错误信息:", response)
|
||||||
|
|
||||||
|
|
||||||
def pushplus_bot(title: str, content: str) -> None:
|
def pushplus_bot(title: str, content: str) -> None:
|
||||||
"""
|
"""
|
||||||
通过 push+ 推送消息。
|
通过 push+ 推送消息。
|
||||||
|
@ -505,6 +525,8 @@ if push_config.get("IGOT_PUSH_KEY"):
|
||||||
notify_function.append(iGot)
|
notify_function.append(iGot)
|
||||||
if push_config.get("PUSH_KEY"):
|
if push_config.get("PUSH_KEY"):
|
||||||
notify_function.append(serverJ)
|
notify_function.append(serverJ)
|
||||||
|
if push_config.get("DEER_KEY"):
|
||||||
|
notify_function.append(pushdeer)
|
||||||
if push_config.get("PUSH_PLUS_TOKEN"):
|
if push_config.get("PUSH_PLUS_TOKEN"):
|
||||||
notify_function.append(pushplus_bot)
|
notify_function.append(pushplus_bot)
|
||||||
if push_config.get("QMSG_KEY") and push_config.get("QMSG_TYPE"):
|
if push_config.get("QMSG_KEY") and push_config.get("QMSG_TYPE"):
|
||||||
|
|
|
@ -77,6 +77,7 @@ export default {
|
||||||
{ value: 'gotify', label: 'Gotify' },
|
{ value: 'gotify', label: 'Gotify' },
|
||||||
{ value: 'goCqHttpBot', label: 'GoCqHttpBot' },
|
{ value: 'goCqHttpBot', label: 'GoCqHttpBot' },
|
||||||
{ value: 'serverChan', label: 'Server酱' },
|
{ value: 'serverChan', label: 'Server酱' },
|
||||||
|
{ value: 'PushDeer', label: 'PushDeer' },
|
||||||
{ value: 'bark', label: 'Bark' },
|
{ value: 'bark', label: 'Bark' },
|
||||||
{ value: 'telegramBot', label: 'Telegram机器人' },
|
{ value: 'telegramBot', label: 'Telegram机器人' },
|
||||||
{ value: 'dingtalkBot', label: '钉钉机器人' },
|
{ value: 'dingtalkBot', label: '钉钉机器人' },
|
||||||
|
@ -113,6 +114,7 @@ export default {
|
||||||
serverChan: [
|
serverChan: [
|
||||||
{ label: 'serverChanKey', tip: 'Server酱SENDKEY', required: true },
|
{ label: 'serverChanKey', tip: 'Server酱SENDKEY', required: true },
|
||||||
],
|
],
|
||||||
|
PushDeer: [{ label: 'PushDeerKey', tip: 'PushDeer的Key', required: true }],
|
||||||
bark: [
|
bark: [
|
||||||
{
|
{
|
||||||
label: 'barkPush',
|
label: 'barkPush',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user