diff --git a/src/core/packet/context/operationContext.ts b/src/core/packet/context/operationContext.ts index 43161e91..b1fee47b 100644 --- a/src/core/packet/context/operationContext.ts +++ b/src/core/packet/context/operationContext.ts @@ -30,13 +30,18 @@ export class PacketOperationContext { return await this.context.client.sendOidbPacket(pkt, rsp); } - async GroupPoke(groupUin: number, uin: number) { - const req = trans.SendPoke.build(true, groupUin, uin); + async GroupPoke(peer: number, uin: number) { + const req = trans.SendPoke.build(true, peer, uin); await this.context.client.sendOidbPacket(req); } - async FriendPoke(uin: number, target?: number) { - const req = trans.SendPoke.build(false, uin, target ?? uin); + async FriendPoke(peer: number, target?: number) { + const req = trans.SendPoke.build(false, peer, target ?? peer); + await this.context.client.sendOidbPacket(req); + } + + async SendPoke(is_group: boolean, peer: number, target?: number) { + const req = trans.SendPoke.build(is_group, peer, target ?? peer); await this.context.client.sendOidbPacket(req); } diff --git a/src/onebot/action/group/GroupPoke.ts b/src/onebot/action/group/GroupPoke.ts deleted file mode 100644 index 8dcc8815..00000000 --- a/src/onebot/action/group/GroupPoke.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { ActionName } from '@/onebot/action/router'; -import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus'; -import { Static, Type } from '@sinclair/typebox'; - -const SchemaData = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()]), - user_id: Type.Union([Type.Number(), Type.String()]), -}); - -type Payload = Static; - -export class GroupPoke extends GetPacketStatusDepends { - override actionName = ActionName.GroupPoke; - override payloadSchema = SchemaData; - - async _handle(payload: Payload) { - await this.core.apis.PacketApi.pkt.operation.GroupPoke(+payload.group_id, +payload.user_id); - } -} diff --git a/src/onebot/action/index.ts b/src/onebot/action/index.ts index 37dc07f5..34294063 100644 --- a/src/onebot/action/index.ts +++ b/src/onebot/action/index.ts @@ -78,7 +78,6 @@ import { GetGroupFileSystemInfo } from '@/onebot/action/go-cqhttp/GetGroupFileSy import { GetGroupRootFiles } from '@/onebot/action/go-cqhttp/GetGroupRootFiles'; import { GetGroupFilesByFolder } from '@/onebot/action/go-cqhttp/GetGroupFilesByFolder'; import { GetGroupSystemMsg } from './system/GetSystemMsg'; -import { GroupPoke } from './group/GroupPoke'; import { GetUserStatus } from './extends/GetUserStatus'; import { GetRkey } from './extends/GetRkey'; import { SetSpecialTitle } from './extends/SetSpecialTitle'; @@ -86,7 +85,6 @@ import { GetGroupShutList } from './group/GetGroupShutList'; import { GetGroupMemberList } from './group/GetGroupMemberList'; import { GetGroupFileUrl } from '@/onebot/action/file/GetGroupFileUrl'; import { GetPacketStatus } from '@/onebot/action/packet/GetPacketStatus'; -import { FriendPoke } from '@/onebot/action/user/FriendPoke'; import { GetCredentials } from './system/GetCredentials'; import { SendGroupSign, SetGroupSign } from './extends/SetGroupSign'; import { GoCQHTTPGetGroupAtAllRemain } from './go-cqhttp/GetGroupAtAllRemain'; @@ -102,7 +100,7 @@ import { GetGuildList } from './guild/GetGuildList'; import { GetGuildProfile } from './guild/GetGuildProfile'; import { GetClientkey } from './extends/GetClientkey'; import { SendPacket } from './extends/SendPacket'; -import { SendPoke } from '@/onebot/action/packet/SendPoke'; +import { FriendPoke, GroupPoke, SendPoke } from '@/onebot/action/packet/SendPoke'; import { SetDiyOnlineStatus } from './extends/SetDiyOnlineStatus'; import { BotExit } from './extends/BotExit'; import { ClickInlineKeyboardButton } from './extends/ClickInlineKeyboardButton'; diff --git a/src/onebot/action/packet/SendPoke.ts b/src/onebot/action/packet/SendPoke.ts index 6b47ebe3..479aa6e6 100644 --- a/src/onebot/action/packet/SendPoke.ts +++ b/src/onebot/action/packet/SendPoke.ts @@ -4,21 +4,32 @@ import { Static, Type } from '@sinclair/typebox'; const SchemaData = Type.Object({ group_id: Type.Optional(Type.String()), - user_id: Type.String(), + user_id: Type.Optional(Type.String()), target_id: Type.Optional(Type.String()), }); type Payload = Static; - -export class SendPoke extends GetPacketStatusDepends { - override actionName = ActionName.SendPoke; +export class SendPokeBase extends GetPacketStatusDepends { override payloadSchema = SchemaData; async _handle(payload: Payload) { - if (payload.group_id) { - await this.core.apis.PacketApi.pkt.operation.GroupPoke(+payload.group_id, +payload.user_id); - } else { - await this.core.apis.PacketApi.pkt.operation.FriendPoke(+payload.user_id, payload.target_id ? +payload.target_id : undefined); + const target_id = payload.target_id ?? payload.user_id; + const peer_id = payload.group_id ?? payload.user_id; + const is_group = !!payload.group_id; + if (!target_id || !peer_id) { + throw new Error('请检查参数,缺少 user_id 或 group_id'); } + await this.core.apis.PacketApi.pkt.operation.SendPoke(is_group, +peer_id, +target_id); } } + + +export class SendPoke extends SendPokeBase { + override actionName = ActionName.SendPoke; +} +export class GroupPoke extends SendPokeBase { + override actionName = ActionName.GroupPoke; +} +export class FriendPoke extends SendPokeBase { + override actionName = ActionName.FriendPoke; +} diff --git a/src/onebot/action/user/FriendPoke.ts b/src/onebot/action/user/FriendPoke.ts deleted file mode 100644 index 80b024fc..00000000 --- a/src/onebot/action/user/FriendPoke.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { ActionName } from '@/onebot/action/router'; -import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus'; -import { Static, Type } from '@sinclair/typebox'; - -const SchemaData = Type.Object({ - user_id: Type.Number(), - target_id: Type.Optional(Type.String()), -}); - -type Payload = Static; - -export class FriendPoke extends GetPacketStatusDepends { - override actionName = ActionName.FriendPoke; - override payloadSchema = SchemaData; - - async _handle(payload: Payload) { - await this.core.apis.PacketApi.pkt.operation.FriendPoke(payload.user_id, payload.target_id ? +payload.target_id : undefined); - } -}