diff --git a/lib/bot.js b/lib/bot.js index 3972fb1..e1b2ab9 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -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 } diff --git a/lib/plugins/loader.js b/lib/plugins/loader.js index 709ce03..ac4a32c 100644 --- a/lib/plugins/loader.js +++ b/lib/plugins/loader.js @@ -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-120秒,0不撤回 + * @param data.recallMsg 是否撤回消息,0-120秒,0不撤回 * @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] }