细节优化
This commit is contained in:
parent
cba4771d6b
commit
bfa67e2deb
39
lib/bot.js
39
lib/bot.js
|
@ -11,8 +11,13 @@ export default class Yunzai extends EventEmitter {
|
||||||
super()
|
super()
|
||||||
this.uin = []
|
this.uin = []
|
||||||
this.adapter = []
|
this.adapter = []
|
||||||
this.server = express()
|
this.express = express()
|
||||||
|
this.server = http.createServer(this.express)
|
||||||
this.wss = {}
|
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() {
|
async run() {
|
||||||
|
@ -24,16 +29,10 @@ export default class Yunzai extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
serverLoad() {
|
serverLoad() {
|
||||||
this.server.all("*", req => {
|
this.express.use(req => {
|
||||||
logger.info(`${logger.blue(`[${req.ip}]`)} HTTP ${req.method} 请求:${req.url} ${JSON.stringify(req.rawHeaders)}`)
|
logger.info(`${logger.blue(`[${req.ip}]`)} HTTP ${req.method} 请求:${req.url} ${JSON.stringify(req.rawHeaders)}`)
|
||||||
req.res.redirect("https://github.com/TimeRainStarSky/Yunzai")
|
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, () => {
|
this.server.listen(cfg.bot.port, () => {
|
||||||
const host = this.server.address().address
|
const host = this.server.address().address
|
||||||
|
@ -47,24 +46,24 @@ export default class Yunzai extends EventEmitter {
|
||||||
getFriendArray() {
|
getFriendArray() {
|
||||||
const array = []
|
const array = []
|
||||||
for (const bot_id of this.uin)
|
for (const bot_id of this.uin)
|
||||||
for (const i of this[bot_id].fl || [])
|
for (const [id, i] of this[bot_id].fl || [])
|
||||||
array.push({ ...i[1], bot_id })
|
array.push({ ...i, bot_id })
|
||||||
return array
|
return array
|
||||||
}
|
}
|
||||||
|
|
||||||
getFriendList() {
|
getFriendList() {
|
||||||
const array = []
|
const array = []
|
||||||
for (const bot_id of this.uin)
|
for (const bot_id of this.uin)
|
||||||
for (const i of this[bot_id].fl || [])
|
for (const [id, i] of this[bot_id].fl || [])
|
||||||
array.push(i[0])
|
array.push(id)
|
||||||
return array
|
return array
|
||||||
}
|
}
|
||||||
|
|
||||||
getFriendMap() {
|
getFriendMap() {
|
||||||
const map = new Map()
|
const map = new Map()
|
||||||
for (const bot_id of this.uin)
|
for (const bot_id of this.uin)
|
||||||
for (const i of this[bot_id].fl || [])
|
for (const [id, i] of this[bot_id].fl || [])
|
||||||
map.set(i[0], { ...i[1], bot_id })
|
map.set(id, { ...i, bot_id })
|
||||||
return map
|
return map
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,24 +74,24 @@ export default class Yunzai extends EventEmitter {
|
||||||
getGroupArray() {
|
getGroupArray() {
|
||||||
const array = []
|
const array = []
|
||||||
for (const bot_id of this.uin)
|
for (const bot_id of this.uin)
|
||||||
for (const i of this[bot_id].gl || [])
|
for (const [id, i] of this[bot_id].gl || [])
|
||||||
array.push({ ...i[1], bot_id })
|
array.push({ ...i, bot_id })
|
||||||
return array
|
return array
|
||||||
}
|
}
|
||||||
|
|
||||||
getGroupList() {
|
getGroupList() {
|
||||||
const array = []
|
const array = []
|
||||||
for (const bot_id of this.uin)
|
for (const bot_id of this.uin)
|
||||||
for (const i of this[bot_id].gl || [])
|
for (const [id, i] of this[bot_id].gl || [])
|
||||||
array.push(i[0])
|
array.push(id)
|
||||||
return array
|
return array
|
||||||
}
|
}
|
||||||
|
|
||||||
getGroupMap() {
|
getGroupMap() {
|
||||||
const map = new Map()
|
const map = new Map()
|
||||||
for (const bot_id of this.uin)
|
for (const bot_id of this.uin)
|
||||||
for (const i of this[bot_id].gl || [])
|
for (const [id, i] of this[bot_id].gl || [])
|
||||||
map.set(i[0], { ...i[1], bot_id })
|
map.set(id, { ...i, bot_id })
|
||||||
return map
|
return map
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -378,7 +378,7 @@ class PluginsLoader {
|
||||||
e.getReply = () => e.friend.getMsg(e.reply_id)
|
e.getReply = () => e.friend.getMsg(e.reply_id)
|
||||||
break
|
break
|
||||||
case "file":
|
case "file":
|
||||||
e.file = val
|
e.file = i
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -470,7 +470,7 @@ class PluginsLoader {
|
||||||
/**
|
/**
|
||||||
* @param msg 发送的消息
|
* @param msg 发送的消息
|
||||||
* @param quote 是否引用回复
|
* @param quote 是否引用回复
|
||||||
* @param data.recallMsg 群聊是否撤回消息,0-120秒,0不撤回
|
* @param data.recallMsg 是否撤回消息,0-120秒,0不撤回
|
||||||
* @param data.at 是否at用户
|
* @param data.at 是否at用户
|
||||||
*/
|
*/
|
||||||
e.reply = async (msg = "", quote = false, data = {}) => {
|
e.reply = async (msg = "", quote = false, data = {}) => {
|
||||||
|
@ -481,16 +481,15 @@ class PluginsLoader {
|
||||||
if (at) {
|
if (at) {
|
||||||
if (at === true)
|
if (at === true)
|
||||||
at = e.user_id
|
at = e.user_id
|
||||||
|
|
||||||
if (Array.isArray(msg))
|
if (Array.isArray(msg))
|
||||||
msg = [segment.at(at), ...msg]
|
msg.unshift(segment.at(at))
|
||||||
else
|
else
|
||||||
msg = [segment.at(at), msg]
|
msg = [segment.at(at), msg]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (quote && e.message_id) {
|
if (quote && e.message_id) {
|
||||||
if (Array.isArray(msg))
|
if (Array.isArray(msg))
|
||||||
msg = [segment.reply(e.message_id), ...msg]
|
msg.unshift(segment.reply(e.message_id))
|
||||||
else
|
else
|
||||||
msg = [segment.reply(e.message_id), msg]
|
msg = [segment.reply(e.message_id), msg]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue