From b4e22a345d9b9a1e52081e2a50627c993730c532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Sun, 13 Oct 2024 14:18:35 +0800 Subject: [PATCH] feat:GetUserStatus --- src/onebot/action/extends/GetUserStatus.ts | 25 ++++++++++++++ src/onebot/action/index.ts | 2 ++ src/onebot/action/types.ts | 1 + src/onebot/index.ts | 38 +++++++++++----------- 4 files changed, 47 insertions(+), 19 deletions(-) create mode 100644 src/onebot/action/extends/GetUserStatus.ts diff --git a/src/onebot/action/extends/GetUserStatus.ts b/src/onebot/action/extends/GetUserStatus.ts new file mode 100644 index 00000000..09272357 --- /dev/null +++ b/src/onebot/action/extends/GetUserStatus.ts @@ -0,0 +1,25 @@ +import BaseAction from '../BaseAction'; +import { ActionName } from '../types'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; +// no_cache get时传字符串 +const SchemaData = { + type: 'object', + properties: { + user_id: { type: ['number', 'string'] }, + }, + required: ['user_id'], +} as const satisfies JSONSchema; + +type Payload = FromSchema; + +export class GetUserStatus extends BaseAction { + actionName = ActionName.GetUserStatus; + payloadSchema = SchemaData; + + async _handle(payload: Payload) { + if (!this.core.apis.PacketApi.PacketClient?.isConnected) { + throw new Error('PacketClient is not init'); + } + return await this.core.apis.PacketApi.sendStatusPacket(+payload.user_id); + } +} \ No newline at end of file diff --git a/src/onebot/action/index.ts b/src/onebot/action/index.ts index 6bb72665..8d2fe012 100644 --- a/src/onebot/action/index.ts +++ b/src/onebot/action/index.ts @@ -85,6 +85,7 @@ 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'; export type ActionMap = Map>; @@ -182,6 +183,7 @@ export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCo new GetGroupSystemMsg(obContext, core), new FetchUserProfileLike(obContext, core), new GroupPoke(obContext, core), + new GetUserStatus(obContext, core), ]; const actionMap = new Map(); for (const action of actionHandlers) { diff --git a/src/onebot/action/types.ts b/src/onebot/action/types.ts index 7ad25cbc..639f880a 100644 --- a/src/onebot/action/types.ts +++ b/src/onebot/action/types.ts @@ -120,4 +120,5 @@ export enum ActionName { GetGroupInfoEx = "get_group_info_ex", GetGroupSystemMsg = 'get_group_system_msg', FetchUserProfileLike = "fetch_user_profile_like", + GetUserStatus = "nc_get_user_status", } diff --git a/src/onebot/index.ts b/src/onebot/index.ts index 5f1e18f9..416ba432 100644 --- a/src/onebot/index.ts +++ b/src/onebot/index.ts @@ -541,26 +541,26 @@ export class NapCatOneBot11Adapter { if (isSelfMsg) { ob11Msg.target_id = parseInt(message.peerUin); } - if (ob11Msg.raw_message.startsWith('!status')) { - console.log('status', message.peerUin, message.senderUin); - let delMsg: string[] = []; - let peer = { - peerUid: message.peerUin, - chatType: 2, - }; - this.core.apis.PacketApi.sendStatusPacket(+message.senderUin).then(async e => { - if (e) { - const { sendElements } = await this.apis.MsgApi.createSendElements([{ - type: OB11MessageDataType.text, - data: { - text: 'status ' + JSON.stringify(e, null, 2), - } - }], peer) + // if (ob11Msg.raw_message.startsWith('!status')) { + // console.log('status', message.peerUin, message.senderUin); + // let delMsg: string[] = []; + // let peer = { + // peerUid: message.peerUin, + // chatType: 2, + // }; + // this.core.apis.PacketApi.sendStatusPacket(+message.senderUin).then(async e => { + // if (e) { + // const { sendElements } = await this.apis.MsgApi.createSendElements([{ + // type: OB11MessageDataType.text, + // data: { + // text: 'status ' + JSON.stringify(e, null, 2), + // } + // }], peer) - this.apis.MsgApi.sendMsgWithOb11UniqueId(peer, sendElements, delMsg) - } - }) - } + // this.apis.MsgApi.sendMsgWithOb11UniqueId(peer, sendElements, delMsg) + // } + // }) + // } this.networkManager.emitEvent(ob11Msg); }).catch(e => this.context.logger.logError.bind(this.context.logger)('constructMessage error: ', e));