26 包 monorepo(TS 全源码): - snowcat-core: NT 内核 API 封装 + listener(含 9.9.37 六回调适配)+ Packet 发包 - snowcat-onebot: OneBot v11 全动作 + MCP Streamable HTTP 适配器 + 稳定线 - snowcat-webui-frontend/backend: 雪猫控制台(React+HeroUI) - snowcat-shell: 单文件 bundle 出口(vite inlineDynamicImports) - snowcat-native: napi2native / MoeHoo / ffmpeg / pty 运行时 - 56 项 SnowLuma 独门动作移植(qzone 全家桶/群相册/装扮/闪照/收藏) - 工具件: 解包器/启动器/便携制作器/doctor GitHub 关联已全量指向 DandanLLab/SnowCatQQ
60 lines
2.4 KiB
TypeScript
60 lines
2.4 KiB
TypeScript
import { OB11Construct } from '@/snowcat-onebot/helper/data';
|
|
import { OneBotAction } from '@/snowcat-onebot/action/OneBotAction';
|
|
import { ActionName } from '@/snowcat-onebot/action/router';
|
|
import { Static, Type } from '@sinclair/typebox';
|
|
import { GroupMember } from 'snowcat-core';
|
|
import { GroupActionsExamples } from '../example/GroupActionsExamples';
|
|
|
|
const PayloadSchema = Type.Object({
|
|
group_id: Type.String({ description: '群号' }),
|
|
no_cache: Type.Optional(Type.Union([Type.Boolean(), Type.String()], { description: '是否不使用缓存' })),
|
|
});
|
|
|
|
type PayloadType = Static<typeof PayloadSchema>;
|
|
|
|
const ReturnSchema = Type.Array(Type.Any(), { description: '群成员列表' });
|
|
|
|
type ReturnType = Static<typeof ReturnSchema>;
|
|
|
|
export class GetGroupMemberList extends OneBotAction<PayloadType, ReturnType> {
|
|
override actionName = ActionName.GetGroupMemberList;
|
|
override payloadSchema = PayloadSchema;
|
|
override returnSchema = ReturnSchema;
|
|
override actionSummary = '获取群成员列表';
|
|
override actionDescription = '获取群聊中的所有成员列表';
|
|
override actionTags = ['群组接口'];
|
|
override payloadExample = GroupActionsExamples.GetGroupMemberList.payload;
|
|
override returnExample = GroupActionsExamples.GetGroupMemberList.response;
|
|
|
|
async _handle (payload: PayloadType) {
|
|
const groupIdStr = payload.group_id.toString();
|
|
const noCache = this.parseBoolean(payload.no_cache ?? false);
|
|
const groupMembers = await this.getGroupMembers(groupIdStr, noCache);
|
|
const _groupMembers = await Promise.all(
|
|
Array.from(groupMembers.values()).map(item =>
|
|
OB11Construct.groupMember(groupIdStr, item)
|
|
)
|
|
);
|
|
return Array.from(new Map(_groupMembers.map(member => [member.user_id, member])).values());
|
|
}
|
|
|
|
private parseBoolean (value: boolean | string): boolean {
|
|
return typeof value === 'string' ? value === 'true' : value;
|
|
}
|
|
|
|
private async getGroupMembers (groupIdStr: string, noCache: boolean): Promise<Map<string, GroupMember>> {
|
|
const memberCache = this.core.apis.GroupApi.groupMemberCache;
|
|
let groupMembers = memberCache.get(groupIdStr);
|
|
|
|
if (noCache || !groupMembers) {
|
|
const data = this.core.apis.GroupApi.refreshGroupMemberCache(groupIdStr, true).then().catch();
|
|
groupMembers = memberCache.get(groupIdStr) || (await data);
|
|
if (!groupMembers) {
|
|
throw new Error(`Failed to get group member list for group ${groupIdStr}`);
|
|
}
|
|
}
|
|
|
|
return groupMembers;
|
|
}
|
|
}
|