SnowCat 雪猫底层全源码:NapCat 4.18.28 底座 + SnowLuma 能力移植 + V8 通道适配 9.9.37
26 包 monorepo(TS 全源码): - snowcat-core: NT 内核 API 封装 + listener(含 9.9.37 六回调适配)+ Packet 发包 - snowcat-onebot: OneBot v11 全动作 + MCP Streamable HTTP 适配器 + 稳定线 - snowcat-webui-frontend/backend: 雪猫控制台(React+HeroUI) - snowcat-shell: 单文件 bundle 出口(vite inlineDynamicImports) - snowcat-native: napi2native / MoeHoo / ffmpeg / pty 运行时 - 56 项 SnowLuma 独门动作移植(qzone 全家桶/群相册/装扮/闪照/收藏) - 工具件: 解包器/启动器/便携制作器/doctor GitHub 关联已全量指向 DandanLLab/SnowCatQQ
This commit is contained in:
commit
b9655a5ab1
1048 files changed
+130851
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import { SnowCatCore } from 'snowcat-core';
|
||||
import { SnowCatProtocolResponse } from '@/snowcat-protocol/types';
|
||||
|
||||
// 前向声明类型,避免循环依赖
|
||||
import type { SnowCatProtocolAdapter } from '@/snowcat-protocol/index';
|
||||
|
||||
// Action 基类
|
||||
export abstract class BaseAction<PayloadType = unknown, ReturnType = unknown> {
|
||||
abstract actionName: string;
|
||||
protected core: SnowCatCore;
|
||||
protected adapter: SnowCatProtocolAdapter;
|
||||
|
||||
constructor (adapter: SnowCatProtocolAdapter, core: SnowCatCore) {
|
||||
this.adapter = adapter;
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
protected abstract _handle (payload: PayloadType): Promise<ReturnType>;
|
||||
|
||||
async handle (payload: PayloadType): Promise<SnowCatProtocolResponse<ReturnType>> {
|
||||
try {
|
||||
const result = await this._handle(payload);
|
||||
return {
|
||||
status: 'ok',
|
||||
retcode: 0,
|
||||
data: result,
|
||||
};
|
||||
} catch (e) {
|
||||
return {
|
||||
status: 'failed',
|
||||
retcode: -1,
|
||||
data: null,
|
||||
message: e instanceof Error ? e.message : String(e),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Action 映射类型
|
||||
export type ActionMap = Map<string, BaseAction<unknown, unknown>>;
|
||||
|
||||
// 创建 Action 映射
|
||||
|
||||
export function createActionMap (_adapter: SnowCatProtocolAdapter, _core: SnowCatCore): ActionMap {
|
||||
const actionMap = new Map<string, BaseAction<unknown, unknown>>();
|
||||
|
||||
// 这里可以注册各种 Action
|
||||
// 例如: actionMap.set('send_msg', new SendMsgAction(adapter, core));
|
||||
|
||||
return actionMap;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { SnowCatCore } from 'snowcat-core';
|
||||
import { SnowCatProtocolAdapter } from '@/snowcat-protocol/index';
|
||||
|
||||
// NapCat Protocol API 基类
|
||||
export abstract class SnowCatProtocolApiBase {
|
||||
protected adapter: SnowCatProtocolAdapter;
|
||||
protected core: SnowCatCore;
|
||||
|
||||
constructor (adapter: SnowCatProtocolAdapter, core: SnowCatCore) {
|
||||
this.adapter = adapter;
|
||||
this.core = core;
|
||||
}
|
||||
}
|
||||
|
||||
// 消息 API
|
||||
export class SnowCatProtocolMsgApi extends SnowCatProtocolApiBase {
|
||||
// 消息相关 API 方法可以在这里实现
|
||||
}
|
||||
|
||||
// 用户 API
|
||||
export class SnowCatProtocolUserApi extends SnowCatProtocolApiBase {
|
||||
// 用户相关 API 方法可以在这里实现
|
||||
}
|
||||
|
||||
// 群组 API
|
||||
export class SnowCatProtocolGroupApi extends SnowCatProtocolApiBase {
|
||||
// 群组相关 API 方法可以在这里实现
|
||||
}
|
||||
|
||||
// 好友 API
|
||||
export class SnowCatProtocolFriendApi extends SnowCatProtocolApiBase {
|
||||
// 好友相关 API 方法可以在这里实现
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import { Type, Static } from '@sinclair/typebox';
|
||||
import { TypeCompiler } from '@sinclair/typebox/compiler';
|
||||
import { Value } from '@sinclair/typebox/value';
|
||||
|
||||
// WebSocket 服务端配置
|
||||
const WebsocketServerConfigSchema = Type.Object({
|
||||
name: Type.String({ default: 'snowcat-ws-server' }),
|
||||
enable: Type.Boolean({ default: false }),
|
||||
host: Type.String({ default: '127.0.0.1' }),
|
||||
port: Type.Number({ default: 6700 }),
|
||||
token: Type.String({ default: '' }),
|
||||
heartInterval: Type.Number({ default: 30000 }),
|
||||
debug: Type.Boolean({ default: false }),
|
||||
});
|
||||
|
||||
// WebSocket 客户端配置
|
||||
const WebsocketClientConfigSchema = Type.Object({
|
||||
name: Type.String({ default: 'snowcat-ws-client' }),
|
||||
enable: Type.Boolean({ default: false }),
|
||||
url: Type.String({ default: 'ws://localhost:6701' }),
|
||||
token: Type.String({ default: '' }),
|
||||
reconnectInterval: Type.Number({ default: 5000 }),
|
||||
heartInterval: Type.Number({ default: 30000 }),
|
||||
debug: Type.Boolean({ default: false }),
|
||||
});
|
||||
|
||||
// HTTP 服务端配置
|
||||
const HttpServerConfigSchema = Type.Object({
|
||||
name: Type.String({ default: 'snowcat-http-server' }),
|
||||
enable: Type.Boolean({ default: false }),
|
||||
host: Type.String({ default: '127.0.0.1' }),
|
||||
port: Type.Number({ default: 6702 }),
|
||||
token: Type.String({ default: '' }),
|
||||
enableCors: Type.Boolean({ default: true }),
|
||||
debug: Type.Boolean({ default: false }),
|
||||
});
|
||||
|
||||
// 网络配置
|
||||
const NetworkConfigSchema = Type.Object({
|
||||
httpServers: Type.Array(HttpServerConfigSchema, { default: [] }),
|
||||
websocketServers: Type.Array(WebsocketServerConfigSchema, { default: [] }),
|
||||
websocketClients: Type.Array(WebsocketClientConfigSchema, { default: [] }),
|
||||
}, { default: {} });
|
||||
|
||||
// NapCat Protocol 主配置 - 默认关闭
|
||||
export const SnowCatProtocolConfigSchema = Type.Object({
|
||||
enable: Type.Boolean({ default: false }), // 默认关闭
|
||||
network: NetworkConfigSchema,
|
||||
});
|
||||
|
||||
export type SnowCatProtocolConfig = Static<typeof SnowCatProtocolConfigSchema>;
|
||||
export type HttpServerConfig = Static<typeof HttpServerConfigSchema>;
|
||||
export type WebsocketServerConfig = Static<typeof WebsocketServerConfigSchema>;
|
||||
export type WebsocketClientConfig = Static<typeof WebsocketClientConfigSchema>;
|
||||
|
||||
export type NetworkAdapterConfig = HttpServerConfig | WebsocketServerConfig | WebsocketClientConfig;
|
||||
export type NetworkConfigKey = keyof SnowCatProtocolConfig['network'];
|
||||
|
||||
export function loadConfig (config: Partial<SnowCatProtocolConfig>): SnowCatProtocolConfig {
|
||||
let data = config;
|
||||
data = Value.Parse(SnowCatProtocolConfigSchema, data) as Partial<SnowCatProtocolConfig>;
|
||||
const validate = TypeCompiler.Compile(SnowCatProtocolConfigSchema);
|
||||
const valid = validate.Check(data);
|
||||
if (!valid) {
|
||||
const errorMsg = [...validate.Errors(data)].map(e => e.message).join(', ');
|
||||
throw new Error(errorMsg);
|
||||
}
|
||||
return data as SnowCatProtocolConfig;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { ConfigBase, SnowCatCore } from 'snowcat-core';
|
||||
|
||||
import { SnowCatProtocolConfig, SnowCatProtocolConfigSchema } from './config';
|
||||
|
||||
export class SnowCatProtocolConfigLoader extends ConfigBase<SnowCatProtocolConfig> {
|
||||
constructor (core: SnowCatCore, configPath: string) {
|
||||
super('napcat_protocol', core, configPath, SnowCatProtocolConfigSchema);
|
||||
}
|
||||
}
|
||||
|
||||
export * from './config';
|
||||
@@ -0,0 +1,66 @@
|
||||
import { SnowCatCore } from 'snowcat-core';
|
||||
|
||||
// NapCat Protocol 事件基类
|
||||
export abstract class SnowCatProtocolEvent {
|
||||
protected core: SnowCatCore;
|
||||
public time: number;
|
||||
public self_id: number;
|
||||
public post_type: string;
|
||||
|
||||
constructor (core: SnowCatCore) {
|
||||
this.core = core;
|
||||
this.time = Math.floor(Date.now() / 1000);
|
||||
this.self_id = parseInt(core.selfInfo.uin);
|
||||
this.post_type = 'event';
|
||||
}
|
||||
|
||||
abstract toJSON (): Record<string, unknown>;
|
||||
}
|
||||
|
||||
// 消息事件基类
|
||||
export abstract class SnowCatProtocolMessageEvent extends SnowCatProtocolEvent {
|
||||
public message_type: 'private' | 'group';
|
||||
public message_id: number;
|
||||
public user_id: number;
|
||||
|
||||
constructor (core: SnowCatCore, messageType: 'private' | 'group', messageId: number, userId: number) {
|
||||
super(core);
|
||||
this.post_type = 'message';
|
||||
this.message_type = messageType;
|
||||
this.message_id = messageId;
|
||||
this.user_id = userId;
|
||||
}
|
||||
}
|
||||
|
||||
// 通知事件基类
|
||||
export abstract class SnowCatProtocolNoticeEvent extends SnowCatProtocolEvent {
|
||||
public notice_type: string;
|
||||
|
||||
constructor (core: SnowCatCore, noticeType: string) {
|
||||
super(core);
|
||||
this.post_type = 'notice';
|
||||
this.notice_type = noticeType;
|
||||
}
|
||||
}
|
||||
|
||||
// 请求事件基类
|
||||
export abstract class SnowCatProtocolRequestEvent extends SnowCatProtocolEvent {
|
||||
public request_type: string;
|
||||
|
||||
constructor (core: SnowCatCore, requestType: string) {
|
||||
super(core);
|
||||
this.post_type = 'request';
|
||||
this.request_type = requestType;
|
||||
}
|
||||
}
|
||||
|
||||
// 元事件基类
|
||||
export abstract class SnowCatProtocolMetaEvent extends SnowCatProtocolEvent {
|
||||
public meta_event_type: string;
|
||||
|
||||
constructor (core: SnowCatCore, metaEventType: string) {
|
||||
super(core);
|
||||
this.post_type = 'meta_event';
|
||||
this.meta_event_type = metaEventType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './SnowCatProtocolEvent';
|
||||
@@ -0,0 +1,104 @@
|
||||
import {
|
||||
InstanceContext,
|
||||
SnowCatCore,
|
||||
} from 'snowcat-core';
|
||||
import { SnowCatProtocolConfigLoader, SnowCatProtocolConfig } from '@/snowcat-protocol/config';
|
||||
import { SnowCatPathWrapper } from 'snowcat-common/src/path';
|
||||
import {
|
||||
SnowCatProtocolNetworkManager,
|
||||
} from '@/snowcat-protocol/network';
|
||||
import {
|
||||
SnowCatProtocolMsgApi,
|
||||
SnowCatProtocolUserApi,
|
||||
SnowCatProtocolGroupApi,
|
||||
SnowCatProtocolFriendApi,
|
||||
} from '@/snowcat-protocol/api';
|
||||
import { ActionMap, createActionMap } from '@/snowcat-protocol/action';
|
||||
|
||||
interface ApiListType {
|
||||
MsgApi: SnowCatProtocolMsgApi;
|
||||
UserApi: SnowCatProtocolUserApi;
|
||||
GroupApi: SnowCatProtocolGroupApi;
|
||||
FriendApi: SnowCatProtocolFriendApi;
|
||||
}
|
||||
|
||||
// NapCat Protocol 适配器 - NapCat 私有 Bot 协议实现
|
||||
export class SnowCatProtocolAdapter {
|
||||
readonly core: SnowCatCore;
|
||||
readonly context: InstanceContext;
|
||||
|
||||
configLoader: SnowCatProtocolConfigLoader;
|
||||
public apis: ApiListType;
|
||||
networkManager: SnowCatProtocolNetworkManager;
|
||||
actions: ActionMap;
|
||||
|
||||
constructor (core: SnowCatCore, context: InstanceContext, pathWrapper: SnowCatPathWrapper) {
|
||||
this.core = core;
|
||||
this.context = context;
|
||||
this.configLoader = new SnowCatProtocolConfigLoader(core, pathWrapper.configPath);
|
||||
this.apis = {
|
||||
MsgApi: new SnowCatProtocolMsgApi(this, core),
|
||||
UserApi: new SnowCatProtocolUserApi(this, core),
|
||||
GroupApi: new SnowCatProtocolGroupApi(this, core),
|
||||
FriendApi: new SnowCatProtocolFriendApi(this, core),
|
||||
} as const;
|
||||
this.actions = createActionMap(this, core);
|
||||
this.networkManager = new SnowCatProtocolNetworkManager();
|
||||
}
|
||||
|
||||
// 检查协议是否启用
|
||||
isEnabled (): boolean {
|
||||
return this.configLoader.configData.enable;
|
||||
}
|
||||
|
||||
async createProtocolLog (config: SnowCatProtocolConfig) {
|
||||
let log = '[SnowCat Protocol] 配置加载\n';
|
||||
log += `协议状态: ${config.enable ? '已启用' : '已禁用'}\n`;
|
||||
|
||||
if (config.enable) {
|
||||
for (const key of config.network.httpServers) {
|
||||
log += `HTTP服务: ${key.host}:${key.port}, : ${key.enable ? '已启动' : '未启动'}\n`;
|
||||
}
|
||||
for (const key of config.network.websocketServers) {
|
||||
log += `WebSocket服务: ${key.host}:${key.port}, : ${key.enable ? '已启动' : '未启动'}\n`;
|
||||
}
|
||||
for (const key of config.network.websocketClients) {
|
||||
log += `WebSocket客户端: ${key.url}, : ${key.enable ? '已启动' : '未启动'}\n`;
|
||||
}
|
||||
}
|
||||
return log;
|
||||
}
|
||||
|
||||
async initProtocol () {
|
||||
const config = this.configLoader.configData;
|
||||
|
||||
// 如果协议未启用,直接返回
|
||||
if (!config.enable) {
|
||||
this.context.logger.log('[SnowCat Protocol] 协议未启用,跳过初始化');
|
||||
return;
|
||||
}
|
||||
|
||||
const selfInfo = this.core.selfInfo;
|
||||
const serviceInfo = await this.createProtocolLog(config);
|
||||
this.context.logger.log(`[Notice] ${serviceInfo}`);
|
||||
|
||||
// 注册网络适配器
|
||||
// 这里可以根据配置注册不同的网络适配器
|
||||
// 例如: WebSocket Server, WebSocket Client, HTTP Server 等
|
||||
|
||||
await this.networkManager.openAllAdapters();
|
||||
|
||||
this.context.logger.log(`[SnowCat Protocol] 初始化完成,Bot: ${selfInfo.uin}`);
|
||||
}
|
||||
|
||||
async close () {
|
||||
await this.networkManager.closeAllAdapters();
|
||||
this.context.logger.log('[SnowCat Protocol] 已关闭所有网络适配器');
|
||||
}
|
||||
}
|
||||
|
||||
export * from './types/index';
|
||||
export * from './api/index';
|
||||
export * from './event/index';
|
||||
export * from './config/index';
|
||||
export * from './network/index';
|
||||
@@ -0,0 +1,37 @@
|
||||
import { NetworkAdapterConfig } from '@/snowcat-protocol/config/config';
|
||||
import { LogWrapper } from 'snowcat-core/helper/log';
|
||||
import { SnowCatCore } from 'snowcat-core';
|
||||
import { SnowCatProtocolAdapter } from '@/snowcat-protocol/index';
|
||||
import { ActionMap } from '@/snowcat-protocol/action';
|
||||
import { SnowCatProtocolEmitEventContent, SnowCatProtocolNetworkReloadType } from '@/snowcat-protocol/network/index';
|
||||
|
||||
export abstract class INapCatProtocolNetworkAdapter<CT extends NetworkAdapterConfig> {
|
||||
name: string;
|
||||
isEnable: boolean = false;
|
||||
config: CT;
|
||||
readonly logger: LogWrapper;
|
||||
readonly core: SnowCatCore;
|
||||
readonly protocolContext: SnowCatProtocolAdapter;
|
||||
readonly actions: ActionMap;
|
||||
|
||||
constructor (name: string, config: CT, core: SnowCatCore, protocolContext: SnowCatProtocolAdapter, actions: ActionMap) {
|
||||
this.name = name;
|
||||
this.config = structuredClone(config);
|
||||
this.core = core;
|
||||
this.protocolContext = protocolContext;
|
||||
this.actions = actions;
|
||||
this.logger = core.context.logger;
|
||||
}
|
||||
|
||||
abstract onEvent<T extends SnowCatProtocolEmitEventContent> (event: T): Promise<void>;
|
||||
|
||||
abstract open (): void | Promise<void>;
|
||||
|
||||
abstract close (): void | Promise<void>;
|
||||
|
||||
abstract reload (config: unknown): SnowCatProtocolNetworkReloadType | Promise<SnowCatProtocolNetworkReloadType>;
|
||||
|
||||
get isActive (): boolean {
|
||||
return this.isEnable;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
import { SnowCatProtocolEvent } from '@/snowcat-protocol/event/SnowCatProtocolEvent';
|
||||
import { SnowCatProtocolMessage } from '@/snowcat-protocol/types';
|
||||
import { NetworkAdapterConfig } from '@/snowcat-protocol/config/config';
|
||||
import { INapCatProtocolNetworkAdapter } from '@/snowcat-protocol/network/adapter';
|
||||
|
||||
export type SnowCatProtocolEmitEventContent = SnowCatProtocolEvent | SnowCatProtocolMessage;
|
||||
|
||||
export enum SnowCatProtocolNetworkReloadType {
|
||||
Normal = 0,
|
||||
ConfigChange = 1,
|
||||
NetWorkReload = 2,
|
||||
NetWorkClose = 3,
|
||||
NetWorkOpen = 4,
|
||||
}
|
||||
|
||||
export class SnowCatProtocolNetworkManager {
|
||||
adapters: Map<string, INapCatProtocolNetworkAdapter<NetworkAdapterConfig>> = new Map();
|
||||
|
||||
async openAllAdapters () {
|
||||
return Promise.all(Array.from(this.adapters.values()).map(adapter => adapter.open()));
|
||||
}
|
||||
|
||||
async emitEvent (event: SnowCatProtocolEmitEventContent) {
|
||||
return Promise.all(Array.from(this.adapters.values()).map(async adapter => {
|
||||
if (adapter.isActive) {
|
||||
return await adapter.onEvent(event);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
async emitEvents (events: SnowCatProtocolEmitEventContent[]) {
|
||||
return Promise.all(events.map(event => this.emitEvent(event)));
|
||||
}
|
||||
|
||||
async emitEventByName (names: string[], event: SnowCatProtocolEmitEventContent) {
|
||||
return Promise.all(names.map(async name => {
|
||||
const adapter = this.adapters.get(name);
|
||||
if (adapter && adapter.isActive) {
|
||||
return await adapter.onEvent(event);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
async emitEventByNames (map: Map<string, SnowCatProtocolEmitEventContent>) {
|
||||
return Promise.all(Array.from(map.entries()).map(async ([name, event]) => {
|
||||
const adapter = this.adapters.get(name);
|
||||
if (adapter && adapter.isActive) {
|
||||
return await adapter.onEvent(event);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
registerAdapter<CT extends NetworkAdapterConfig> (adapter: INapCatProtocolNetworkAdapter<CT>) {
|
||||
this.adapters.set(adapter.name, adapter);
|
||||
}
|
||||
|
||||
async registerAdapterAndOpen<CT extends NetworkAdapterConfig> (adapter: INapCatProtocolNetworkAdapter<CT>) {
|
||||
this.registerAdapter(adapter);
|
||||
await adapter.open();
|
||||
}
|
||||
|
||||
async closeSomeAdapters<CT extends NetworkAdapterConfig> (adaptersToClose: INapCatProtocolNetworkAdapter<CT>[]) {
|
||||
for (const adapter of adaptersToClose) {
|
||||
this.adapters.delete(adapter.name);
|
||||
await adapter.close();
|
||||
}
|
||||
}
|
||||
|
||||
async closeSomeAdapterWhenOpen<CT extends NetworkAdapterConfig> (adaptersToClose: INapCatProtocolNetworkAdapter<CT>[]) {
|
||||
for (const adapter of adaptersToClose) {
|
||||
this.adapters.delete(adapter.name);
|
||||
if (adapter.isEnable) {
|
||||
await adapter.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
findSomeAdapter (name: string) {
|
||||
return this.adapters.get(name);
|
||||
}
|
||||
|
||||
async closeAdapterByPredicate (closeFilter: (adapter: INapCatProtocolNetworkAdapter<NetworkAdapterConfig>) => boolean) {
|
||||
const adaptersToClose = Array.from(this.adapters.values()).filter(closeFilter);
|
||||
await this.closeSomeAdapters(adaptersToClose);
|
||||
}
|
||||
|
||||
async closeAllAdapters () {
|
||||
await Promise.all(Array.from(this.adapters.values()).map(adapter => adapter.close()));
|
||||
this.adapters.clear();
|
||||
}
|
||||
|
||||
async reloadAdapter<T> (name: string, config: T) {
|
||||
const adapter = this.adapters.get(name);
|
||||
if (adapter) {
|
||||
await adapter.reload(config);
|
||||
}
|
||||
}
|
||||
|
||||
async reloadSomeAdapters<T> (configMap: Map<string, T>) {
|
||||
await Promise.all(Array.from(configMap.entries()).map(([name, config]) => this.reloadAdapter(name, config)));
|
||||
}
|
||||
|
||||
hasActiveAdapters (): boolean {
|
||||
return Array.from(this.adapters.values()).some(adapter => adapter.isActive);
|
||||
}
|
||||
|
||||
async getAllConfig () {
|
||||
return Array.from(this.adapters.values()).map(adapter => adapter.config);
|
||||
}
|
||||
}
|
||||
|
||||
export * from './adapter';
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "snowcat-protocol",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "index.ts",
|
||||
"scripts": {
|
||||
"typecheck": "tsc --noEmit --skipLibCheck -p tsconfig.json"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./index.ts"
|
||||
},
|
||||
"./*": {
|
||||
"import": "./*"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@sinclair/typebox": "^0.34.38",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^5.0.0",
|
||||
"json5": "^2.2.3",
|
||||
"snowcat-common": "workspace:*",
|
||||
"snowcat-core": "workspace:*",
|
||||
"ws": "^8.18.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/cors": "^2.8.17",
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/node": "^22.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"include": [
|
||||
"*.ts",
|
||||
"**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// NapCat Protocol 消息类型定义
|
||||
|
||||
export interface SnowCatProtocolMessage {
|
||||
post_type: 'message' | 'notice' | 'request' | 'meta_event';
|
||||
time: number;
|
||||
self_id: number;
|
||||
message_type?: 'private' | 'group';
|
||||
sub_type?: string;
|
||||
message_id?: number;
|
||||
user_id?: number;
|
||||
group_id?: number;
|
||||
message?: SnowCatProtocolMessageSegment[] | string;
|
||||
raw_message?: string;
|
||||
sender?: SnowCatProtocolSender;
|
||||
}
|
||||
|
||||
export interface SnowCatProtocolMessageSegment {
|
||||
type: string;
|
||||
data: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface SnowCatProtocolSender {
|
||||
user_id: number;
|
||||
nickname: string;
|
||||
card?: string;
|
||||
sex?: 'male' | 'female' | 'unknown';
|
||||
age?: number;
|
||||
area?: string;
|
||||
level?: string;
|
||||
role?: 'owner' | 'admin' | 'member';
|
||||
title?: string;
|
||||
}
|
||||
|
||||
// API 请求类型
|
||||
export interface SnowCatProtocolRequest {
|
||||
action: string;
|
||||
params?: Record<string, unknown>;
|
||||
echo?: string | number;
|
||||
}
|
||||
|
||||
// API 响应类型
|
||||
export interface SnowCatProtocolResponse<T = unknown> {
|
||||
status: 'ok' | 'failed';
|
||||
retcode: number;
|
||||
data: T | null;
|
||||
message?: string;
|
||||
echo?: string | number;
|
||||
}
|
||||
|
||||
// 心跳事件
|
||||
export interface SnowCatProtocolHeartbeat {
|
||||
post_type: 'meta_event';
|
||||
meta_event_type: 'heartbeat';
|
||||
time: number;
|
||||
self_id: number;
|
||||
status: {
|
||||
online: boolean;
|
||||
good: boolean;
|
||||
};
|
||||
interval: number;
|
||||
}
|
||||
|
||||
// 生命周期事件
|
||||
export interface SnowCatProtocolLifecycle {
|
||||
post_type: 'meta_event';
|
||||
meta_event_type: 'lifecycle';
|
||||
time: number;
|
||||
self_id: number;
|
||||
sub_type: 'connect' | 'enable' | 'disable';
|
||||
}
|
||||
Reference in new issue
Block a user