update: optimize entity factory (formerly converter.ts)

This commit is contained in:
Seijo Cecilia
2024-08-26 14:36:10 +08:00
parent e3e5a1bcdb
commit 9ea5c413d3
11 changed files with 51 additions and 64 deletions

View File

@@ -1,5 +1,5 @@
import { OB11Group } from '../../types';
import { OB11Constructor } from '@/onebot/helper/converter';
import { OB11Group } from '@/onebot';
import { OB11Entities } from '@/onebot/helper/entities';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
@@ -22,7 +22,7 @@ class GetGroupInfo extends BaseAction<Payload, OB11Group> {
const NTQQGroupApi = this.core.apis.GroupApi;
const group = (await NTQQGroupApi.getGroups()).find(e => e.groupCode == payload.group_id.toString());
if (!group) throw `${payload.group_id}不存在`;
return OB11Constructor.group(group);
return OB11Entities.group(group);
}
}

View File

@@ -1,5 +1,5 @@
import { OB11Group } from '../../types';
import { OB11Constructor } from '@/onebot/helper/converter';
import { OB11Group } from '@/onebot';
import { OB11Entities } from '@/onebot/helper/entities';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { Group } from '@/core/entities';
@@ -21,7 +21,7 @@ class GetGroupList extends BaseAction<Payload, OB11Group[]> {
async _handle(payload: Payload) {
const NTQQGroupApi = this.core.apis.GroupApi;
const groupList: Group[] = await NTQQGroupApi.getGroups(typeof payload.no_cache === 'string' ? payload.no_cache === 'true' : !!payload.no_cache);
return OB11Constructor.groups(groupList);
return OB11Entities.groups(groupList);
}
}

View File

@@ -1,5 +1,5 @@
import { OB11GroupMember } from '../../types';
import { OB11Constructor } from '@/onebot/helper/converter';
import { OB11GroupMember } from '@/onebot';
import { OB11Entities } from '@/onebot/helper/entities';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
@@ -39,7 +39,7 @@ class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
this.core.context.logger.logDebug(`获取群成员详细信息失败, 只能返回基础信息 ${info.reason}`);
}
const date = Math.round(Date.now() / 1000);
const retMember = OB11Constructor.groupMember(payload.group_id.toString(), member.value as GroupMember);
const retMember = OB11Entities.groupMember(payload.group_id.toString(), member.value as GroupMember);
const Member = await this.core.apis.GroupApi.getGroupMember(payload.group_id.toString(), retMember.user_id);
retMember.last_sent_time = parseInt(Member?.lastSpeakTime || date.toString());
retMember.join_time = parseInt(Member?.joinTime || date.toString());

View File

@@ -1,5 +1,5 @@
import { OB11GroupMember } from '../../types';
import { OB11Constructor } from '@/onebot/helper/converter';
import { OB11GroupMember } from '@/onebot';
import { OB11Entities } from '@/onebot/helper/entities';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
@@ -26,7 +26,7 @@ class GetGroupMemberList extends BaseAction<Payload, OB11GroupMember[]> {
const groupMembersArr = Array.from(groupMembers.values());
let _groupMembers = groupMembersArr.map(item => {
return OB11Constructor.groupMember(payload.group_id.toString(), item);
return OB11Entities.groupMember(payload.group_id.toString(), item);
});
const MemberMap: Map<number, OB11GroupMember> = new Map<number, OB11GroupMember>();