update: optimize entity factory (formerly converter.ts)

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

View File

@@ -1,4 +1,4 @@
import { OB11Constructor } from '@/onebot/helper/converter';
import { OB11Entities } from '@/onebot/helper/entities';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
@@ -7,7 +7,7 @@ export class GetFriendWithCategory extends BaseAction<void, any> {
async _handle(payload: void) {
return (await this.core.apis.FriendApi.getBuddyV2ExWithCate(true)).map(category => ({
...category,
buddyList: OB11Constructor.friendsV2(category.buddyList),
buddyList: OB11Entities.friendsV2(category.buddyList),
}));
}
}

View File

@@ -1,6 +1,6 @@
import BaseAction from '../BaseAction';
import { OB11User, OB11UserSex } from '../../types';
import { OB11Constructor } from '@/onebot/helper/converter';
import { OB11User, OB11UserSex } from '@/onebot';
import { OB11Entities } from '@/onebot/helper/entities';
import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import { calcQQLevel } from '@/common/utils/helper';
@@ -41,6 +41,6 @@ export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11Use
return ret;
}
const data = { ...extendData, ...(await NTQQUserApi.getUserDetailInfo(uid)) };
return OB11Constructor.stranger(data);
return OB11Entities.stranger(data);
}
}

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

View File

@@ -1,5 +1,5 @@
import { OB11User } from '../../types';
import { OB11Constructor } from '@/onebot/helper/converter';
import { OB11User } from '@/onebot';
import { OB11Entities } from '@/onebot/helper/entities';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
@@ -7,7 +7,7 @@ class GetLoginInfo extends BaseAction<null, OB11User> {
actionName = ActionName.GetLoginInfo;
async _handle(payload: null) {
return OB11Constructor.selfInfo(this.core.selfInfo);
return OB11Entities.selfInfo(this.core.selfInfo);
}
}

View File

@@ -1,5 +1,5 @@
import { OB11User } from '../../types';
import { OB11Constructor } from '@/onebot/helper/converter';
import { OB11User } from '@/onebot';
import { OB11Entities } from '@/onebot/helper/entities';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
@@ -20,6 +20,6 @@ export default class GetFriendList extends BaseAction<Payload, OB11User[]> {
async _handle(payload: Payload) {
//全新逻辑
const NTQQFriendApi = this.core.apis.FriendApi;
return OB11Constructor.friendsV2(await NTQQFriendApi.getBuddyV2(typeof payload.no_cache === 'string' ? payload.no_cache === 'true' : !!payload.no_cache));
return OB11Entities.friendsV2(await NTQQFriendApi.getBuddyV2(typeof payload.no_cache === 'string' ? payload.no_cache === 'true' : !!payload.no_cache));
}
}