Feat/Implement QQ Online File/Folder and Flash Transfer support (#1541)

* feat: implement QQ online file transfer and flash transfer support

* fix: change OnlineFile OB11Message data

* fix: add fileSize and isDir to OB11MessageOnlineFile

* fix: resolve typescript strict mode errors
This commit is contained in:
H3CoF6 authored and GitHub committed 2026-01-22 17:44:09 +08:00
1 parent 772f07c58b
commit 75236dd50c
35 files changed
+1831 -23

No files matched your search

@@ -0,0 +1,24 @@
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
// 不全部使用json因为:一个文件解析Form-data会变字符串!!! 但是api文档就写List
const SchemaData = Type.Object({
files: Type.Union([
Type.Array(Type.String()),
Type.String(),
]),
});
type Payload = Static<typeof SchemaData>;
export class CreateFlashTask extends OneBotAction<Payload, unknown> {
override actionName = ActionName.CreateFlashTask;
override payloadSchema = SchemaData;
async _handle (payload: Payload) {
// todo fileset的名字和缩略图还没实现!!
const fileList = Array.isArray(payload.files) ? payload.files : [payload.files];
return await this.core.apis.FlashApi.createFlashTransferUploadTask(fileList);
}
}
@@ -0,0 +1,19 @@
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
fileset_id: Type.String(),
});
type Payload = Static<typeof SchemaData>;
export class DownloadFileset extends OneBotAction<Payload, unknown> {
override actionName = ActionName.DownloadFileset;
override payloadSchema = SchemaData;
async _handle (payload: Payload) {
// 默认路径 / fileset_id /为下载路径
return await this.core.apis.FlashApi.downloadFileSetBySetId(payload.fileset_id);
}
}
@@ -0,0 +1,20 @@
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
share_code: Type.String(),
});
type Payload = Static<typeof SchemaData>;
export class GetFilesetId extends OneBotAction<Payload, unknown> {
override actionName = ActionName.GetFilesetId;
override payloadSchema = SchemaData;
async _handle (payload: Payload) {
// 适配share_link 防止被传 Link无法解析
const code = payload.share_code.includes('=') ? payload.share_code.split('=').slice(1).join('=') : payload.share_code;
return await this.core.apis.FlashApi.fromShareLinkFindSetId(code);
}
}
@@ -0,0 +1,18 @@
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
fileset_id: Type.String(),
});
type Payload = Static<typeof SchemaData>;
export class GetFilesetInfo extends OneBotAction<Payload, unknown> {
override actionName = ActionName.GetFilesetInfo;
override payloadSchema = SchemaData;
async _handle (payload: Payload) {
return await this.core.apis.FlashApi.getFileSetIndoBySetId(payload.fileset_id);
}
}
@@ -0,0 +1,18 @@
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
fileset_id: Type.String(),
});
type Payload = Static<typeof SchemaData>;
export class GetFlashFileList extends OneBotAction<Payload, unknown> {
override actionName = ActionName.GetFlashFileList;
override payloadSchema = SchemaData;
async _handle (payload: Payload) {
return await this.core.apis.FlashApi.getFileListBySetId(payload.fileset_id);
}
}
@@ -0,0 +1,24 @@
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
fileset_id: Type.String(),
file_name: Type.Optional(Type.String()),
file_index: Type.Optional(Type.Number()),
});
type Payload = Static<typeof SchemaData>;
export class GetFlashFileUrl extends OneBotAction<Payload, unknown> {
override actionName = ActionName.GetFlashFileUrl;
override payloadSchema = SchemaData;
async _handle (payload: Payload) {
// 文件的索引依旧从0开始
return await this.core.apis.FlashApi.getFileTransUrl(payload.fileset_id, {
fileName: payload.file_name,
fileIndex: payload.file_index,
});
}
}
@@ -0,0 +1,18 @@
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
fileset_id: Type.String(),
});
type Payload = Static<typeof SchemaData>;
export class GetShareLink extends OneBotAction<Payload, unknown> {
override actionName = ActionName.GetShareLink;
override payloadSchema = SchemaData;
async _handle (payload: Payload) {
return await this.core.apis.FlashApi.getShareLinkBySetId(payload.fileset_id);
}
}
@@ -0,0 +1,39 @@
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
import { ChatType, Peer } from 'napcat-core/types';
const SchemaData = Type.Object({
fileset_id: Type.String(),
user_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
group_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
});
type Payload = Static<typeof SchemaData>;
export class SendFlashMsg extends OneBotAction<Payload, unknown> {
override actionName = ActionName.SendFlashMsg;
override payloadSchema = SchemaData;
async _handle (payload: Payload) {
let peer: Peer;
if (payload.group_id) {
peer = { chatType: ChatType.KCHATTYPEGROUP, peerUid: payload.group_id.toString() };
} else if (payload.user_id) {
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
if (!uid) throw new Error('User not found');
// 可能需要更严格的判断
const isBuddy = await this.core.apis.FriendApi.isBuddy(uid);
peer = {
chatType: isBuddy ? ChatType.KCHATTYPEC2C : ChatType.KCHATTYPETEMPC2CFROMGROUP,
peerUid: uid,
};
} else {
throw new Error('user_id or group_id is required');
}
return await this.core.apis.FlashApi.sendFlashMessage(payload.fileset_id, peer);
}
}
@@ -0,0 +1,26 @@
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
import { ChatType } from 'napcat-core/types';
const SchemaData = Type.Object({
user_id: Type.Union([Type.Number(), Type.String()]),
msg_id: Type.String(),
});
type Payload = Static<typeof SchemaData>;
export class CancelOnlineFile extends OneBotAction<Payload, unknown> {
override actionName = ActionName.CancelOnlineFile;
override payloadSchema = SchemaData;
async _handle (payload: Payload) {
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
if (!uid) throw new Error('User not found');
// 仅私聊
const peer = { chatType: ChatType.KCHATTYPEC2C, peerUid: uid };
return await this.core.apis.OnlineApi.cancelMyOnlineFileMsg(peer, payload.msg_id);
}
}
@@ -0,0 +1,25 @@
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
import { ChatType } from 'napcat-core/types';
const SchemaData = Type.Object({
user_id: Type.Union([Type.Number(), Type.String()]),
});
type Payload = Static<typeof SchemaData>;
export class GetOnlineFileMessages extends OneBotAction<Payload, unknown> {
override actionName = ActionName.GetOnlineFileMessages;
override payloadSchema = SchemaData;
async _handle (payload: Payload) {
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
if (!uid) throw new Error('User not found');
// 仅私聊
const peer = { chatType: ChatType.KCHATTYPEC2C, peerUid: uid };
return await this.core.apis.OnlineApi.getOnlineFileMsg(peer);
}
}
@@ -0,0 +1,27 @@
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
import { ChatType } from 'napcat-core/types';
const SchemaData = Type.Object({
user_id: Type.Union([Type.Number(), Type.String()]),
msg_id: Type.String(),
element_id: Type.String(),
});
type Payload = Static<typeof SchemaData>;
export class ReceiveOnlineFile extends OneBotAction<Payload, unknown> {
override actionName = ActionName.ReceiveOnlineFile;
override payloadSchema = SchemaData;
async _handle (payload: Payload) {
// 默认下载路径
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
if (!uid) throw new Error('User not found');
const peer = { chatType: ChatType.KCHATTYPEC2C, peerUid: uid };
return await this.core.apis.OnlineApi.receiveOnlineFileOrFolder(peer, payload.msg_id, payload.element_id);
}
}
@@ -0,0 +1,26 @@
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
import { ChatType } from 'napcat-core/types';
const SchemaData = Type.Object({
user_id: Type.Union([Type.Number(), Type.String()]),
msg_id: Type.String(),
element_id: Type.String(),
});
type Payload = Static<typeof SchemaData>;
export class RefuseOnlineFile extends OneBotAction<Payload, unknown> {
override actionName = ActionName.RefuseOnlineFile;
override payloadSchema = SchemaData;
async _handle (payload: Payload) {
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
if (!uid) throw new Error('User not found');
const peer = { chatType: ChatType.KCHATTYPEC2C, peerUid: uid };
return await this.core.apis.OnlineApi.refuseOnlineFileMsg(peer, payload.msg_id, payload.element_id);
}
}
@@ -0,0 +1,28 @@
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
import { ChatType } from 'napcat-core/types';
const SchemaData = Type.Object({
user_id: Type.Union([Type.Number(), Type.String()]),
file_path: Type.String(),
file_name: Type.Optional(Type.String()),
});
type Payload = Static<typeof SchemaData>;
export class SendOnlineFile extends OneBotAction<Payload, unknown> {
override actionName = ActionName.SendOnlineFile;
override payloadSchema = SchemaData;
async _handle (payload: Payload) {
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
if (!uid) throw new Error('User not found');
// 仅私聊
const peer = { chatType: ChatType.KCHATTYPEC2C, peerUid: uid };
const fileName = payload.file_name || '';
return await this.core.apis.OnlineApi.sendOnlineFile(peer, payload.file_path, fileName);
}
}
@@ -0,0 +1,26 @@
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
import { ChatType } from 'napcat-core/types';
const SchemaData = Type.Object({
user_id: Type.Union([Type.Number(), Type.String()]),
folder_path: Type.String(),
folder_name: Type.Optional(Type.String()),
});
type Payload = Static<typeof SchemaData>;
export class SendOnlineFolder extends OneBotAction<Payload, unknown> {
override actionName = ActionName.SendOnlineFolder;
override payloadSchema = SchemaData;
async _handle (payload: Payload) {
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
if (!uid) throw new Error('User not found');
const peer = { chatType: ChatType.KCHATTYPEC2C, peerUid: uid };
return await this.core.apis.OnlineApi.sendOnlineFolder(peer, payload.folder_path, payload.folder_name);
}
}
+29 -1
View File
@@ -66,9 +66,9 @@ import { FetchCustomFace } from './extends/FetchCustomFace';
import GoCQHTTPUploadPrivateFile from './go-cqhttp/UploadPrivateFile';
import { FetchEmojiLike } from './extends/FetchEmojiLike';
import { NapCatCore } from 'napcat-core';
import { NapCatOneBot11Adapter } from '@/napcat-onebot/index';
import type { NetworkAdapterConfig } from '../config/config';
import { OneBotAction } from './OneBotAction';
import { NapCatOneBot11Adapter } from '@/napcat-onebot';
import { SetInputStatus } from './extends/SetInputStatus';
import { GetCSRF } from './system/GetCSRF';
import { DelGroupNotice } from './group/DelGroupNotice';
@@ -140,6 +140,20 @@ import { DownloadFileImageStream } from './stream/DownloadFileImageStream';
import { TestDownloadStream } from './stream/TestStreamDownload';
import { UploadFileStream } from './stream/UploadFileStream';
import { AutoRegisterRouter } from './auto-register';
import { CreateFlashTask } from './file/flash/CreateFlashTask';
import { SendFlashMsg } from './file/flash/SendFlashMsg';
import { GetFlashFileList } from './file/flash/GetFlashFileList';
import { GetFlashFileUrl } from './file/flash/GetFlashFileUrl';
import { GetShareLink } from './file/flash/GetShareLink';
import { GetFilesetInfo } from './file/flash/GetFilesetInfo';
import { DownloadFileset } from './file/flash/DownloadFileset';
import { GetOnlineFileMessages } from './file/online/GetOnlineFileMessages';
import { SendOnlineFile } from './file/online/SendOnlineFile';
import { SendOnlineFolder } from './file/online/SendOnlineFolder';
import { CancelOnlineFile } from './file/online/CancelOnlineFile';
import { ReceiveOnlineFile } from './file/online/ReceiveOnlineFile';
import { RefuseOnlineFile } from './file/online/RefuseOnlineFile';
import { GetFilesetId } from './file/flash/GetFilesetIdByCode';
export function createActionMap (obContext: NapCatOneBot11Adapter, core: NapCatCore) {
const actionHandlers = [
@@ -293,6 +307,20 @@ export function createActionMap (obContext: NapCatOneBot11Adapter, core: NapCatC
new CleanCache(obContext, core),
new GetGroupAddRequest(obContext, core),
new GetCollectionList(obContext, core),
new CreateFlashTask(obContext, core),
new GetFlashFileList(obContext, core),
new GetFlashFileUrl(obContext, core),
new SendFlashMsg(obContext, core),
new GetShareLink(obContext, core),
new GetFilesetInfo(obContext, core),
new GetOnlineFileMessages(obContext, core),
new SendOnlineFile(obContext, core),
new SendOnlineFolder(obContext, core),
new ReceiveOnlineFile(obContext, core),
new RefuseOnlineFile(obContext, core),
new CancelOnlineFile(obContext, core),
new DownloadFileset(obContext, core),
new GetFilesetId(obContext, core),
];
type HandlerUnion = typeof actionHandlers[number];
+20 -2
View File
@@ -125,8 +125,8 @@ export const ActionName = {
// 以下为扩展napcat扩展
Unknown: 'unknown',
SetDiyOnlineStatus: 'set_diy_online_status',
SharePeer: 'ArkSharePeer',// @deprecated
ShareGroupEx: 'ArkShareGroup',// @deprecated
SharePeer: 'ArkSharePeer', // @deprecated
ShareGroupEx: 'ArkShareGroup', // @deprecated
// 标准化接口
SendGroupArkShare: 'send_group_ark_share',
SendArkShare: 'send_ark_share',
@@ -185,4 +185,22 @@ export const ActionName = {
GetClientkey: 'get_clientkey',
SendPoke: 'send_poke',
// Flash (闪传) 扩展
CreateFlashTask: 'create_flash_task',
SendFlashMsg: 'send_flash_msg', // 因为不可能手动构造element,所以不走sendMsg
GetShareLink: 'get_share_link',
DownloadFileset: 'download_fileset',
GetFilesetInfo: 'get_fileset_info',
GetFlashFileList: 'get_flash_file_list',
GetFlashFileUrl: 'get_flash_file_url',
GetFilesetId: 'get_fileset_id',
// Online File (在线文件) 扩展
SendOnlineFile: 'send_online_file',
SendOnlineFolder: 'send_online_folder',
GetOnlineFileMessages: 'get_online_file_msg',
ReceiveOnlineFile: 'receive_online_file',
RefuseOnlineFile: 'refuse_online_file',
CancelOnlineFile: 'cancel_online_file',
} as const;
+101 -7
View File
@@ -42,11 +42,18 @@ import { OB11GroupIncreaseEvent } from '../event/notice/OB11GroupIncreaseEvent';
import { GroupDecreaseSubType, OB11GroupDecreaseEvent } from '../event/notice/OB11GroupDecreaseEvent';
import { GroupAdmin } from 'napcat-core/packet/transformer/proto/message/groupAdmin';
import { OB11GroupAdminNoticeEvent } from '../event/notice/OB11GroupAdminNoticeEvent';
import { GroupChange, GroupChangeInfo, GroupInvite, PushMsgBody } from 'napcat-core/packet/transformer/proto';
import {
GroupChange,
GroupChangeInfo,
GroupInvite,
PushMsgBody,
} from 'napcat-core/packet/transformer/proto';
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest';
import { LRUCache } from 'napcat-common/src/lru-cache';
import { cleanTaskQueue } from 'napcat-common/src/clean-task';
import { registerResource } from 'napcat-common/src/health';
import { OB11OnlineFileReceiveEvent } from '@/napcat-onebot/event/notice/OB11OnlineFileReceiveEvent';
import { OB11OnlineFileSendEvent } from '@/napcat-onebot/event/notice/OB11OnlineFileSendEvent';
type RawToOb11Converters = {
[Key in keyof MessageElement as Key extends `${string}Element` ? Key : never]: (
@@ -143,6 +150,21 @@ export class OneBotMsgApi {
},
fileElement: async (element, msg, elementWrapper, { disableGetUrl }) => {
// 让在线文件/文件夹的消息单独出去(否则无法正确处理UUID!!!)
if (+elementWrapper.elementType === 23 || +elementWrapper.elementType === 30) {
// 判断为在线文件/文件夹
return {
type: OB11MessageDataType.onlinefile,
data: {
msgId: msg.msgId,
elementId: elementWrapper.elementId,
fileName: element.fileName,
fileSize: element.fileSize,
isDir: (elementWrapper.elementType === 30),
},
};
}
const peer = {
chatType: msg.chatType,
peerUid: msg.peerUid,
@@ -538,12 +560,22 @@ export class OneBotMsgApi {
},
markdownElement: async (element) => {
return {
type: OB11MessageDataType.markdown,
data: {
content: element.content,
},
};
// 让QQ闪传消息独立出去
if (element.mdExtInfo !== undefined && element.mdExtInfo.flashTransferInfo) {
return {
type: OB11MessageDataType.flashtransfer,
data: {
fileSetId: element.mdExtInfo.flashTransferInfo.filesetId,
},
};
} else {
return {
type: OB11MessageDataType.markdown,
data: {
content: element.content,
},
};
}
},
};
@@ -880,6 +912,10 @@ export class OneBotMsgApi {
}
return undefined;
},
// 不需要支持发送
[OB11MessageDataType.onlinefile]: async () => undefined,
[OB11MessageDataType.flashtransfer]: async () => undefined,
};
constructor (obContext: NapCatOneBot11Adapter, core: NapCatCore) {
@@ -1329,6 +1365,7 @@ export class OneBotMsgApi {
async parseSysMessage (msg: number[]) {
const SysMessage = new NapProtoMsg(PushMsgBody).decode(Uint8Array.from(msg));
// 邀请需要解grayTipElement
// console.log(SysMessage.body?.msgContent);
if (SysMessage.contentHead.type === 33 && SysMessage.body?.msgContent) {
const groupChange = new NapProtoMsg(GroupChange).decode(SysMessage.body.msgContent);
await this.core.apis.GroupApi.refreshGroupMemberCache(groupChange.groupUin.toString(), true);
@@ -1484,6 +1521,63 @@ export class OneBotMsgApi {
);
} else if (SysMessage.contentHead.type === 528 && SysMessage.contentHead.subType === 39 && SysMessage.body?.msgContent) {
return await this.obContext.apis.UserApi.parseLikeEvent(SysMessage.body?.msgContent);
} else if (SysMessage.contentHead.type === 166 && SysMessage.contentHead.c2CCmd === 133 && SysMessage.body?.msgContent) {
this.core.context.logger.logDebug('在线文件通道断开');
// 可能原因: 对方取消 对方拒绝 对方转离线
// body不是proto,只能手动提取,可能是错的!!
// console.log(SysMessage.body?.msgContent);
const mainCmd = SysMessage.body.msgContent[15];
const subCmd = SysMessage.body.msgContent[17];
if (mainCmd === 101) {
// 在线文件
if (subCmd === 225) {
// 对方取消或转离线
this.core.context.logger.log(`好友:${SysMessage.responseHead.fromUin}取消了在线文件的传输(或转离线)`);
return new OB11OnlineFileReceiveEvent(
this.core,
+SysMessage.responseHead.fromUin
);
} else if (subCmd === 230) {
// 对方拒绝接收
this.core.context.logger.log(`好友:${SysMessage.responseHead.fromUin}拒绝了你的在线文件传输`);
return new OB11OnlineFileSendEvent(
this.core,
+SysMessage.responseHead.fromUin,
'refuse'
);
}
} else if (mainCmd === 136) {
if (subCmd === 225) {
// 对方取消或转离线
this.core.context.logger.log(`好友:${SysMessage.responseHead.fromUin}取消了在线文件夹的传输(或转离线)`);
return new OB11OnlineFileReceiveEvent(
this.core,
+SysMessage.responseHead.fromUin
);
} else if (subCmd === 230) {
// 对方拒绝接收
this.core.context.logger.log(`好友:${SysMessage.responseHead.fromUin}拒绝了你的在线文件夹传输`);
return new OB11OnlineFileSendEvent(
this.core,
+SysMessage.responseHead.fromUin,
'refuse'
);
}
}
this.core.context.logger.logDebug('未知的系统消息事件:', mainCmd, subCmd);
return undefined;
} else if (SysMessage.contentHead.type === 166 && SysMessage.contentHead.c2CCmd === 131 && SysMessage.body?.msgContent) {
const mainCmd = SysMessage.body.msgContent[15];
if (mainCmd === 101) {
this.core.context.logger.log('在线文件传输成功!');
} else if (mainCmd === 136) {
this.core.context.logger.log('在线文件夹传输成功!');
}
return new OB11OnlineFileSendEvent(
this.core,
+SysMessage.responseHead.fromUin,
'receive'
);
}
// else if (SysMessage.contentHead.type == 732 && SysMessage.contentHead.subType == 16 && SysMessage.body?.msgContent) {
// let data_wrap = PBString(2);
@@ -0,0 +1,11 @@
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
import { NapCatCore } from 'napcat-core';
export abstract class OB11OnlineFileNoticeEvent extends OB11BaseNoticeEvent {
peer_id: number;
protected constructor (core: NapCatCore, peer_id: number) {
super(core);
this.peer_id = peer_id;
}
}
@@ -0,0 +1,13 @@
import { OB11OnlineFileNoticeEvent } from './OB11OnlineFileNoticeEvent';
import { NapCatCore } from '@/napcat-core';
export class OB11OnlineFileReceiveEvent extends OB11OnlineFileNoticeEvent {
notice_type: string;
sub_type: string;
constructor (core: NapCatCore, peer_id: number) {
super(core, peer_id);
this.notice_type = 'online_file_receive';
this.sub_type = 'cancel';
}
}
@@ -0,0 +1,12 @@
import { OB11OnlineFileNoticeEvent } from './OB11OnlineFileNoticeEvent';
import { NapCatCore } from '@/napcat-core';
export class OB11OnlineFileSendEvent extends OB11OnlineFileNoticeEvent {
notice_type = 'online_file_send';
sub_type: 'receive' | 'refuse';
constructor (core: NapCatCore, peer_id: number, sub_type: 'receive' | 'refuse') {
super(core, peer_id);
this.sub_type = sub_type;
}
}
+32
View File
@@ -328,6 +328,38 @@ export class NapCatOneBot11Adapter {
);
}
};
/**
* 加入在线文件的listener
*/
msgListener.onRecvOnlineFileMsg = async (msg: RawMessage[]) => {
if (!this.networkManager.hasActiveAdapters()) {
return;
}
for (const m of msg) {
// this.context.logger.logMessage(m, this.core.selfInfo);
if (this.bootTime > parseInt(m.msgTime)) {
this.context.logger.logDebug(`在线文件消息时间${m.msgTime}早于启动时间${this.bootTime},忽略上报`);
continue;
}
m.id = MessageUnique.createUniqueMsgId(
{
chatType: m.chatType,
peerUid: m.peerUid,
guildId: '',
},
m.msgId
);
await this.emitMsg(m).catch((e) =>
this.context.logger.logError('处理在线文件消息失败', e)
);
}
};
msgListener.onAddSendMsg = async (msg) => {
try {
if (msg.sendStatus === SendStatusType.KSEND_STATUS_SENDING) {
+22 -1
View File
@@ -73,6 +73,8 @@ export enum OB11MessageDataType {
miniapp = 'miniapp', // json类
contact = 'contact',
location = 'location',
onlinefile = 'onlinefile', // 在线文件/文件夹
flashtransfer = 'flashtransfer', // QQ闪传
}
export interface OB11MessagePoke {
@@ -254,6 +256,24 @@ export interface OB11MessageForward {
};
}
export interface OB11MessageOnlineFile {
type: OB11MessageDataType.onlinefile;
data: {
msgId: string;
elementId: string;
fileName: string;
fileSize: string;
isDir: boolean;
}
}
export interface OB11MessageFlashTransfer {
type: OB11MessageDataType.flashtransfer;
data: {
fileSetId: string;
}
}
// 消息数据类型定义
export type OB11MessageData =
OB11MessageText |
@@ -261,7 +281,8 @@ export type OB11MessageData =
OB11MessageAt | OB11MessageReply |
OB11MessageImage | OB11MessageRecord | OB11MessageFile | OB11MessageVideo |
OB11MessageNode | OB11MessageIdMusic | OB11MessageCustomMusic | OB11MessageJson |
OB11MessageDice | OB11MessageRPS | OB11MessageMarkdown | OB11MessageForward | OB11MessageContact | OB11MessagePoke;
OB11MessageDice | OB11MessageRPS | OB11MessageMarkdown | OB11MessageForward | OB11MessageContact |
OB11MessagePoke | OB11MessageOnlineFile | OB11MessageFlashTransfer;
// 发送消息接口定义
export interface OB11PostSendMsg {