Refactor type handling and improve message parsing

Updated several actions to use more precise type casting and type guards, improving type safety and clarity. Enhanced message parsing logic for forward messages and group/friend message history. Standardized return schemas and error handling for avatar and group portrait actions.
This commit is contained in:
手瓜一十雪
2026-01-25 16:32:36 +08:00
parent e562a57713
commit 20398af648
10 changed files with 67 additions and 38 deletions

View File

@@ -1,8 +1,9 @@
import { OB11MessageMixType } from '@/napcat-onebot/types';
import { ContextMode, normalize, ReturnDataType, SendMsgBase, SendMsgPayload } from '@/napcat-onebot/action/msg/SendMsg';
import { ActionName } from '@/napcat-onebot/action/router';
// 未验证
type GoCQHTTPSendForwardMsgPayload = SendMsgPayload & { messages?: any; };
type GoCQHTTPSendForwardMsgPayload = SendMsgPayload & { messages?: OB11MessageMixType; };
export class GoCQHTTPSendForwardMsgBase extends SendMsgBase {
protected override async check (payload: GoCQHTTPSendForwardMsgPayload) {
@@ -20,14 +21,14 @@ export class GoCQHTTPSendForwardMsg extends GoCQHTTPSendForwardMsgBase {
}
export class GoCQHTTPSendPrivateForwardMsg extends GoCQHTTPSendForwardMsgBase {
override actionName = ActionName.GoCQHTTP_SendPrivateForwardMsg;
override async _handle (payload: SendMsgPayload): Promise<ReturnDataType> {
override async _handle (payload: GoCQHTTPSendForwardMsgPayload): Promise<ReturnDataType> {
return this.base_handle(payload, ContextMode.Private);
}
}
export class GoCQHTTPSendGroupForwardMsg extends GoCQHTTPSendForwardMsgBase {
override actionName = ActionName.GoCQHTTP_SendGroupForwardMsg;
override async _handle (payload: SendMsgPayload): Promise<ReturnDataType> {
override async _handle (payload: GoCQHTTPSendForwardMsgPayload): Promise<ReturnDataType> {
return this.base_handle(payload, ContextMode.Group);
}
}