From 0b33fc9153c72f5d9ea3bc2f4ec06bc17f90326e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8C=8C?= Date: Sat, 8 Jul 2023 21:40:55 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=86=E8=8A=82=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/bot.js | 40 ++++++++++++++++++------------------ lib/common/common.js | 4 ++-- plugins/adapter/ComWeChat.js | 12 +++++------ plugins/adapter/GSUIDCore.js | 11 ++++++---- plugins/adapter/go-cqhttp.js | 16 +++++++-------- 5 files changed, 43 insertions(+), 40 deletions(-) diff --git a/lib/bot.js b/lib/bot.js index 1ed3cd7..3972fb1 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -46,25 +46,25 @@ export default class Yunzai extends EventEmitter { getFriendArray() { const array = [] - for (const i of this.uin) - this[i].fl?.forEach(value => - array.push({ ...value, bot_id: i })) + for (const bot_id of this.uin) + for (const i of this[bot_id].fl || []) + array.push({ ...i[1], bot_id }) return array } getFriendList() { const array = [] - for (const i of this.uin) - this[i].fl?.forEach((value, key) => - array.push(key)) + for (const bot_id of this.uin) + for (const i of this[bot_id].fl || []) + array.push(i[0]) return array } getFriendMap() { const map = new Map() - for (const i of this.uin) - this[i].fl?.forEach((value, key) => - map.set(key, { ...value, bot_id: i })) + for (const bot_id of this.uin) + for (const i of this[bot_id].fl || []) + map.set(i[0], { ...i[1], bot_id }) return map } @@ -74,25 +74,25 @@ export default class Yunzai extends EventEmitter { getGroupArray() { const array = [] - for (const i of this.uin) - this[i].gl?.forEach(value => - array.push({ ...value, bot_id: i })) + for (const bot_id of this.uin) + for (const i of this[bot_id].gl || []) + array.push({ ...i[1], bot_id }) return array } getGroupList() { const array = [] - for (const i of this.uin) - this[i].gl?.forEach((value, key) => - array.push(key)) + for (const bot_id of this.uin) + for (const i of this[bot_id].gl || []) + array.push(i[0]) return array } getGroupMap() { const map = new Map() - for (const i of this.uin) - this[i].gl?.forEach((value, key) => - map.set(key, { ...value, bot_id: i })) + for (const bot_id of this.uin) + for (const i of this[bot_id].gl || []) + map.set(i[0], { ...i[1], bot_id }) return map } @@ -195,8 +195,8 @@ export default class Yunzai extends EventEmitter { async sendForwardMsg(send, msg) { const messages = [] - for (const i of msg) - messages.push(await send(i.message)) + for (const { message } of msg) + messages.push(await send(message)) return messages } } \ No newline at end of file diff --git a/lib/common/common.js b/lib/common/common.js index 1c5265c..79c718b 100644 --- a/lib/common/common.js +++ b/lib/common/common.js @@ -58,8 +58,8 @@ function mkdirs (dirname) { */ function makeForwardMsg (e, msg = []) { const forwardMsg = [] - for (const i of msg) - forwardMsg.push({ message: i }) + for (const message of msg) + forwardMsg.push({ message }) if (e?.group?.makeForwardMsg) return e.group.makeForwardMsg(forwardMsg) diff --git a/plugins/adapter/ComWeChat.js b/plugins/adapter/ComWeChat.js index 1111325..7f149a3 100644 --- a/plugins/adapter/ComWeChat.js +++ b/plugins/adapter/ComWeChat.js @@ -154,8 +154,8 @@ Bot.adapter.push(new class ComWeChatAdapter { async getFriendList(data) { const array = [] - for (const i of (await this.getFriendArray(data))) - array.push(i.user_id) + for (const { user_id } of (await this.getFriendArray(data))) + array.push(user_id) return array } @@ -178,8 +178,8 @@ Bot.adapter.push(new class ComWeChatAdapter { async getGroupList(data) { const array = [] - for (const i of (await this.getGroupArray(data))) - array.push(i.group_id) + for (const { group_id } of (await this.getGroupArray(data))) + array.push(group_id) return array } @@ -204,8 +204,8 @@ Bot.adapter.push(new class ComWeChatAdapter { async getMemberList(data) { const array = [] - for (const i of (await this.getMemberArray(data))) - array.push(i.user_id) + for (const { user_id } of (await this.getMemberArray(data))) + array.push(user_id) return array } diff --git a/plugins/adapter/GSUIDCore.js b/plugins/adapter/GSUIDCore.js index 69b9543..5393f42 100644 --- a/plugins/adapter/GSUIDCore.js +++ b/plugins/adapter/GSUIDCore.js @@ -67,10 +67,13 @@ Bot.adapter.push(new class GSUIDCoreAdapter { case "reply": i.data = i.data.id break - case "node": - for (const n in i.data) - i.data[n] = this.makeMsg(i.data[n]) - default: + case "node": { + const array = [] + for (const { message } of i.data) + array.push(...this.makeMsg(message)) + i.data = array + break + } default: i = { type: "text", data: JSON.stringify(i) } } msgs.push(i) diff --git a/plugins/adapter/go-cqhttp.js b/plugins/adapter/go-cqhttp.js index 12e8d29..99a01a6 100644 --- a/plugins/adapter/go-cqhttp.js +++ b/plugins/adapter/go-cqhttp.js @@ -148,8 +148,8 @@ Bot.adapter.push(new class gocqhttpAdapter { async getFriendList(data) { const array = [] - for (const i of (await this.getFriendArray(data))) - array.push(i.user_id) + for (const { user_id } of (await this.getFriendArray(data))) + array.push(user_id) return array } @@ -184,8 +184,8 @@ Bot.adapter.push(new class gocqhttpAdapter { async getGroupList(data) { const array = [] - for (const i of (await this.getGroupArray(data))) - array.push(i.group_id) + for (const { group_id } of (await this.getGroupArray(data))) + array.push(group_id) return array } @@ -210,8 +210,8 @@ Bot.adapter.push(new class gocqhttpAdapter { async getMemberList(data) { const array = [] - for (const i of (await this.getMemberArray(data))) - array.push(i.user_id) + for (const { user_id } of (await this.getMemberArray(data))) + array.push(user_id) return array } @@ -274,8 +274,8 @@ Bot.adapter.push(new class gocqhttpAdapter { async getGuildMemberList(data) { const array = [] - for (const i of (await this.getGuildMemberArray(data))) - array.push(i.user_id) + for (const { user_id } of (await this.getGuildMemberArray(data))) + array.push(user_id) return array.push }