From e1027169ba4955d15d91036c2678df809e8d46a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8C=8C?= Date: Sun, 16 Jul 2023 08:55:31 +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 | 52 +++++++++++++++++++++------------------ package.json | 8 +++--- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/lib/modules/oicq/index.js b/lib/modules/oicq/index.js index f44d85f..1dc85ca 100644 --- a/lib/modules/oicq/index.js +++ b/lib/modules/oicq/index.js @@ -1,55 +1,59 @@ import fs from "node:fs" +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:\/\//, ""))) + data[i] = `base64://${fs.readFileSync(data[i].replace(/^file:\/\//, "")).toString("base64")}` + break + case "object": + if (Buffer.isBuffer(data[i])) + data[i] = `base64://${data[i].toString("base64")}` + } + } + return { type, ...data } +} + const segment = new class segment { custom(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:\/\//, ""))) - data[i] = `base64://${fs.readFileSync(data[i].replace(/^file:\/\//, "")).toString("base64")}` - break - case "object": - if (Buffer.isBuffer(data[i])) - data[i] = `base64://${data[i].toString("base64")}` - } - } - return { type, ...data } + return toSegment(type, data) } image(file) { - return this.custom("image", { file }) + return toSegment("image", { file }) } at(qq, name) { - return this.custom("at", { qq, name }) + return toSegment("at", { qq, name }) } record(file) { - return this.custom("record", { file }) + return toSegment("record", { file }) } video(file) { - return this.custom("video", { file }) + return toSegment("video", { file }) } reply(id, text, qq, time, seq) { - return this.custom("reply", { id, text, qq, time, seq }) + return toSegment("reply", { id, text, qq, time, seq }) } face(id) { - return this.custom("face", { id }) + return toSegment("face", { id }) } share(url, title, content, image) { - return this.custom("share", { url, title, content, image }) + return toSegment("share", { url, title, content, image }) } music(type, id, url, audio, title) { - return this.custom("music", { type, id, url, audio, title }) + return toSegment("music", { type, id, url, audio, title }) } poke(qq) { - return this.custom("poke", { qq }) + return toSegment("poke", { qq }) } gift(qq, id) { - return this.custom("gift", { qq, id }) + return toSegment("gift", { qq, id }) } cardimage(file, minwidth, minheight, maxwidth, maxheight, source, icon) { - return this.custom("cardimage", { file, minwidth, minheight, maxwidth, maxheight, source, icon }) + return toSegment("cardimage", { file, minwidth, minheight, maxwidth, maxheight, source, icon }) } tts(text) { - return this.custom("tts", { text }) + return toSegment("tts", { text }) } } diff --git a/package.json b/package.json index 8bd2d7a..0319386 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "chokidar": "^3.5.3", "express": "^4.18.2", "file-type": "^18.5.0", - "https-proxy-agent": "7.0.0", + "https-proxy-agent": "7.0.1", "image-size": "^1.0.2", "lodash": "^4.17.21", "log4js": "^6.9.1", @@ -32,7 +32,7 @@ "node-xlsx": "^0.23.0", "oicq": "link:lib/modules/oicq", "pm2": "^5.3.0", - "puppeteer": "^20.8.0", + "puppeteer": "^20.8.2", "redis": "^4.6.7", "sequelize": "^6.32.1", "sqlite3": "^5.1.6", @@ -40,7 +40,7 @@ "yaml": "^2.3.1" }, "devDependencies": { - "eslint": "^8.44.0", + "eslint": "^8.45.0", "eslint-config-standard": "^17.1.0", "eslint-plugin-import": "^2.27.5", "eslint-plugin-n": "^16.0.1", @@ -50,4 +50,4 @@ "#miao": "./plugins/miao-plugin/components/index.js", "#miao.models": "./plugins/miao-plugin/models/index.js" } -} \ No newline at end of file +}