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
69 lines
2.4 KiB
TypeScript
69 lines
2.4 KiB
TypeScript
import { OneBotAction } from '@/snowcat-onebot/action/OneBotAction';
|
|
import { ChatType, Peer } from 'snowcat-core/types';
|
|
import { ActionName } from '@/snowcat-onebot/action/router';
|
|
import { MessageUnique } from 'snowcat-common/src/message-unique';
|
|
import { Static, Type } from '@sinclair/typebox';
|
|
|
|
const PayloadSchema = Type.Object({
|
|
message_id: Type.Union([Type.Number(), Type.String()], { description: '消息ID' }),
|
|
group_id: Type.Optional(Type.String({ description: '目标群号' })),
|
|
user_id: Type.Optional(Type.String({ description: '目标用户QQ' })),
|
|
});
|
|
|
|
type PayloadType = Static<typeof PayloadSchema>;
|
|
|
|
const ReturnSchema = Type.Null({ description: '操作结果' });
|
|
|
|
type ReturnType = Static<typeof ReturnSchema>;
|
|
|
|
class ForwardSingleMsg extends OneBotAction<PayloadType, ReturnType> {
|
|
override actionSummary = '转发单条消息';
|
|
override actionDescription = '转发单条消息';
|
|
override actionTags = ['消息接口'];
|
|
override payloadExample = {
|
|
message_id: 12345,
|
|
group_id: '123456',
|
|
};
|
|
|
|
override returnExample = null;
|
|
|
|
protected async getTargetPeer (payload: PayloadType): Promise<Peer> {
|
|
if (payload.user_id) {
|
|
const peerUid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
|
if (!peerUid) {
|
|
throw new Error(`无法找到私聊对象${payload.user_id}`);
|
|
}
|
|
return { chatType: ChatType.KCHATTYPEC2C, peerUid };
|
|
}
|
|
return { chatType: ChatType.KCHATTYPEGROUP, peerUid: payload.group_id!.toString() };
|
|
}
|
|
|
|
async _handle (payload: PayloadType): Promise<null> {
|
|
const msg = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id);
|
|
if (!msg) {
|
|
throw new Error(`无法找到消息${payload.message_id}`);
|
|
}
|
|
const peer = await this.getTargetPeer(payload);
|
|
const ret = await this.core.apis.MsgApi.forwardMsg(msg.Peer,
|
|
peer,
|
|
[msg.MsgId]
|
|
);
|
|
if (ret.result !== 0) {
|
|
throw new Error(`转发消息失败 ${ret.errMsg}`);
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export class ForwardFriendSingleMsg extends ForwardSingleMsg {
|
|
override payloadSchema = PayloadSchema;
|
|
override returnSchema = ReturnSchema;
|
|
override actionName = ActionName.ForwardFriendSingleMsg;
|
|
}
|
|
|
|
export class ForwardGroupSingleMsg extends ForwardSingleMsg {
|
|
override payloadSchema = PayloadSchema;
|
|
override returnSchema = ReturnSchema;
|
|
override actionName = ActionName.ForwardGroupSingleMsg;
|
|
}
|