From 7185c2f2d41d7236ffd701be76463e42ca4936e4 Mon Sep 17 00:00:00 2001 From: sameu Date: Fri, 8 Sep 2023 02:31:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E8=A1=A8=E6=83=85=E4=B8=8D=E9=9A=8F=E6=9C=BA=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=80=92=E5=BA=8F=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=85=B1?= =?UTF-8?q?=E5=A4=9A=E5=B0=91=E9=A1=B5=E6=8F=90=E7=A4=BA=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=88=A4=E6=96=AD=E9=94=99=E8=AF=AF=20(#245)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/system/add.js | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/plugins/system/add.js b/plugins/system/add.js index dc750b7..268b454 100644 --- a/plugins/system/add.js +++ b/plugins/system/add.js @@ -408,8 +408,8 @@ export class add extends plugin { if (lodash.isEmpty(msg) && lodash.isEmpty(globalMsg)) return false msg = [...msg, ...globalMsg] - - if (num >= 0 && num < msg.length) { + /** 如果只有一个则不随机 */ + if (num >= 0 && msg.length === 1) { msg = msg[num] } else { /** 随机获取一个 */ @@ -705,37 +705,44 @@ export class add extends plugin { return } - let msg = [] - let num = 0 + let msg = [], result = [], num = 0 for (let i in arr) { if (num >= page * pageSize) break let keyWord = await this.keyWordTran(arr[i].key) if (!keyWord) continue - let result = [] if (Array.isArray(keyWord)) { keyWord.unshift(`${num + 1}、`) - keyWord.push('\n') - result.push(...keyWord) + // keyWord.push('\n') + keyWord.push(v => msg.push(v)) } else if (keyWord.type) { - result.push(`\n${num + 1}、`, keyWord, '\n\n') + msg.push(`\n${num + 1}、`, keyWord) } else { - result.push(`${num + 1}、${keyWord}\n`) + msg.push(`${num + 1}、`, keyWord) } - msg.push(result) num++ } - - if (type == 'list' && count > 100) { - msg.push(`更多内容请翻页查看\n如:#表情列表${Number(page) + 1}`) + /** 数组分段 */ + for (const i in msg) { + result.push([msg[i]]) + } + /** 计算页数 */ + let book = count / pageSize; + if (book % 1 === 0) { + book = result; + } else { + book = Math.floor(book) + 1; + } + if (type == 'list' && msg.length >= pageSize) { + result.push(`更多内容请翻页查看\n如:#表情列表${Number(page) + 1}`) } - let title = `表情列表,第${page}页,共${count}条` + let title = `表情列表,第${page}页,共${count}条,共${book}页` if (type == 'search') { title = `表情${search},${count}条` } - let forwardMsg = await common.makeForwardMsg(this.e, [title, ...msg], title) + let forwardMsg = await common.makeForwardMsg(this.e, [title, ...result], title) this.e.reply(forwardMsg) }