完善<set_input_status>接口

This commit is contained in:
Nepenthe 2024-10-28 23:21:49 +08:00
parent c3d4698af3
commit 5f831958c3

View File

@ -1,16 +1,15 @@
import { FromSchema, JSONSchema } from 'json-schema-to-ts'; import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import BaseAction from '../BaseAction'; import BaseAction from '../BaseAction';
import { ActionName } from '../types'; import { ActionName, BaseCheckResult } from '../types';
import { ChatType, Peer } from '@/core'; import { ChatType, Peer } from '@/core';
const SchemaData = { const SchemaData = {
type: 'object', type: 'object',
properties: { properties: {
eventType: { type: 'string' }, event_type: { type: 'number' },
group_id: { type: 'string' }, user_id: { type: ['number', 'string'] },
user_id: { type: 'string' },
}, },
required: ['eventType'], required: ['event_type','user_id'],
} as const satisfies JSONSchema; } as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>; type Payload = FromSchema<typeof SchemaData>;
@ -19,23 +18,12 @@ export class SetInputStatus extends BaseAction<Payload, any> {
actionName = ActionName.SetInputStatus; actionName = ActionName.SetInputStatus;
async _handle(payload: Payload) { async _handle(payload: Payload) {
let peer: Peer; const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
if (payload.group_id) { if (!uid) throw new Error('uid is empty');
peer = { const peer = {
chatType: ChatType.KCHATTYPEGROUP, chatType: ChatType.KCHATTYPEC2C,
peerUid: payload.group_id, peerUid: uid,
}; };
} else if (payload.user_id) { return await this.core.apis.MsgApi.sendShowInputStatusReq(peer, payload.event_type);
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id);
if (!uid) throw new Error('uid is empty');
peer = {
chatType: ChatType.KCHATTYPEC2C,
peerUid: uid,
};
} else {
throw new Error('请指定 group_id 或 user_id');
}
return await this.core.apis.MsgApi.sendShowInputStatusReq(peer, parseInt(payload.eventType));
} }
} }