mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-05 23:19:37 +00:00
Refactored all Satori action classes to use TypeBox schemas for payload validation and unified action naming via a new router. Added schema-based parameter checking to the SatoriAction base class. Introduced new actions for guild and member approval, and login retrieval. Centralized action name constants and types in a new router module. Enhanced event and message APIs with more structured event types and parsing logic. Added helper utilities for XML parsing. Updated exports and registration logic to support the new structure.
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { Static, Type } from '@sinclair/typebox';
|
|
import { SatoriAction } from '../SatoriAction';
|
|
import { SatoriActionName } from '../router';
|
|
import { SatoriGuild } from '../../types';
|
|
|
|
const SchemaData = Type.Object({
|
|
guild_id: Type.String(),
|
|
});
|
|
|
|
type Payload = Static<typeof SchemaData>;
|
|
|
|
export class GuildGetAction extends SatoriAction<Payload, SatoriGuild> {
|
|
actionName = SatoriActionName.GuildGet;
|
|
override payloadSchema = SchemaData;
|
|
|
|
protected async _handle (payload: Payload): Promise<SatoriGuild> {
|
|
const { guild_id } = payload;
|
|
|
|
// 先从群列表缓存中查找
|
|
const groups = await this.core.apis.GroupApi.getGroups();
|
|
const group = groups.find((e) => e.groupCode === guild_id);
|
|
|
|
if (!group) {
|
|
// 如果缓存中没有,尝试获取详细信息
|
|
const data = await this.core.apis.GroupApi.fetchGroupDetail(guild_id);
|
|
return {
|
|
id: guild_id,
|
|
name: data.groupName,
|
|
avatar: `https://p.qlogo.cn/gh/${guild_id}/${guild_id}/640`,
|
|
};
|
|
}
|
|
|
|
return {
|
|
id: guild_id,
|
|
name: group.groupName,
|
|
avatar: `https://p.qlogo.cn/gh/${guild_id}/${guild_id}/640`,
|
|
};
|
|
}
|
|
}
|