细节优化

This commit is contained in:
🌌 2023-07-08 21:40:55 +08:00
parent 92b53f9ac8
commit 0b33fc9153
5 changed files with 43 additions and 40 deletions

View File

@ -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
}
}

View File

@ -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)

View File

@ -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
}

View File

@ -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)

View File

@ -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
}