From 58077b02e0b518cb09a492e573f0f28baf27dcff Mon Sep 17 00:00:00 2001 From: wangluping Date: Fri, 16 Jun 2023 14:32:11 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81Server=E9=85=B1?= =?UTF-8?q?=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/auto.yml | 1 + README.md | 1 + workflows/utils/env.js | 7 ++++++- workflows/utils/notification-kit.ts | 25 +++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/.github/workflows/auto.yml b/.github/workflows/auto.yml index 288b7067..e4f9ca54 100644 --- a/.github/workflows/auto.yml +++ b/.github/workflows/auto.yml @@ -17,6 +17,7 @@ env: DINGDING_WEBHOOK: ${{ secrets.DINGDING_WEBHOOK }} PUSHPLUS_TOKEN: ${{ secrets.PUSHPLUS_TOKEN }} WEIXIN_WEBHOOK: ${{ secrets.WEIXIN_WEBHOOK }} + SERVERPUSHKEY: ${{ secrets.SERVERPUSHKEY }} jobs: CheckIn: diff --git a/README.md b/README.md index 6ad429b9..22505a90 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ | EMAIL_TO | 订阅人邮箱地址(收件人). 如需多人订阅使用 `, ` 分割, 例如: `a@163.com, b@qq.com` | 否 | | DINGDING_WEBHOOK | 钉钉机器人WEBHOOK | 否 | | PUSHPLUS_TOKEN | [Pushplus](http://www.pushplus.plus/) 官网申请,支持微信消息推送 | 否 | + | SERVERPUSHKEY | [Server酱](https://sct.ftqq.com//) 官网申请,支持微信消息推送 | 否 | | WEIXIN_WEBHOOK | 企业微信机器人WEBHOOK | 否 | 4. 仓库 -> Actions, 检查Workflows并启用。 diff --git a/workflows/utils/env.js b/workflows/utils/env.js index 8e9b1c12..4665ebcc 100644 --- a/workflows/utils/env.js +++ b/workflows/utils/env.js @@ -29,5 +29,10 @@ module.exports = { * 企业微信机器人配置 * https://developer.work.weixin.qq.com/document/path/91770 */ - WEIXIN_WEBHOOK: env.WEIXIN_WEBHOOK + WEIXIN_WEBHOOK: env.WEIXIN_WEBHOOK, + /** + * server酱推送key + * https://sct.ftqq.com/sendkey + */ + SERVERPUSHKEY: env.SERVERPUSHKEY, }; diff --git a/workflows/utils/notification-kit.ts b/workflows/utils/notification-kit.ts index 6af4543d..8791f637 100644 --- a/workflows/utils/notification-kit.ts +++ b/workflows/utils/notification-kit.ts @@ -132,6 +132,30 @@ export class NotificationKit { }); } + /** + * serverPush推送 + * @param options + */ + async serverPush(options: PushPlusOptions) { + const token: string | unknown = env.SERVERPUSHKEY; + if (!token || token === "") { + throw new Error("未配置server酱 key。"); + } + + const config = { + title: options.title, + desp: options.content, + short: "签到成功", + channel: "9", + }; + + return axios.post(`https://sctapi.ftqq.com/${token}.send`, config, { + headers: { + "Content-Type": "application/json" + } + }); + } + /** * 钉钉Webhook * @param options @@ -206,6 +230,7 @@ export class NotificationKit { await trycatch("钉钉", this.dingtalkWebhook.bind(this)); await trycatch("微信", this.wecomWebhook.bind(this)); await trycatch("PushPlus", this.pushplus.bind(this)); + await trycatch("server酱", this.serverPush.bind(this)); } } From a1dce0f6c876f0ba54ddde26dd369b14e8394820 Mon Sep 17 00:00:00 2001 From: wangluping Date: Fri, 16 Jun 2023 15:41:54 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat=20title=E5=A2=9E=E5=8A=A0=E7=AD=BE?= =?UTF-8?q?=E5=88=B0=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- workflows/checkin.js | 4 ++-- workflows/utils/notification-kit.ts | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/workflows/checkin.js b/workflows/checkin.js index 19e15993..1bd7538c 100644 --- a/workflows/checkin.js +++ b/workflows/checkin.js @@ -328,7 +328,7 @@ async function run(args) { const message = messageList.join(`\n${"-".repeat(15)}\n`); notification.pushMessage({ - title: "掘金每日签到", + title: `掘金每日签到[${this.growthTask.todayStatus == 0 ? 'fail' : 'success'}]`, content: message, msgtype: "text" }); @@ -336,7 +336,7 @@ async function run(args) { run(process.argv.splice(2)).catch(error => { notification.pushMessage({ - title: "掘金每日签到", + title: "掘金每日签到[fail]", content: `Error
${error.message}
`, msgtype: "html" }); diff --git a/workflows/utils/notification-kit.ts b/workflows/utils/notification-kit.ts index 8791f637..3f38d4a2 100644 --- a/workflows/utils/notification-kit.ts +++ b/workflows/utils/notification-kit.ts @@ -145,7 +145,6 @@ export class NotificationKit { const config = { title: options.title, desp: options.content, - short: "签到成功", channel: "9", }; From 3944916e50ba26081c86f184c56d97f2f296d26d Mon Sep 17 00:00:00 2001 From: lupingW <50098740+lupingW@users.noreply.github.com> Date: Fri, 16 Jun 2023 16:37:41 +0800 Subject: [PATCH 3/5] Update checkin.js --- workflows/checkin.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/workflows/checkin.js b/workflows/checkin.js index 1bd7538c..d2e05052 100644 --- a/workflows/checkin.js +++ b/workflows/checkin.js @@ -262,6 +262,8 @@ class CheckIn { await this.bugfixTask.run(); await juejin.logout(); console.log("-------------------------"); + + return this.growthTask.todayStatus } toString() { @@ -314,11 +316,12 @@ ${this.lotteriesTask.lotteryCount > 0 ? "==============\n" + drawLotteryHistory async function run(args) { const cookies = utils.getUsersCookie(env); let messageList = []; + let todayStatus = 0 for (let cookie of cookies) { const checkin = new CheckIn(cookie); await utils.wait(utils.randomRangeNumber(1000, 5000)); // 初始等待1-5s - await checkin.run(); // 执行 + todayStatus = await checkin.run(); // 执行 const content = checkin.toString(); console.log(content); // 打印结果 @@ -328,7 +331,7 @@ async function run(args) { const message = messageList.join(`\n${"-".repeat(15)}\n`); notification.pushMessage({ - title: `掘金每日签到[${this.growthTask.todayStatus == 0 ? 'fail' : 'success'}]`, + title: `掘金每日签到[${todayStatus == 0 ? 'fail' : 'success'}]`, content: message, msgtype: "text" }); From b553995702167d04b561971b8fe1dbd8d46b3881 Mon Sep 17 00:00:00 2001 From: Derek Li <24502299+iDerekLi@users.noreply.github.com> Date: Mon, 19 Jun 2023 10:21:22 +0800 Subject: [PATCH 4/5] Update checkin.js --- workflows/checkin.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/workflows/checkin.js b/workflows/checkin.js index d2e05052..ffcd6e00 100644 --- a/workflows/checkin.js +++ b/workflows/checkin.js @@ -316,12 +316,11 @@ ${this.lotteriesTask.lotteryCount > 0 ? "==============\n" + drawLotteryHistory async function run(args) { const cookies = utils.getUsersCookie(env); let messageList = []; - let todayStatus = 0 for (let cookie of cookies) { const checkin = new CheckIn(cookie); await utils.wait(utils.randomRangeNumber(1000, 5000)); // 初始等待1-5s - todayStatus = await checkin.run(); // 执行 + await checkin.run(); // 执行 const content = checkin.toString(); console.log(content); // 打印结果 @@ -331,7 +330,7 @@ async function run(args) { const message = messageList.join(`\n${"-".repeat(15)}\n`); notification.pushMessage({ - title: `掘金每日签到[${todayStatus == 0 ? 'fail' : 'success'}]`, + title: "掘金每日签到", content: message, msgtype: "text" }); @@ -339,7 +338,7 @@ async function run(args) { run(process.argv.splice(2)).catch(error => { notification.pushMessage({ - title: "掘金每日签到[fail]", + title: "掘金每日签到", content: `Error
${error.message}
`, msgtype: "html" }); From 6c9ee948b56f0cadcc4570af403c0527167cc0bc Mon Sep 17 00:00:00 2001 From: Derek Li <24502299+iDerekLi@users.noreply.github.com> Date: Mon, 19 Jun 2023 10:23:23 +0800 Subject: [PATCH 5/5] Update notification-kit.ts --- workflows/utils/notification-kit.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/workflows/utils/notification-kit.ts b/workflows/utils/notification-kit.ts index 3f38d4a2..24c58800 100644 --- a/workflows/utils/notification-kit.ts +++ b/workflows/utils/notification-kit.ts @@ -139,7 +139,7 @@ export class NotificationKit { async serverPush(options: PushPlusOptions) { const token: string | unknown = env.SERVERPUSHKEY; if (!token || token === "") { - throw new Error("未配置server酱 key。"); + throw new Error("未配置Server酱 key。"); } const config = { @@ -229,7 +229,7 @@ export class NotificationKit { await trycatch("钉钉", this.dingtalkWebhook.bind(this)); await trycatch("微信", this.wecomWebhook.bind(this)); await trycatch("PushPlus", this.pushplus.bind(this)); - await trycatch("server酱", this.serverPush.bind(this)); + await trycatch("Server酱", this.serverPush.bind(this)); } }