细节优化

This commit is contained in:
🌌 2023-07-23 16:39:33 +08:00
parent cba4771d6b
commit bfa67e2deb
2 changed files with 23 additions and 25 deletions

View File

@ -11,8 +11,13 @@ export default class Yunzai extends EventEmitter {
super()
this.uin = []
this.adapter = []
this.server = express()
this.express = express()
this.server = http.createServer(this.express)
this.wss = {}
this.server.on("upgrade", (req, socket, head) => {
const wss = this.wss[req.url.split("/")[1]]
if (wss) wss.handleUpgrade(req, socket, head, conn => wss.emit("connection", conn, req))
})
}
async run() {
@ -24,16 +29,10 @@ export default class Yunzai extends EventEmitter {
}
serverLoad() {
this.server.all("*", req => {
this.express.use(req => {
logger.info(`${logger.blue(`[${req.ip}]`)} HTTP ${req.method} 请求:${req.url} ${JSON.stringify(req.rawHeaders)}`)
req.res.redirect("https://github.com/TimeRainStarSky/Yunzai")
})
this.server = http.createServer(this.server)
this.server.on("upgrade", (req, socket, head) => {
const wss = this.wss[req.url.split("/")[1]]
if (wss) wss.handleUpgrade(req, socket, head, conn => wss.emit("connection", conn, req))
})
this.server.listen(cfg.bot.port, () => {
const host = this.server.address().address
@ -47,24 +46,24 @@ export default class Yunzai extends EventEmitter {
getFriendArray() {
const array = []
for (const bot_id of this.uin)
for (const i of this[bot_id].fl || [])
array.push({ ...i[1], bot_id })
for (const [id, i] of this[bot_id].fl || [])
array.push({ ...i, bot_id })
return array
}
getFriendList() {
const array = []
for (const bot_id of this.uin)
for (const i of this[bot_id].fl || [])
array.push(i[0])
for (const [id, i] of this[bot_id].fl || [])
array.push(id)
return array
}
getFriendMap() {
const map = new Map()
for (const bot_id of this.uin)
for (const i of this[bot_id].fl || [])
map.set(i[0], { ...i[1], bot_id })
for (const [id, i] of this[bot_id].fl || [])
map.set(id, { ...i, bot_id })
return map
}
@ -75,24 +74,24 @@ export default class Yunzai extends EventEmitter {
getGroupArray() {
const array = []
for (const bot_id of this.uin)
for (const i of this[bot_id].gl || [])
array.push({ ...i[1], bot_id })
for (const [id, i] of this[bot_id].gl || [])
array.push({ ...i, bot_id })
return array
}
getGroupList() {
const array = []
for (const bot_id of this.uin)
for (const i of this[bot_id].gl || [])
array.push(i[0])
for (const [id, i] of this[bot_id].gl || [])
array.push(id)
return array
}
getGroupMap() {
const map = new Map()
for (const bot_id of this.uin)
for (const i of this[bot_id].gl || [])
map.set(i[0], { ...i[1], bot_id })
for (const [id, i] of this[bot_id].gl || [])
map.set(id, { ...i, bot_id })
return map
}

View File

@ -378,7 +378,7 @@ class PluginsLoader {
e.getReply = () => e.friend.getMsg(e.reply_id)
break
case "file":
e.file = val
e.file = i
break
}
}
@ -470,7 +470,7 @@ class PluginsLoader {
/**
* @param msg 发送的消息
* @param quote 是否引用回复
* @param data.recallMsg 群聊是否撤回消息0-1200不撤回
* @param data.recallMsg 是否撤回消息0-1200不撤回
* @param data.at 是否at用户
*/
e.reply = async (msg = "", quote = false, data = {}) => {
@ -481,16 +481,15 @@ class PluginsLoader {
if (at) {
if (at === true)
at = e.user_id
if (Array.isArray(msg))
msg = [segment.at(at), ...msg]
msg.unshift(segment.at(at))
else
msg = [segment.at(at), msg]
}
if (quote && e.message_id) {
if (Array.isArray(msg))
msg = [segment.reply(e.message_id), ...msg]
msg.unshift(segment.reply(e.message_id))
else
msg = [segment.reply(e.message_id), msg]
}