chore: initial commit

This commit is contained in:
2026-10-22 17:07:08 +08:00
commit 0acef64f48
200 changed files with 35546 additions and 0 deletions
@@ -0,0 +1,47 @@
import {MinecraftJsonParser} from '../../../../utils/message_json_parser.ts';
import type {Json} from '../../../../types/bot/workflow/workflow.ts';
import type {WorkflowEventTemplate} from '../../../../types/bot/workflow/metadata.ts';
import {assert_json} from '../../runtime/value.ts';
import {describe, output} from '../../metadata.ts';
export const config_template: WorkflowEventTemplate = {
name: 'message', version: '1.0.0', readiness: 'spawned',
i18n: describe('消息事件', '接收聊天或系统消息,将原始文本组件解析为用户名、消息和完整纯文本。'),
config: [],
output: {
...output('object', '消息数据', '解析后的消息内容和协议附加信息。'),
properties: {
event: output('string', '事件名称', '固定为 message。'),
username: output('string', '用户名', '从消息文本提取的用户名;无法识别时为空字符串。'),
message: output('string', '消息内容', '去除已识别用户名后的消息;无法识别时为裁剪首尾空白的纯文本。'),
plainText: output('string', '完整纯文本', '展开翻译和文本组件后得到的完整消息文本。'),
position: output('string', '显示位置', '协议提供的字符串位置;缺失或类型不符时为空字符串。'),
sender: {...output('string', '发送者', '协议提供的发送者标识;缺失或类型不符时为 null。'), nullable: true},
verified: {...output('boolean', '签名验证', '协议提供的验证结果;缺失或类型不符时为 null。'), nullable: true},
},
},
};
export function parse_message_trigger(args: unknown[]): Record<string, Json> | undefined {
try {
if (args.length > 32) return;
let component = args[0];
if (component && typeof component === 'object' && !Array.isArray(component)) {
const json = Object.getOwnPropertyDescriptor(component, 'json');
if (json && 'value' in json) component = json.value;
}
assert_json(component);
if (Buffer.byteLength(JSON.stringify(component)) > 65_536) return;
const parsed = MinecraftJsonParser.parse(component);
const trigger: Record<string, Json> = {
event: 'message', username: parsed.username, message: parsed.message, plainText: parsed.plainText,
position: typeof args[1] === 'string' ? args[1] : '',
sender: typeof args[2] === 'string' ? args[2] : null,
verified: typeof args[3] === 'boolean' ? args[3] : null,
};
assert_json(trigger);
if (Buffer.byteLength(JSON.stringify(trigger)) <= 65_536) return trigger;
} catch { /* Malformed or non-JSON message payloads are not workflow inputs. */ }
}
export const normalize = parse_message_trigger;