feat:GetUserStatus

This commit is contained in:
手瓜一十雪 2024-10-13 14:18:35 +08:00
parent 30e594ae5f
commit b4e22a345d
4 changed files with 47 additions and 19 deletions

View File

@ -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<typeof SchemaData>;
export class GetUserStatus extends BaseAction<Payload, { status: number; ext_status: number; } | undefined> {
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);
}
}

View File

@ -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<string, BaseAction<any, any>>;
@ -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) {

View File

@ -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",
}

View File

@ -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));