From 0634aa026b84e07ed4bbc0ad5fa61e698becb133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8C=8C?= Date: Tue, 12 Sep 2023 13:28:11 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=86=E8=8A=82=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/modules/oicq/index.js | 25 ++++++++++++++++--------- package.json | 8 ++++---- plugins/adapter/ComWeChat.js | 28 ++++++++-------------------- plugins/other/update.js | 2 +- 4 files changed, 29 insertions(+), 34 deletions(-) diff --git a/lib/modules/oicq/index.js b/lib/modules/oicq/index.js index 1dc85ca..75af0cb 100644 --- a/lib/modules/oicq/index.js +++ b/lib/modules/oicq/index.js @@ -1,11 +1,15 @@ import fs from "node:fs" +import path from "node:path" function toSegment(type, data) { for (const i in data) { switch (typeof data[i]) { case "string": - if ((i == "file" || data[i].match(/^file:\/\//)) && fs.existsSync(data[i].replace(/^file:\/\//, ""))) + if ((i == "file" || data[i].match(/^file:\/\//)) && fs.existsSync(data[i].replace(/^file:\/\//, ""))) { + if (i == "file" && !data.name) + data.name = path.basename(data[i]) data[i] = `base64://${fs.readFileSync(data[i].replace(/^file:\/\//, "")).toString("base64")}` + } break case "object": if (Buffer.isBuffer(data[i])) @@ -19,17 +23,20 @@ const segment = new class segment { custom(type, data) { return toSegment(type, data) } - image(file) { - return toSegment("image", { file }) + image(file, name) { + return toSegment("image", { file, name }) } at(qq, name) { return toSegment("at", { qq, name }) } - record(file) { - return toSegment("record", { file }) + record(file, name) { + return toSegment("record", { file, name }) } - video(file) { - return toSegment("video", { file }) + video(file, name) { + return toSegment("video", { file, name }) + } + file(file, name) { + return toSegment("file", { file, name }) } reply(id, text, qq, time, seq) { return toSegment("reply", { id, text, qq, time, seq }) @@ -49,8 +56,8 @@ const segment = new class segment { gift(qq, id) { return toSegment("gift", { qq, id }) } - cardimage(file, minwidth, minheight, maxwidth, maxheight, source, icon) { - return toSegment("cardimage", { file, minwidth, minheight, maxwidth, maxheight, source, icon }) + cardimage(file, name, minwidth, minheight, maxwidth, maxheight, source, icon) { + return toSegment("cardimage", { file, name, minwidth, minheight, maxwidth, maxheight, source, icon }) } tts(text) { return toSegment("tts", { text }) diff --git a/package.json b/package.json index d5958ca..b90f8ce 100644 --- a/package.json +++ b/package.json @@ -34,16 +34,16 @@ "pm2": "^5.3.0", "puppeteer": "^21.1.1", "redis": "^4.6.8", - "sequelize": "^6.32.1", + "sequelize": "^6.33.0", "sqlite3": "^5.1.6", - "ws": "^8.14.0", + "ws": "^8.14.1", "yaml": "^2.3.2" }, "devDependencies": { - "eslint": "^8.48.0", + "eslint": "^8.49.0", "eslint-config-standard": "^17.1.0", "eslint-plugin-import": "^2.28.1", - "eslint-plugin-n": "^16.0.2", + "eslint-plugin-n": "^16.1.0", "eslint-plugin-promise": "^6.1.1" }, "imports": { diff --git a/plugins/adapter/ComWeChat.js b/plugins/adapter/ComWeChat.js index 012eaa0..a0b910c 100644 --- a/plugins/adapter/ComWeChat.js +++ b/plugins/adapter/ComWeChat.js @@ -26,7 +26,7 @@ Bot.adapter.push(new class ComWeChatAdapter { } makeLog(msg) { - return this.toStr(msg).replace(/(base64:\/\/|"type":"data","data":").*?(,|]|")/g, "$1...$2") + return this.toStr(msg).replace(/(base64:\/\/|"type":"data","data":").*?"/g, '$1..."') } sendApi(ws, action, params = {}) { @@ -63,7 +63,7 @@ Bot.adapter.push(new class ComWeChatAdapter { opts.type = "data" opts.data = file.replace(/^base64:\/\//, "") } else if (fs.existsSync(file)) { - opts.type = "data", + opts.type = "data" opts.data = fs.readFileSync(file).toString("base64") } else { opts.type = "path" @@ -84,16 +84,16 @@ Bot.adapter.push(new class ComWeChatAdapter { else if (!i.data) i = { type: i.type, data: { ...i, type: undefined }} if (i.data.file) - i.data = { file_id: (await this.uploadFile(data, i.data.file)).file_id } + i.data = { file_id: (await this.uploadFile(data, i.data.file, i.data.name)).file_id } switch (i.type) { case "text": - break case "image": + case "file": + case "wx.emoji": + case "wx.link": break case "record": - i.type = "file" - break case "video": i.type = "file" break @@ -105,11 +105,6 @@ Bot.adapter.push(new class ComWeChatAdapter { break case "reply": continue - break - case "wx.emoji": - break - case "wx.link": - break default: i = { type: "text", data: { text: JSON.stringify(i) }} } @@ -223,13 +218,6 @@ Bot.adapter.push(new class ComWeChatAdapter { }) } - async sendFile(data, send, file, name) { - logger.info(`${logger.blue(`[${data.self_id}]`)} 发送文件:${name}(${file})`) - return send(segment.custom("file", { - file_id: (await this.uploadFile(data, file, name)).file_id - })) - } - pickFriend(data, user_id) { const i = { ...data.bot.fl.get(user_id), @@ -239,7 +227,7 @@ Bot.adapter.push(new class ComWeChatAdapter { return { ...i, sendMsg: msg => this.sendFriendMsg(i, msg), - sendFile: (file, name) => this.sendFile(i, msg => this.sendFriendMsg(i, msg), file, name), + sendFile: (file, name) => this.sendFriendMsg(i, segment.file(file, name)), getInfo: () => this.getFriendInfo(i), getAvatarUrl: async () => (await this.getFriendInfo(i))["wx.avatar"], } @@ -269,7 +257,7 @@ Bot.adapter.push(new class ComWeChatAdapter { return { ...i, sendMsg: msg => this.sendGroupMsg(i, msg), - sendFile: (file, name) => this.sendFile(i, msg => this.sendGroupMsg(i, msg), file, name), + sendFile: (file, name) => this.sendGroupMsg(i, segment.file(file, name)), getInfo: () => this.getGroupInfo(i), getAvatarUrl: async () => (await this.getGroupInfo(i))["wx.avatar"], getMemberArray: () => this.getMemberArray(i), diff --git a/plugins/other/update.js b/plugins/other/update.js index ce65b26..70d75c2 100644 --- a/plugins/other/update.js +++ b/plugins/other/update.js @@ -204,7 +204,7 @@ export class update extends plugin { if (!logAll) return false - logAll = logAll.split('\n') + logAll = logAll.trim().split('\n') let log = [] for (let str of logAll) {