feat: 新增群待办完成和取消功能 (#1764)
- 添加CompleteGroupTodo和CancelGroupTodo方法 - 重构SetGroupTodo使用BaseGroupTodoAction基类 - 更新相关测试用例和依赖配置 Signed-off-by: xboHodx <2679933924@qq.com>
This commit is contained in:
1 parent
d849188ef2
commit
6d63da4fa0
19 files changed
+214
-37
No files matched your search
@@ -41,6 +41,16 @@ export class PacketOperationContext {
|
||||
await this.context.client.sendOidbPacket(req, true);
|
||||
}
|
||||
|
||||
async CompleteGroupTodo (groupUin: number, msgSeq: string) {
|
||||
const req = trans.CompleteGroupTodo.build(groupUin, msgSeq);
|
||||
await this.context.client.sendOidbPacket(req, true);
|
||||
}
|
||||
|
||||
async CancelGroupTodo (groupUin: number, msgSeq: string) {
|
||||
const req = trans.CancelGroupTodo.build(groupUin, msgSeq);
|
||||
await this.context.client.sendOidbPacket(req, true);
|
||||
}
|
||||
|
||||
async FetchRkey (timeout: number = 10000) {
|
||||
const req = trans.FetchRkey.build();
|
||||
const resp = await this.context.client.sendOidbPacket(req, true, timeout);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import * as proto from '@/napcat-core/packet/transformer/proto';
|
||||
import { NapProtoMsg } from 'napcat-protobuf';
|
||||
import { OidbPacket, PacketTransformer } from '@/napcat-core/packet/transformer/base';
|
||||
import OidbBase from '@/napcat-core/packet/transformer/oidb/oidbBase';
|
||||
|
||||
class CancelGroupTodo extends PacketTransformer<typeof proto.OidbSvcTrpcTcpBase> {
|
||||
build (peer: number, msgSeq: string): OidbPacket {
|
||||
const data = new NapProtoMsg(proto.OidbSvcTrpcTcp0XF90).encode({
|
||||
groupUin: peer,
|
||||
msgSeq: BigInt(msgSeq),
|
||||
});
|
||||
return OidbBase.build(0xF90, 3, data);
|
||||
}
|
||||
|
||||
parse (data: Buffer) {
|
||||
return OidbBase.parse(data);
|
||||
}
|
||||
}
|
||||
|
||||
export default new CancelGroupTodo();
|
||||
@@ -0,0 +1,20 @@
|
||||
import * as proto from '@/napcat-core/packet/transformer/proto';
|
||||
import { NapProtoMsg } from 'napcat-protobuf';
|
||||
import { OidbPacket, PacketTransformer } from '@/napcat-core/packet/transformer/base';
|
||||
import OidbBase from '@/napcat-core/packet/transformer/oidb/oidbBase';
|
||||
|
||||
class CompleteGroupTodo extends PacketTransformer<typeof proto.OidbSvcTrpcTcpBase> {
|
||||
build (peer: number, msgSeq: string): OidbPacket {
|
||||
const data = new NapProtoMsg(proto.OidbSvcTrpcTcp0XF90).encode({
|
||||
groupUin: peer,
|
||||
msgSeq: BigInt(msgSeq),
|
||||
});
|
||||
return OidbBase.build(0xF90, 2, data);
|
||||
}
|
||||
|
||||
parse (data: Buffer) {
|
||||
return OidbBase.parse(data);
|
||||
}
|
||||
}
|
||||
|
||||
export default new CompleteGroupTodo();
|
||||
@@ -5,7 +5,7 @@ import OidbBase from '@/napcat-core/packet/transformer/oidb/oidbBase';
|
||||
|
||||
class SetGroupTodo extends PacketTransformer<typeof proto.OidbSvcTrpcTcpBase> {
|
||||
build (peer: number, msgSeq: string): OidbPacket {
|
||||
const data = new NapProtoMsg(proto.OidbSvcTrpcTcp0XF90_1).encode({
|
||||
const data = new NapProtoMsg(proto.OidbSvcTrpcTcp0XF90).encode({
|
||||
groupUin: peer,
|
||||
msgSeq: BigInt(msgSeq),
|
||||
});
|
||||
|
||||
@@ -8,4 +8,6 @@ export { default as SetSpecialTitle } from './SetSpecialTitle';
|
||||
export { default as ImageOCR } from './ImageOCR';
|
||||
export { default as MoveGroupFile } from './MoveGroupFile';
|
||||
export { default as RenameGroupFile } from './RenameGroupFile';
|
||||
export { default as CompleteGroupTodo } from './CompleteGroupTodo';
|
||||
export { default as CancelGroupTodo } from './CancelGroupTodo';
|
||||
export { default as SetGroupTodo } from './SetGroupTodo';
|
||||
@@ -31,4 +31,4 @@ export * from './oidb/Oidb.0xED3_1';
|
||||
export * from './oidb/Oidb.0XFE1_2';
|
||||
export * from './oidb/OidbBase';
|
||||
export * from './oidb/Oidb.0xE07';
|
||||
export * from './oidb/Oidb.0xf90_1';
|
||||
export * from './oidb/Oidb.0xf90';
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { ProtoField, ScalarType } from 'napcat-protobuf';
|
||||
|
||||
export const OidbSvcTrpcTcp0XF90_1 = {
|
||||
export const OidbSvcTrpcTcp0XF90 = {
|
||||
groupUin: ProtoField(1, ScalarType.UINT32),
|
||||
msgSeq: ProtoField(2, ScalarType.UINT64),
|
||||
};
|
||||
@@ -11,4 +11,12 @@ export const PacketActionsExamples = {
|
||||
payload: { group_id: '123456', message_id: '123456789' },
|
||||
response: {},
|
||||
},
|
||||
CompleteGroupTodo: {
|
||||
payload: { group_id: '123456', message_id: '123456789' },
|
||||
response: {},
|
||||
},
|
||||
CancelGroupTodo: {
|
||||
payload: { group_id: '123456', message_id: '123456789' },
|
||||
response: {},
|
||||
},
|
||||
};
|
||||
@@ -127,6 +127,8 @@ import SetGroupKickMembers from './extends/SetGroupKickMembers';
|
||||
import { GetGroupDetailInfo } from './group/GetGroupDetailInfo';
|
||||
import GetGroupAddRequest from './extends/GetGroupAddRequest';
|
||||
import { GetCollectionList } from './extends/GetCollectionList';
|
||||
import { CompleteGroupTodo } from './packet/CompleteGroupTodo';
|
||||
import { CancelGroupTodo } from './packet/CancelGroupTodo';
|
||||
import { SetGroupTodo } from './packet/SetGroupTodo';
|
||||
import { GetQunAlbumList } from './extends/GetQunAlbumList';
|
||||
import { UploadImageToQunAlbum } from './extends/UploadImageToQunAlbum';
|
||||
@@ -171,6 +173,8 @@ export function getAllHandlers (obContext: NapCatOneBot11Adapter, core: NapCatCo
|
||||
new GetQunAlbumList(obContext, core),
|
||||
new UploadImageToQunAlbum(obContext, core),
|
||||
new SetGroupTodo(obContext, core),
|
||||
new CompleteGroupTodo(obContext, core),
|
||||
new CancelGroupTodo(obContext, core),
|
||||
new GetGroupDetailInfo(obContext, core),
|
||||
new SetGroupKickMembers(obContext, core),
|
||||
new SetGroupAddOption(obContext, core),
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { MessageUnique } from 'napcat-common/src/message-unique';
|
||||
import { ChatType, Peer } from 'napcat-core';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketStatus';
|
||||
|
||||
export const GroupTodoPayloadSchema = Type.Object({
|
||||
group_id: Type.Union([Type.String(), Type.Number()], { description: '群号' }),
|
||||
message_id: Type.Optional(Type.String({ description: '消息ID' })),
|
||||
message_seq: Type.Optional(Type.String({ description: '消息Seq (可选)' })),
|
||||
});
|
||||
|
||||
export type GroupTodoPayload = Static<typeof GroupTodoPayloadSchema>;
|
||||
|
||||
export abstract class BaseGroupTodoAction extends GetPacketStatusDepends<GroupTodoPayload, void> {
|
||||
override payloadSchema = GroupTodoPayloadSchema;
|
||||
override returnSchema = Type.Null();
|
||||
override actionTags = ['核心接口'];
|
||||
|
||||
protected abstract handleGroupTodo(groupId: number, msgSeq: string): Promise<void>;
|
||||
|
||||
async _handle (payload: GroupTodoPayload) {
|
||||
const groupId = +payload.group_id;
|
||||
if (payload.message_seq) {
|
||||
return await this.handleGroupTodo(groupId, payload.message_seq.toString());
|
||||
}
|
||||
if (!payload.message_id) {
|
||||
throw new Error('缺少参数 message_id 或 message_seq');
|
||||
}
|
||||
const peer: Peer = {
|
||||
chatType: ChatType.KCHATTYPEGROUP,
|
||||
peerUid: payload.group_id.toString(),
|
||||
};
|
||||
const { MsgId, Peer } = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id) ?? { Peer: peer, MsgId: payload.message_id.toString() };
|
||||
const msg = (await this.core.apis.MsgApi.getMsgsByMsgId(Peer, [MsgId])).msgList[0];
|
||||
if (!msg) {
|
||||
throw new Error('消息不存在');
|
||||
}
|
||||
await this.handleGroupTodo(groupId, msg.msgSeq);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { ActionName } from '../router';
|
||||
import { PacketActionsExamples } from '../example/PacketActionsExamples';
|
||||
import { BaseGroupTodoAction } from './BaseGroupTodoAction';
|
||||
|
||||
export class CancelGroupTodo extends BaseGroupTodoAction {
|
||||
override actionName = ActionName.CancelGroupTodo;
|
||||
override actionSummary = '取消群待办';
|
||||
override actionDescription = '将指定消息对应的群待办取消';
|
||||
override payloadExample = PacketActionsExamples.CancelGroupTodo.payload;
|
||||
override returnExample = PacketActionsExamples.CancelGroupTodo.response;
|
||||
|
||||
protected override async handleGroupTodo (groupId: number, msgSeq: string) {
|
||||
await this.core.apis.PacketApi.pkt.operation.CancelGroupTodo(groupId, msgSeq);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { ActionName } from '../router';
|
||||
import { PacketActionsExamples } from '../example/PacketActionsExamples';
|
||||
import { BaseGroupTodoAction } from './BaseGroupTodoAction';
|
||||
|
||||
export class CompleteGroupTodo extends BaseGroupTodoAction {
|
||||
override actionName = ActionName.CompleteGroupTodo;
|
||||
override actionSummary = '完成群待办';
|
||||
override actionDescription = '将指定消息对应的群待办标记为已完成';
|
||||
override payloadExample = PacketActionsExamples.CompleteGroupTodo.payload;
|
||||
override returnExample = PacketActionsExamples.CompleteGroupTodo.response;
|
||||
|
||||
protected override async handleGroupTodo (groupId: number, msgSeq: string) {
|
||||
await this.core.apis.PacketApi.pkt.operation.CompleteGroupTodo(groupId, msgSeq);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +1,14 @@
|
||||
import { MessageUnique } from 'napcat-common/src/message-unique';
|
||||
import { ChatType, Peer } from 'napcat-core';
|
||||
import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketStatus';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { ActionName } from '../router';
|
||||
|
||||
import { PacketActionsExamples } from '../example/PacketActionsExamples';
|
||||
|
||||
export const SetGroupTodoPayloadSchema = Type.Object({
|
||||
group_id: Type.Union([Type.String(), Type.Number()], { description: '群号' }),
|
||||
message_id: Type.Optional(Type.String({ description: '消息ID' })),
|
||||
message_seq: Type.Optional(Type.String({ description: '消息Seq (可选)' })),
|
||||
});
|
||||
|
||||
export type SetGroupTodoPayload = Static<typeof SetGroupTodoPayloadSchema>;
|
||||
export class SetGroupTodo extends GetPacketStatusDepends<SetGroupTodoPayload, void> {
|
||||
import { BaseGroupTodoAction } from './BaseGroupTodoAction';
|
||||
export class SetGroupTodo extends BaseGroupTodoAction {
|
||||
override actionName = ActionName.SetGroupTodo;
|
||||
override payloadSchema = SetGroupTodoPayloadSchema;
|
||||
override returnSchema = Type.Null();
|
||||
override actionSummary = '设置群待办';
|
||||
override actionDescription = '将指定消息设置为群待办';
|
||||
override actionTags = ['核心接口'];
|
||||
override payloadExample = PacketActionsExamples.SetGroupTodo.payload;
|
||||
override returnExample = PacketActionsExamples.SetGroupTodo.response;
|
||||
|
||||
async _handle (payload: SetGroupTodoPayload) {
|
||||
if (payload.message_seq) {
|
||||
return await this.core.apis.PacketApi.pkt.operation.SetGroupTodo(+payload.group_id, payload.message_seq.toString());
|
||||
}
|
||||
if (!payload.message_id) {
|
||||
throw new Error('缺少参数 message_id 或 message_seq');
|
||||
}
|
||||
const peer: Peer = {
|
||||
chatType: ChatType.KCHATTYPEGROUP,
|
||||
peerUid: payload.group_id.toString(),
|
||||
};
|
||||
const { MsgId, Peer } = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id) ?? { Peer: peer, MsgId: payload.message_id.toString() };
|
||||
const msg = (await this.core.apis.MsgApi.getMsgsByMsgId(Peer, [MsgId])).msgList[0];
|
||||
if (!msg) throw new Error('消息不存在');
|
||||
await this.core.apis.PacketApi.pkt.operation.SetGroupTodo(+payload.group_id, msg.msgSeq);
|
||||
protected override async handleGroupTodo (groupId: number, msgSeq: string) {
|
||||
await this.core.apis.PacketApi.pkt.operation.SetGroupTodo(groupId, msgSeq);
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,8 @@ export const ActionName = {
|
||||
UploadImageToQunAlbum: 'upload_image_to_qun_album',
|
||||
GetQunAlbumList: 'get_qun_album_list',
|
||||
SetGroupTodo: 'set_group_todo',
|
||||
CompleteGroupTodo: 'complete_group_todo',
|
||||
CancelGroupTodo: 'cancel_group_todo',
|
||||
SetGroupKickMembers: 'set_group_kick_members',
|
||||
SetGroupRobotAddOption: 'set_group_robot_add_option',
|
||||
SetGroupAddOption: 'set_group_add_option',
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { describe, expect, test, vi } from 'vitest';
|
||||
import { NapProtoMsg } from 'napcat-protobuf';
|
||||
import { OidbSvcTrpcTcpBase } from '@/napcat-core/packet/transformer/proto/oidb/OidbBase';
|
||||
import { OidbSvcTrpcTcp0XF90 } from '@/napcat-core/packet/transformer/proto/oidb/Oidb.0xf90';
|
||||
|
||||
vi.mock('@/napcat-core/packet/transformer/base', () => ({
|
||||
PacketTransformer: class PacketTransformer {
|
||||
protected msgBuilder: unknown;
|
||||
|
||||
constructor () {
|
||||
this.msgBuilder = undefined;
|
||||
}
|
||||
},
|
||||
PacketBufBuilder: (str: Uint8Array) => Buffer.from(str),
|
||||
}));
|
||||
|
||||
import SetGroupTodo from '@/napcat-core/packet/transformer/action/SetGroupTodo';
|
||||
import CompleteGroupTodo from '@/napcat-core/packet/transformer/action/CompleteGroupTodo';
|
||||
import CancelGroupTodo from '@/napcat-core/packet/transformer/action/CancelGroupTodo';
|
||||
|
||||
const decodePacket = (data: Buffer) => {
|
||||
const base = new NapProtoMsg(OidbSvcTrpcTcpBase).decode(data);
|
||||
const body = new NapProtoMsg(OidbSvcTrpcTcp0XF90).decode(base.body);
|
||||
return { base, body };
|
||||
};
|
||||
|
||||
describe('Group todo packet builder', () => {
|
||||
test('builds OIDB 0xF90 subCommand 1 for set', () => {
|
||||
const packet = SetGroupTodo.build(123456, '789');
|
||||
const { base, body } = decodePacket(packet.data);
|
||||
|
||||
expect(packet.cmd).toBe('OidbSvcTrpcTcp.0xF90_1');
|
||||
expect(base.command).toBe(0xF90);
|
||||
expect(base.subCommand).toBe(1);
|
||||
expect(body.groupUin).toBe(123456);
|
||||
expect(body.msgSeq).toBe('789');
|
||||
});
|
||||
|
||||
test('builds OIDB 0xF90 subCommand 2 for complete', () => {
|
||||
const packet = CompleteGroupTodo.build(123456, '789');
|
||||
const { base, body } = decodePacket(packet.data);
|
||||
|
||||
expect(packet.cmd).toBe('OidbSvcTrpcTcp.0xF90_2');
|
||||
expect(base.command).toBe(0xF90);
|
||||
expect(base.subCommand).toBe(2);
|
||||
expect(body.groupUin).toBe(123456);
|
||||
expect(body.msgSeq).toBe('789');
|
||||
});
|
||||
|
||||
test('builds OIDB 0xF90 subCommand 3 for cancel', () => {
|
||||
const packet = CancelGroupTodo.build(123456, '789');
|
||||
const { base, body } = decodePacket(packet.data);
|
||||
|
||||
expect(packet.cmd).toBe('OidbSvcTrpcTcp.0xF90_3');
|
||||
expect(base.command).toBe(0xF90);
|
||||
expect(base.subCommand).toBe(3);
|
||||
expect(body.groupUin).toBe(123456);
|
||||
expect(body.msgSeq).toBe('789');
|
||||
});
|
||||
});
|
||||
@@ -15,6 +15,7 @@
|
||||
"napcat-core": "workspace:*",
|
||||
"napcat-image-size": "workspace:*",
|
||||
"napcat-onebot": "workspace:*",
|
||||
"napcat-rpc": "workspace:*"
|
||||
"napcat-rpc": "workspace:*",
|
||||
"napcat-protobuf": "workspace:*"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": ".."
|
||||
},
|
||||
"include": [
|
||||
"*.ts",
|
||||
"**/*.ts"
|
||||
@@ -8,4 +11,4 @@
|
||||
"node_modules",
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,8 @@ export default defineConfig({
|
||||
'@/napcat-test': resolve(__dirname, '.'),
|
||||
'@/napcat-common': resolve(__dirname, '../napcat-common'),
|
||||
'@/napcat-core': resolve(__dirname, '../napcat-core'),
|
||||
'@/napcat-onebot': resolve(__dirname, '../napcat-onebot'),
|
||||
'napcat-protobuf': resolve(__dirname, '../napcat-protobuf/NapProto.ts'),
|
||||
},
|
||||
},
|
||||
});
|
||||
Generated
+3
@@ -387,6 +387,9 @@ importers:
|
||||
napcat-onebot:
|
||||
specifier: workspace:*
|
||||
version: link:../napcat-onebot
|
||||
napcat-protobuf:
|
||||
specifier: workspace:*
|
||||
version: link:../napcat-protobuf
|
||||
napcat-rpc:
|
||||
specifier: workspace:*
|
||||
version: link:../napcat-rpc
|
||||
|
||||
Reference in new issue
Block a user