@kotori-bot/kotori-plugin-adapter-sandbox
Version:
Kotori modules test environment,a visual sandbox
92 lines (91 loc) • 3.32 kB
JavaScript
/**
* @Package @kotori-bot/kotori-plugin-adapter-sandbox
* @Version 1.1.1
* @Author Hotaru <me@hotaru.icu>
* @Copyright 2024-2025 Hotaru. All rights reserved.
* @License BAN-ZHINESE-USING
* @Link https://github.com/kotorijs/kotori
* @Date 2025/8/4 17:29:40
*/
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var adapter_exports = {};
__export(adapter_exports, {
SandboxAdapter: () => SandboxAdapter,
config: () => config,
default: () => adapter_default
});
module.exports = __toCommonJS(adapter_exports);
var import_kotori_bot = require("kotori-bot");
var import_api = __toESM(require("./api"));
var import_elements = __toESM(require("./elements"));
var import_type = require("./type");
const config = import_kotori_bot.Tsu.Object({});
class SandboxAdapter extends import_kotori_bot.Adapters.WebSocket {
wsSend;
config;
api = new import_api.default(this);
elements = new import_elements.default(this);
platform = "sandbox";
constructor(ctx, config2, identity) {
super(ctx, config2, identity);
this.config = config2;
this.connection = (ws) => {
this.wsSend = ws.send.bind(ws);
this.online();
ws.on("close", () => this.offline());
};
}
handle(data) {
if ("response" in data) {
const result2 = import_type.responseSchema.safeParse(data);
if (result2.success) {
this.ctx.emit("literal_sandbox_response", result2.data);
} else {
this.send({ action: "on_data_error", error: result2.error.message });
}
return;
}
const result = import_type.eventDataSchema.safeParse(data);
if (result.success) {
this.session(result.data.event, result.data);
} else {
this.send({ action: "on_data_error", error: result.error.message });
}
}
send(data) {
this.wsSend?.(JSON.stringify(data));
}
}
var adapter_default = SandboxAdapter;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
SandboxAdapter,
config
});