From 46901224d234b33e2afd0d3fbc7f1b0bc9c357a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AF=E8=BE=BE=E9=B8=AD?= Date: Tue, 18 Mar 2025 13:03:13 +0800 Subject: [PATCH] Update message.js --- util/message.js | 76 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 25 deletions(-) diff --git a/util/message.js b/util/message.js index 6a46ed2..059f3c4 100644 --- a/util/message.js +++ b/util/message.js @@ -5,34 +5,38 @@ export class Message { this.func = process.psyDuck this.msg = this.func.message this.title = `🐽 消息提醒: ${this.func.profile.title}` - message.push([`PsyDuck [https://github.com/qitoqito/psyduck]`]) - this.message = message.map(d => d.join("\n")) + this.msgAry = message.map(d => d.join("\n")) } async send(msgAry) { - if (this.msg.hasOwnProperty('TELEGRAM_TOKEN')) { - await this.tgNotify() - } - if (this.msg.hasOwnProperty('BARK_TOKEN')) { - await this.barkNotify() - } - if (this.msg.hasOwnProperty('PUSHPLUS_TOKEN')) { - await this.ppNotify() - } - if (this.msg.hasOwnProperty('FTQQ_TOKEN')) { - await this.ftqqNotify() - } - if (this.msg.hasOwnProperty('DINGTALK_TOKEN')) { - await this.ddNotify() - } - if (this.msg.hasOwnProperty('IGOT_TOKEN')) { - await this.igotNotify() - } - if (this.msg.hasOwnProperty('WEIXIN_TOKEN')) { - await this.wechatNotify() - } - if (this.msg.hasOwnProperty('WXAM_TOKEN')) { - await this.wxamNotify() + const result = this.splitArrays(this.msgAry); + for (let message of result) { + message.push([`PsyDuck [https://github.com/qitoqito/psyduck]`]) + this.message = message + if (this.msg.hasOwnProperty('TELEGRAM_TOKEN')) { + await this.tgNotify() + } + if (this.msg.hasOwnProperty('BARK_TOKEN')) { + await this.barkNotify() + } + if (this.msg.hasOwnProperty('PUSHPLUS_TOKEN')) { + await this.ppNotify() + } + if (this.msg.hasOwnProperty('FTQQ_TOKEN')) { + await this.ftqqNotify() + } + if (this.msg.hasOwnProperty('DINGTALK_TOKEN')) { + await this.ddNotify() + } + if (this.msg.hasOwnProperty('IGOT_TOKEN')) { + await this.igotNotify() + } + if (this.msg.hasOwnProperty('WEIXIN_TOKEN')) { + await this.wechatNotify() + } + if (this.msg.hasOwnProperty('WXAM_TOKEN')) { + await this.wxamNotify() + } } } @@ -320,4 +324,26 @@ export class Message { console.log('[Message] Telegram 发送通知消息失败') } } + + splitArrays(arr, maxLength = 200) { + const result = []; + let currentArray = []; + let currentLength = 0; + for (const subArray of arr) { + const subLength = subArray.split("\n").length; + if (currentLength + subLength<=maxLength) { + currentArray.push(subArray); + currentLength += subLength; + } + else { + result.push(currentArray); + currentArray = [subArray]; + currentLength = subLength; + } + } + if (currentArray.length>0) { + result.push(currentArray); + } + return result; + } }