@kotori-bot/kotori-plugin-adapter-onebot
Version:
Adapter For Onebot 11
75 lines (74 loc) • 2.59 kB
JavaScript
/**
* @Package @kotori-bot/kotori-plugin-adapter-onebot
* @Version 2.1.1
* @Author Hotaru <me@hotaru.icu>
* @Copyright 2024-2025 Hotaru. All rights reserved.
* @License GPL-3.0
* @Link https://github.com/kotorijs/kotori
* @Date 2026/2/14 21:24:52
*/
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var elements_exports = {};
__export(elements_exports, {
OnebotElements: () => OnebotElements,
default: () => elements_default
});
module.exports = __toCommonJS(elements_exports);
var import_kotori_bot = require("kotori-bot");
class OnebotElements extends import_kotori_bot.Elements {
getSupportsElements() {
return ["mention", "mentionAll", "image", "voice", "video", "text", "reply"];
}
decode(message) {
if (typeof message === "string") return message;
if (!(message instanceof import_kotori_bot.MessageSingle)) {
return Array.from(message).map((el) => this.decode(el)).join("");
}
switch (message.data.type) {
case "text":
return message.toString();
case "image":
return this.cq("image", `file=${message.data.content},cache=0`);
case "voice":
return this.cq("record", `file=${message.data.content}`);
case "video":
return this.cq("video", `file=${message.data.content}`);
case "mention":
return this.cq("at", `qq=${message.data.userId}`);
case "mentionAll":
return this.cq("at", "qq=all");
case "reply":
return this.cq("reply", `id=${message.data.messageId}`);
default:
return "";
}
}
encode(raw) {
return new import_kotori_bot.MessageSingle("text", { text: raw });
}
cq(type, data) {
return `[CQ:${type},${data}]`;
}
}
var elements_default = OnebotElements;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
OnebotElements
});