细节优化

This commit is contained in:
🌌 2023-07-16 08:55:31 +08:00
parent d085cb4d10
commit e1027169ba
2 changed files with 32 additions and 28 deletions

View File

@ -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 })
}
}

View File

@ -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",