Update message.js

This commit is contained in:
可达鸭 2025-03-18 13:03:13 +08:00
parent 19f8ab03d1
commit 46901224d2

View File

@ -5,11 +5,14 @@ export class Message {
this.func = process.psyDuck this.func = process.psyDuck
this.msg = this.func.message this.msg = this.func.message
this.title = `🐽 消息提醒: ${this.func.profile.title}` this.title = `🐽 消息提醒: ${this.func.profile.title}`
message.push([`PsyDuck [https://github.com/qitoqito/psyduck]`]) this.msgAry = message.map(d => d.join("\n"))
this.message = message.map(d => d.join("\n"))
} }
async send(msgAry) { async send(msgAry) {
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')) { if (this.msg.hasOwnProperty('TELEGRAM_TOKEN')) {
await this.tgNotify() await this.tgNotify()
} }
@ -35,6 +38,7 @@ export class Message {
await this.wxamNotify() await this.wxamNotify()
} }
} }
}
async wxamNotify() { async wxamNotify() {
let message = this.message.join("\n\n") let message = this.message.join("\n\n")
@ -320,4 +324,26 @@ export class Message {
console.log('[Message] Telegram 发送通知消息失败') 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;
}
} }