Skip to content

Commit

Permalink
细节优化
Browse files Browse the repository at this point in the history
  • Loading branch information
TimeRainStarSky committed May 24, 2024
1 parent 863fe37 commit 3f2530a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@ export default class Yunzai extends EventEmitter {
this.adapter = []

this.express = express()
this.express.quiet = []
for (const i of ["urlencoded", "json", "raw", "text"])
this.express.use(express[i]({ extended: false }))
this.express.use(req => {
req.next()
let quiet = false
for (const i of req.app.quiet)
if (req.originalUrl.startsWith(i)) {
quiet = true
break
}
req.rid = `${req.ip}:${req.socket.remotePort}`
req.sid = `${req.protocol}://${req.hostname}:${req.socket.localPort}${req.originalUrl}`
this.makeLog("mark", ["HTTP", req.method, "请求", req.headers, req.query, req.body], `${req.sid} <= ${req.rid}`)
req.next()
this.makeLog(quiet ? "debug" : "mark", ["HTTP", req.method, "请求", req.headers, req.query, req.body], `${req.sid} <= ${req.rid}`)
})
this.express.use("/exit", req => {
if (["::1", "::ffff:127.0.0.1"].includes(req.ip) || req.hostname == "localhost")
Expand Down Expand Up @@ -519,8 +526,7 @@ export default class Yunzai extends EventEmitter {
getFriendList() {
const array = []
for (const bot_id of this.uin)
for (const [id, i] of this.bots[bot_id].fl || [])
array.push(id)
array.push(...(this.bots[bot_id].fl?.keys() || []))
return array
}

Expand All @@ -544,8 +550,7 @@ export default class Yunzai extends EventEmitter {
getGroupList() {
const array = []
for (const bot_id of this.uin)
for (const [id, i] of this.bots[bot_id].gl || [])
array.push(id)
array.push(...(this.bots[bot_id].gl?.keys() || []))
return array
}

Expand Down

0 comments on commit 3f2530a

Please sign in to comment.