修改示例脚本

This commit is contained in:
whyour 2024-05-05 19:47:54 +08:00
parent 20be84b352
commit e9852a0002
5 changed files with 41 additions and 29 deletions

View File

@ -64,7 +64,7 @@ const push_config = {
TG_BOT_TOKEN: '', // tg 机器人的 TG_BOT_TOKEN1407203283:AAG9rt-6RDaaX0HBLZQq0laNOh898iFYaRQ TG_BOT_TOKEN: '', // tg 机器人的 TG_BOT_TOKEN1407203283:AAG9rt-6RDaaX0HBLZQq0laNOh898iFYaRQ
TG_USER_ID: '', // tg 机器人的 TG_USER_ID1434078534 TG_USER_ID: '', // tg 机器人的 TG_USER_ID1434078534
TG_API_HOST: '', // tg 代理 api TG_API_HOST: 'https://api.telegram.org', // tg 代理 api
TG_PROXY_AUTH: '', // tg 代理认证参数 TG_PROXY_AUTH: '', // tg 代理认证参数
TG_PROXY_HOST: '', // tg 机器人的 TG_PROXY_HOST TG_PROXY_HOST: '', // tg 机器人的 TG_PROXY_HOST
TG_PROXY_PORT: '', // tg 机器人的 TG_PROXY_PORT TG_PROXY_PORT: '', // tg 机器人的 TG_PROXY_PORT
@ -143,7 +143,7 @@ async function one() {
function gotifyNotify(text, desp) { function gotifyNotify(text, desp) {
return new Promise((resolve) => { return new Promise((resolve) => {
const { GOTIFY_URL, GOTIFY_TOKEN } = push_config; const { GOTIFY_URL, GOTIFY_TOKEN, GOTIFY_PRIORITY } = push_config;
if (GOTIFY_URL && GOTIFY_TOKEN) { if (GOTIFY_URL && GOTIFY_TOKEN) {
const options = { const options = {
url: `${GOTIFY_URL}/message?token=${GOTIFY_TOKEN}`, url: `${GOTIFY_URL}/message?token=${GOTIFY_TOKEN}`,
@ -179,7 +179,7 @@ function gotifyNotify(text, desp) {
function gobotNotify(text, desp) { function gobotNotify(text, desp) {
return new Promise((resolve) => { return new Promise((resolve) => {
const { GOBOT_URL } = push_config; const { GOBOT_URL, GOBOT_TOKEN, GOBOT_QQ } = push_config;
if (GOBOT_URL) { if (GOBOT_URL) {
const options = { const options = {
url: `${GOBOT_URL}?access_token=${GOBOT_TOKEN}&${GOBOT_QQ}`, url: `${GOBOT_URL}?access_token=${GOBOT_TOKEN}&${GOBOT_QQ}`,
@ -199,9 +199,7 @@ function gobotNotify(text, desp) {
} else if (data.retcode === 100) { } else if (data.retcode === 100) {
console.log(`Go-cqhttp 发送通知消息异常 ${data.errmsg}\n`); console.log(`Go-cqhttp 发送通知消息异常 ${data.errmsg}\n`);
} else { } else {
console.log( console.log(`Go-cqhttp 发送通知消息异常 ${JSON.stringify(data)}`);
`Go-cqhttp 发送通知消息异常 ${JSON.stringify(data)}`,
);
} }
} }
} catch (e) { } catch (e) {
@ -218,14 +216,14 @@ function gobotNotify(text, desp) {
function serverNotify(text, desp) { function serverNotify(text, desp) {
return new Promise((resolve) => { return new Promise((resolve) => {
const { SCKEY } = push_config; const { PUSH_KEY } = push_config;
if (SCKEY) { if (PUSH_KEY) {
// 微信server酱推送通知一个\n不会换行需要两个\n才能换行故做此替换 // 微信server酱推送通知一个\n不会换行需要两个\n才能换行故做此替换
desp = desp.replace(/[\n\r]/g, '\n\n'); desp = desp.replace(/[\n\r]/g, '\n\n');
const options = { const options = {
url: SCKEY.includes('SCT') url: PUSH_KEY.includes('SCT')
? `https://sctapi.ftqq.com/${SCKEY}.send` ? `https://sctapi.ftqq.com/${PUSH_KEY}.send`
: `https://sc.ftqq.com/${SCKEY}.send`, : `https://sc.ftqq.com/${PUSH_KEY}.send`,
body: `text=${text}&desp=${desp}`, body: `text=${text}&desp=${desp}`,
headers: { headers: {
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
@ -261,13 +259,13 @@ function serverNotify(text, desp) {
function pushDeerNotify(text, desp) { function pushDeerNotify(text, desp) {
return new Promise((resolve) => { return new Promise((resolve) => {
const { DEER_KEY, PUSHDEER_URL } = push_config; const { DEER_KEY, DEER_URL } = push_config;
if (DEER_KEY) { if (DEER_KEY) {
// PushDeer 建议对消息内容进行 urlencode // PushDeer 建议对消息内容进行 urlencode
desp = encodeURI(desp); desp = encodeURI(desp);
const options = { const options = {
url: PUSHDEER_URL || `https://api2.pushdeer.com/message/push`, url: DEER_URL || `https://api2.pushdeer.com/message/push`,
body: `pushkey=${PUSHDEER_KEY}&text=${text}&desp=${desp}&type=markdown`, body: `pushkey=${DEER_KEY}&text=${text}&desp=${desp}&type=markdown`,
headers: { headers: {
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
}, },
@ -285,7 +283,9 @@ function pushDeerNotify(text, desp) {
) { ) {
console.log('PushDeer 发送通知消息成功🎉\n'); console.log('PushDeer 发送通知消息成功🎉\n');
} else { } else {
console.log(`PushDeer 发送通知消息异常😞 ${JSON.stringify(data)}`); console.log(
`PushDeer 发送通知消息异常😞 ${JSON.stringify(data)}`,
);
} }
} }
} catch (e) { } catch (e) {
@ -388,8 +388,14 @@ function barkNotify(text, desp, params = {}) {
function tgBotNotify(text, desp) { function tgBotNotify(text, desp) {
return new Promise((resolve) => { return new Promise((resolve) => {
const { TG_BOT_TOKEN, TG_USER_ID, TG_PROXY_HOST, TG_PROXY_PORT } = const {
push_config; TG_BOT_TOKEN,
TG_USER_ID,
TG_PROXY_HOST,
TG_PROXY_PORT,
TG_API_HOST,
TG_PROXY_AUTH,
} = push_config;
if (TG_BOT_TOKEN && TG_USER_ID) { if (TG_BOT_TOKEN && TG_USER_ID) {
const options = { const options = {
url: `${TG_API_HOST}/bot${TG_BOT_TOKEN}/sendMessage`, url: `${TG_API_HOST}/bot${TG_BOT_TOKEN}/sendMessage`,
@ -680,7 +686,9 @@ function do_qywxamNotify(text, desp) {
'企业微信应用消息发送通知消息成功🎉。\n', '企业微信应用消息发送通知消息成功🎉。\n',
); );
} else { } else {
console.log(`企业微信应用消息发送通知消息异常 ${data.errmsg}\n`); console.log(
`企业微信应用消息发送通知消息异常 ${data.errmsg}\n`,
);
} }
} }
} catch (e) { } catch (e) {
@ -1221,8 +1229,7 @@ async function sendNotify(text, desp, params = {}) {
} }
} }
hitokoto = push_config.HITOKOTO; if (push_config.HITOKOTO) {
if (hitokoto) {
desp += '\n\n' + (await one()); desp += '\n\n' + (await one());
} }

View File

@ -43,7 +43,7 @@ push_config = {
'BARK_LEVEL': '', # bark 推送时效性 'BARK_LEVEL': '', # bark 推送时效性
'BARK_URL': '', # bark 推送跳转URL 'BARK_URL': '', # bark 推送跳转URL
'CONSOLE': True, # 控制台输出 'CONSOLE': False, # 控制台输出
'DD_BOT_SECRET': '', # 钉钉机器人的 DD_BOT_SECRET 'DD_BOT_SECRET': '', # 钉钉机器人的 DD_BOT_SECRET
'DD_BOT_TOKEN': '', # 钉钉机器人的 DD_BOT_TOKEN 'DD_BOT_TOKEN': '', # 钉钉机器人的 DD_BOT_TOKEN

11
sample/ql_sample.js Normal file
View File

@ -0,0 +1,11 @@
/**
* 任务名称
* name: script name
* 定时规则
* cron: 1 9 * * *
*/
const { sendNotify } = require('./sendNotify.js'); // commonjs
// import { sendNotify } from './sendNotify'; // es6
console.log('test scripts');
sendNotify('test scripts', 'test desc');

View File

@ -4,5 +4,7 @@ name: script name
定时规则 定时规则
cron: 1 9 * * * cron: 1 9 * * *
""" """
import notify
print("test script") print("test script")
notify.send('test script', 'test desc')

View File

@ -1,8 +0,0 @@
/**
* 任务名称
* name: script name
* 定时规则
* cron: 1 9 * * *
*/
console.log('test scripts');