feat: send_packet

This commit is contained in:
手瓜一十雪
2024-12-26 20:36:53 +08:00
parent a62de441cf
commit 8ed4cc4b0a
4 changed files with 27 additions and 2 deletions

View File

@@ -23,7 +23,9 @@ export class PacketClientSession {
get operation() { get operation() {
return this.context.operation; return this.context.operation;
} }
get client() {
return this.context.client;
}
// TODO: global message element adapter (? // TODO: global message element adapter (?
get msgConverter() { get msgConverter() {
return this.context.msgConverter; return this.context.msgConverter;

View File

@@ -0,0 +1,21 @@
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
cmd: Type.String(),
data: Type.String(),
rsp: Type.Union([Type.String(), Type.Boolean()], { default: true }),
});
type Payload = Static<typeof SchemaData>;
export class SendPacket extends GetPacketStatusDepends<Payload, any> {
payloadSchema = SchemaData;
actionName = ActionName.SendPacket;
async _handle(payload: Payload) {
const rsp = typeof payload.rsp === 'boolean' ? payload.rsp : payload.rsp === 'true';
const data = await this.core.apis.PacketApi.pkt.client.sendOidbPacket({ cmd: payload.cmd, data: payload.data as any }, rsp);
return typeof data === 'object' ? data.toString('hex') : undefined;
}
}

View File

@@ -103,6 +103,7 @@ import { GetAiCharacters } from "@/onebot/action/extends/GetAiCharacters";
import { GetGuildList } from './guild/GetGuildList'; import { GetGuildList } from './guild/GetGuildList';
import { GetGuildProfile } from './guild/GetGuildProfile'; import { GetGuildProfile } from './guild/GetGuildProfile';
import { GetClientkey } from './extends/GetClientkey'; import { GetClientkey } from './extends/GetClientkey';
import { SendPacket } from './extends/SendPacket';
export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCore) { export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCore) {
@@ -218,6 +219,7 @@ export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCo
new GetAiRecord(obContext, core), new GetAiRecord(obContext, core),
new SendGroupAiRecord(obContext, core), new SendGroupAiRecord(obContext, core),
new GetAiCharacters(obContext, core), new GetAiCharacters(obContext, core),
new SendPacket(obContext, core),
]; ];
type HandlerUnion = typeof actionHandlers[number]; type HandlerUnion = typeof actionHandlers[number];

View File

@@ -137,7 +137,7 @@ export const ActionName = {
SetGroupSign: "set_group_sign", SetGroupSign: "set_group_sign",
SendGroupSign: "send_group_sign", SendGroupSign: "send_group_sign",
SendPacket: "send_packet",
GetMiniAppArk: "get_mini_app_ark", GetMiniAppArk: "get_mini_app_ark",
// UploadForwardMsg : "upload_forward_msg", // UploadForwardMsg : "upload_forward_msg",
GetAiRecord: "get_ai_record", GetAiRecord: "get_ai_record",