From d085cb4d10599d8d39243783a637a8c4cc877582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8C=8C?= Date: Sun, 9 Jul 2023 00:58:50 +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 --- CHANGELOG.md | 1 - README.md | 1 - lib/modules/oicq/index.js | 56 +++++++++++++++++++++++++++++++++++ lib/modules/oicq/package.json | 5 ++++ lib/plugins/loader.js | 35 ++-------------------- package.json | 1 + 6 files changed, 64 insertions(+), 35 deletions(-) create mode 100644 lib/modules/oicq/index.js create mode 100644 lib/modules/oicq/package.json diff --git a/CHANGELOG.md b/CHANGELOG.md index a3d3aad..940b0ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,6 @@ # 3.0.1 * 支持多账号,支持协议端:go-cqhttp -* 由于完全删除了 OICQ,并且内置 `segment`,若插件缺少 OICQ,需删除 `import { segment } from "oicq"` # 3.0.0 diff --git a/README.md b/README.md index ad6fc65..e700fa1 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,6 @@ Yunzai 应用端,支持多账号,支持协议端:go-cqhttp、ComWeChat、G - 基于 [Miao-Yunzai](../../../../yoimiya-kokomi/Miao-Yunzai) 改造,需要同时安装 [miao-plugin](../../../../yoimiya-kokomi/miao-plugin) -- 由于完全删除了 OICQ,并且内置 `segment`,若插件缺少 OICQ,需删除 `import { segment } from "oicq"` - 开发文档:[docs 分支](../../tree/docs) ## TRSS-Yunzai 后续计划 diff --git a/lib/modules/oicq/index.js b/lib/modules/oicq/index.js new file mode 100644 index 0000000..f44d85f --- /dev/null +++ b/lib/modules/oicq/index.js @@ -0,0 +1,56 @@ +import fs from "node:fs" + +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 } + } + image(file) { + return this.custom("image", { file }) + } + at(qq, name) { + return this.custom("at", { qq, name }) + } + record(file) { + return this.custom("record", { file }) + } + video(file) { + return this.custom("video", { file }) + } + reply(id, text, qq, time, seq) { + return this.custom("reply", { id, text, qq, time, seq }) + } + face(id) { + return this.custom("face", { id }) + } + share(url, title, content, image) { + return this.custom("share", { url, title, content, image }) + } + music(type, id, url, audio, title) { + return this.custom("music", { type, id, url, audio, title }) + } + poke(qq) { + return this.custom("poke", { qq }) + } + gift(qq, id) { + return this.custom("gift", { qq, id }) + } + cardimage(file, minwidth, minheight, maxwidth, maxheight, source, icon) { + return this.custom("cardimage", { file, minwidth, minheight, maxwidth, maxheight, source, icon }) + } + tts(text) { + return this.custom("tts", { text }) + } +} + +export { segment } \ No newline at end of file diff --git a/lib/modules/oicq/package.json b/lib/modules/oicq/package.json new file mode 100644 index 0000000..6e44b52 --- /dev/null +++ b/lib/modules/oicq/package.json @@ -0,0 +1,5 @@ +{ + "name": "oicq", + "type": "module", + "main": "index.js" +} \ No newline at end of file diff --git a/lib/plugins/loader.js b/lib/plugins/loader.js index 14a461e..d1b0942 100644 --- a/lib/plugins/loader.js +++ b/lib/plugins/loader.js @@ -4,6 +4,7 @@ import lodash from "lodash" import cfg from "../config/config.js" import plugin from "./plugin.js" import schedule from "node-schedule" +import { segment } from "oicq" import chokidar from "chokidar" import moment from "moment" import path from "node:path" @@ -12,39 +13,7 @@ import Runtime from "./runtime.js" /** 全局变量 plugin */ global.plugin = plugin - -function toSegment(type, data) { - for (const i in data) - if (data[i]) - 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 } -} - -global.segment = { - image: file => toSegment("image", { file }), - at: (qq, name) => toSegment("at", { qq, name }), - record: file => toSegment("record", { file }), - video: file => toSegment("video", { file }), - reply: (id, text, qq, time, seq) => toSegment("reply", { id, text, qq, time, seq }), - face: id => toSegment("face", { id }), - share: (url, title, content, image) => toSegment("share", { url, title, content, image }), - music: (type, id, url, audio, title) => toSegment("music", { type, id, url, audio, title }), - poke: qq => toSegment("poke", { qq }), - gift: (qq, id) => toSegment("gift", { qq, id }), - xml: (data, resid) => toSegment("xml", { data, resid }), - json: (data, resid) => toSegment("json", { data, resid }), - cardimage: (file, minwidth, minheight, maxwidth, maxheight, source, icon) => toSegment("cardimage", { file, minwidth, minheight, maxwidth, maxheight, source, icon }), - tts: text => toSegment("tts", { text }), - custom: toSegment, -} +global.segment = segment /** * 加载插件 diff --git a/package.json b/package.json index 271f363..8bd2d7a 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "node-fetch": "^3.3.1", "node-schedule": "^2.1.1", "node-xlsx": "^0.23.0", + "oicq": "link:lib/modules/oicq", "pm2": "^5.3.0", "puppeteer": "^20.8.0", "redis": "^4.6.7",