UNPKG

onebots

Version:

基于icqq的多例oneBot实现

68 lines (67 loc) 2.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.processMessages = processMessages; const shareMusicCustom_1 = require("./shareMusicCustom"); async function processMessages(uin, target_id, target_type, list) { if (!Array.isArray(list)) list = [list]; let result = []; for (let item of [].concat(list).filter(Boolean)) { if (typeof item === "string") item = { type: "text", text: item }; const { type, ...data } = item; switch (type) { case "node": { result.push({ type, ...data, user_id: data.user_id, message: await processMessages.call(this, uin, data.user_id, "private", data.message || []), }); break; } case "music": { if (String(item.platform) === "custom") { item.platform = item["subtype"]; // gocq 的平台数据存储在 subtype 内,兼容 icqq 时要求前端必须发送 id 字段 } await shareMusicCustom_1.shareMusic.call(this[target_type === "private" ? "pickFriend" : "pickGroup"](target_id), { type, ...data, }); break; } case "share": { await this[target_type === "private" ? "pickFriend" : "pickGroup"](target_id).shareUrl(data); break; } case "video": case "audio": case "image": { if (data["file"]?.startsWith("base64://")) data["file"] = Buffer.from(data["file"].slice(9), "base64"); result.push({ type: type, ...data, }); break; } case "reply": { const oneBot = this.getOneBot(uin); const message_id = oneBot.V11.getStrByInt("message_id", data.id); const msg = await oneBot.internal.getMsg(message_id); result.push({ type: "quote", ...msg, }); break; } default: { result.push({ type: type, ...data, }); } } } return result; }