Update sendNotify.js

This commit is contained in:
smallfawn
2023-07-11 13:38:39 +08:00
committed by GitHub
parent 05800a73ba
commit 1962c6b7c9

View File

@@ -195,6 +195,8 @@ if (process.env.PUSH_PLUS_USER) {
/** /**
* sendNotify 推送通知功能 * sendNotify 推送通知功能
* 魔改smallfawn https://github.com/smallfawn 增加黑白名单模式
* 变量值 smallfawnPushWhite白名单 smallfawnPushBlack黑名单 不写默认通知 黑白名单二选一
* @param text 通知头 * @param text 通知头
* @param desp 通知体 * @param desp 通知体
* @param params 某些推送通知方式点击弹窗可跳转, 例:{ url: 'https://abc.com' } * @param params 某些推送通知方式点击弹窗可跳转, 例:{ url: 'https://abc.com' }
@@ -207,6 +209,71 @@ async function sendNotify(
params = {}, params = {},
author = '\n\n本通知 Byhttps://github.com/whyour/qinglong', author = '\n\n本通知 Byhttps://github.com/whyour/qinglong',
) { ) {
let pushType = ["smallfawnPushWhite", "smallfawnPushBlack", 'default']
function checkSmallfawnPushType() {
if (process.env.hasOwnProperty(pushType[0]) !== undefined) {
return pushType[0];
} else if (process.env.hasOwnProperty(pushType[1]) !== undefined) {
return pushType[1];
} else {
return pushType[2];
}
}
function checkSmallfawnPush(variable) {
if (typeof variable === 'string') {
if (variable.includes('&') || variable.includes('#') || variable.includes('@')) {
console.log(variable.split(/[&#@]/))
return variable.split(/[&#@]/);
} else {
return [variable];
}
} else if (typeof variable === 'number') {
return [variable.toString()];
} else {
return [];
}
}
let type = checkSmallfawnPushType()
if (type !== pushType[2]) {
if (checkSmallfawnPush(process.env[type]).length == 0) {
console.log(`[${type}]长度为0 默认形式发送`);
await push()
return
} else {
if (type == pushType[0]) {
console.log(`通知变量为白名单模式`);
for (let sm of checkSmallfawnPush(process.env[pushType[0]])) {
if (text == sm) {
console.log(`根据[${type}]变量来选择通知`);
await push()
return
} else {
console.log(`[${type}]未含有该脚本的env名字不通知`)
}
}
} else if (type == pushType[1]) {
console.log(`通知变量为黑名单模式`);
for (let sm of checkSmallfawnPush(process.env[pushType[1]])) {
if (text == sm) {
console.log(`根据[${type}]变量来选择不通知`);
} else {
console.log(`[${type}]未含有该脚本的env名字通知`);
await push()
return
}
}
}
}
} else {
//不启动黑白名单模式 启动默认形式发送
console.log(`不启动黑白名单模式 启动默认形式发送`);
await push()
return
}
async function push() {
//提供6种通知 //提供6种通知
desp += author; //增加作者信息,防止被贩卖等 desp += author; //增加作者信息,防止被贩卖等
await Promise.all([ await Promise.all([
@@ -227,6 +294,13 @@ async function sendNotify(
]); ]);
} }
}
function gotifyNotify(text, desp) { function gotifyNotify(text, desp) {
return new Promise((resolve) => { return new Promise((resolve) => {
if (GOTIFY_URL && GOTIFY_TOKEN) { if (GOTIFY_URL && GOTIFY_TOKEN) {
@@ -409,8 +483,7 @@ function CoolPush(text, desp) {
console.log(`酷推发送${pushMode(QQ_MODE)}通知消息成功🎉\n`); console.log(`酷推发送${pushMode(QQ_MODE)}通知消息成功🎉\n`);
} else if (data.code === 400) { } else if (data.code === 400) {
console.log( console.log(
`QQ酷推(Cool Push)发送${pushMode(QQ_MODE)}推送失败:${ `QQ酷推(Cool Push)发送${pushMode(QQ_MODE)}推送失败:${data.msg
data.msg
}\n`, }\n`,
); );
} else if (data.code === 503) { } else if (data.code === 503) {
@@ -830,8 +903,7 @@ function pushPlusNotify(text, desp) {
try { try {
if (err) { if (err) {
console.log( console.log(
`push+发送${ `push+发送${PUSH_PLUS_USER ? '一对多' : '一对一'
PUSH_PLUS_USER ? '一对多' : '一对一'
}通知消息失败!!\n`, }通知消息失败!!\n`,
); );
console.log(err); console.log(err);
@@ -839,14 +911,12 @@ function pushPlusNotify(text, desp) {
data = JSON.parse(data); data = JSON.parse(data);
if (data.code === 200) { if (data.code === 200) {
console.log( console.log(
`push+发送${ `push+发送${PUSH_PLUS_USER ? '一对多' : '一对一'
PUSH_PLUS_USER ? '一对多' : '一对一'
}通知消息完成。\n`, }通知消息完成。\n`,
); );
} else { } else {
console.log( console.log(
`push+发送${ `push+发送${PUSH_PLUS_USER ? '一对多' : '一对一'
PUSH_PLUS_USER ? '一对多' : '一对一'
}通知消息失败:${data.msg}\n`, }通知消息失败:${data.msg}\n`,
); );
} }