chore: api

This commit is contained in:
手瓜一十雪 2024-08-09 13:58:26 +08:00
parent 958709faf2
commit aaa874b099
7 changed files with 20 additions and 17 deletions

View File

@ -8,7 +8,7 @@ import {
import path from 'path'; import path from 'path';
import fs from 'fs'; import fs from 'fs';
import fsPromises from 'fs/promises'; import fsPromises from 'fs/promises';
import { InstanceContext, NapCatCore } from '@/core'; import { InstanceContext, NapCatCore, OnRichMediaDownloadCompleteParams } from '@/core';
import * as fileType from 'file-type'; import * as fileType from 'file-type';
import imageSize from 'image-size'; import imageSize from 'image-size';
import { ISizeCalculationResult } from 'image-size/dist/types/interface'; import { ISizeCalculationResult } from 'image-size/dist/types/interface';

View File

@ -40,7 +40,7 @@ export class NTQQGroupApi {
* } * }
*/ */
async getGroupMemberLastestSendTime(GroupCode: string) { async getGroupMemberLastestSendTime(GroupCode: string) {
async function getdata(uid: string) { const getdata = async (uid: string) => {
let NTRet = await this.getLastestMsgByUids(GroupCode, [uid]); let NTRet = await this.getLastestMsgByUids(GroupCode, [uid]);
if (NTRet.result != 0 && NTRet.msgList.length < 1) { if (NTRet.result != 0 && NTRet.msgList.length < 1) {
return undefined; return undefined;

View File

@ -207,14 +207,14 @@ export class NTQQMsgApi {
return this.context.session.getMSFService().getServerTime(); return this.context.session.getMSFService().getServerTime();
} }
async getServerTimeV2() { async getServerTimeV2() {
return this.core.eventWrapper.CallNoListenerEvent<() => string>('NodeIKernelMsgService/getServerTime', 5000); return this.core.eventWrapper.callNoListenerEvent<() => string>('NodeIKernelMsgService/getServerTime', 5000);
} }
async forwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) { async forwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
return this.context.session.getMsgService().forwardMsg(msgIds, srcPeer, [destPeer], new Map()); return this.context.session.getMsgService().forwardMsg(msgIds, srcPeer, [destPeer], new Map());
} }
async multiForwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]): Promise<RawMessage> { async multiForwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]): Promise<RawMessage> {
const msgInfos = msgIds.map(id => { const msgInfos = msgIds.map(id => {
return { msgId: id, senderShowName: selfInfo.nick }; return { msgId: id, senderShowName: this.core.selfInfo.nick };
}); });
let data = await this.core.eventWrapper.CallNormalEvent< let data = await this.core.eventWrapper.CallNormalEvent<
(msgInfo: typeof msgInfos, srcPeer: Peer, destPeer: Peer, comment: Array<any>, attr: Map<any, any>,) => Promise<unknown>, (msgInfo: typeof msgInfos, srcPeer: Peer, destPeer: Peer, comment: Array<any>, attr: Map<any, any>,) => Promise<unknown>,
@ -226,7 +226,7 @@ export class NTQQMsgApi {
5000, 5000,
(msgRecords: RawMessage[]) => { (msgRecords: RawMessage[]) => {
for (let msgRecord of msgRecords) { for (let msgRecord of msgRecords) {
if (msgRecord.peerUid == destPeer.peerUid && msgRecord.senderUid == selfInfo.uid) { if (msgRecord.peerUid == destPeer.peerUid && msgRecord.senderUid == this.core.selfInfo.uid) {
return true; return true;
} }
} }
@ -247,7 +247,7 @@ export class NTQQMsgApi {
if (forwardData.app != 'com.tencent.multimsg') { if (forwardData.app != 'com.tencent.multimsg') {
continue; continue;
} }
if (msg.peerUid == destPeer.peerUid && msg.senderUid == selfInfo.uid) { if (msg.peerUid == destPeer.peerUid && msg.senderUid == this.core.selfInfo.uid) {
return msg; return msg;
} }
} }

View File

@ -154,7 +154,7 @@ export class NTQQUserApi {
return profile; return profile;
} }
async modifySelfProfile(param: ModifyProfileParams) { async modifySelfProfile(param: ModifyProfileParams) {
return napCatCore.session.getProfileService().modifyDesktopMiniProfile(param); return this.context.session.getProfileService().modifyDesktopMiniProfile(param);
} }
//需要异常处理 //需要异常处理
async getCookies(domain: string) { async getCookies(domain: string) {
@ -224,10 +224,10 @@ export class NTQQUserApi {
if (uid) return uid; if (uid) return uid;
uid = (await this.context.session.getUixConvertService().getUid([Uin])).uidInfo.get(Uin); uid = (await this.context.session.getUixConvertService().getUid([Uin])).uidInfo.get(Uin);
if (uid) return uid; if (uid) return uid;
console.log((await NTQQFriendApi.getBuddyIdMapCache(true))); console.log((await this.core.getApiContext().FriendApi.getBuddyIdMapCache(true)));
uid = (await NTQQFriendApi.getBuddyIdMapCache(true)).getValue(Uin);//从Buddy缓存获取Uid uid = (await this.core.getApiContext().FriendApi.getBuddyIdMapCache(true)).getValue(Uin);//从Buddy缓存获取Uid
if (uid) return uid; if (uid) return uid;
uid = (await NTQQFriendApi.getBuddyIdMap(true)).getValue(Uin); uid = (await this.core.getApiContext().FriendApi.getBuddyIdMap(true)).getValue(Uin);
if (uid) return uid; if (uid) return uid;
let unveifyUid = (await this.getUserDetailInfoByUinV2(Uin)).detail.uid;//从QQ Native 特殊转换 let unveifyUid = (await this.getUserDetailInfoByUinV2(Uin)).detail.uid;//从QQ Native 特殊转换
if (unveifyUid.indexOf("*") == -1) uid = unveifyUid; if (unveifyUid.indexOf("*") == -1) uid = unveifyUid;
@ -242,9 +242,9 @@ export class NTQQUserApi {
if (uin) return uin; if (uin) return uin;
uin = (await this.context.session.getUixConvertService().getUin([Uid])).uinInfo.get(Uid); uin = (await this.context.session.getUixConvertService().getUin([Uid])).uinInfo.get(Uid);
if (uin) return uin; if (uin) return uin;
uin = (await NTQQFriendApi.getBuddyIdMapCache(true)).getKey(Uid);//从Buddy缓存获取Uin uin = (await this.core.getApiContext().FriendApi.getBuddyIdMapCache(true)).getKey(Uid);//从Buddy缓存获取Uin
if (uin) return uin; if (uin) return uin;
uin = (await NTQQFriendApi.getBuddyIdMap(true)).getKey(Uid); uin = (await this.core.getApiContext().FriendApi.getBuddyIdMap(true)).getKey(Uid);
if (uin) return uin; if (uin) return uin;
uin = (await this.getUserDetailInfo(Uid)).uin; //从QQ Native 转换 uin = (await this.getUserDetailInfo(Uid)).uin; //从QQ Native 转换
return uin; return uin;

View File

@ -8,7 +8,7 @@ import { MsgListener, ProfileListener } from "./listeners";
import { sleep } from "@/common/utils/helper"; import { sleep } from "@/common/utils/helper";
import { SelfInfo, LineDevice, SelfStatusInfo } from "./entities"; import { SelfInfo, LineDevice, SelfStatusInfo } from "./entities";
import { LegacyNTEventWrapper } from "@/common/framework/event-legacy"; import { LegacyNTEventWrapper } from "@/common/framework/event-legacy";
import { NTQQGroupApi, NTQQMsgApi, NTQQUserApi } from "./apis"; import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, NTQQUserApi } from "./apis";
export enum NapCatCoreWorkingEnv { export enum NapCatCoreWorkingEnv {
Unknown = 0, Unknown = 0,
@ -41,9 +41,10 @@ export class NapCatCore {
this.eventWrapper = new LegacyNTEventWrapper(context.wrapper, context.session); this.eventWrapper = new LegacyNTEventWrapper(context.wrapper, context.session);
this.initNapCatCoreListeners().then().catch(console.error); this.initNapCatCoreListeners().then().catch(console.error);
this.ApiContext = { this.ApiContext = {
FriendApi: new NTQQFriendApi(this.context,this),
MsgApi: new NTQQMsgApi(this.context,this), MsgApi: new NTQQMsgApi(this.context,this),
UserApi: new NTQQUserApi(this.context), UserApi: new NTQQUserApi(this.context,this),
GroupApi: new NTQQGroupApi(this.context) GroupApi: new NTQQGroupApi(this.context,this)
} }
} }
getApiContext() { getApiContext() {

View File

@ -2,3 +2,4 @@ export * from './core';
export * from './wrapper'; export * from './wrapper';
export * from './entities'; export * from './entities';
export * from './services'; export * from './services';
export * from './listeners'

View File

@ -4,7 +4,7 @@ import { NapCatCoreWorkingEnv } from "@/core";
import { SelfInfo } from "../entities"; import { SelfInfo } from "../entities";
import { NodeIKernelLoginService } from "../services"; import { NodeIKernelLoginService } from "../services";
import { WrapperNodeApi, NodeIQQNTWrapperSession } from "@/core"; import { WrapperNodeApi, NodeIQQNTWrapperSession } from "@/core";
import { NTQQGroupApi, NTQQMsgApi, NTQQUserApi } from "../apis"; import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, NTQQUserApi } from "../apis";
export interface InstanceContext { export interface InstanceContext {
readonly workingEnv: NapCatCoreWorkingEnv; readonly workingEnv: NapCatCoreWorkingEnv;
@ -15,6 +15,7 @@ export interface InstanceContext {
readonly basicInfoWrapper: QQBasicInfoWrapper; readonly basicInfoWrapper: QQBasicInfoWrapper;
} }
export interface NTApiContext { export interface NTApiContext {
FriendApi: NTQQFriendApi,
MsgApi: NTQQMsgApi, MsgApi: NTQQMsgApi,
UserApi: NTQQUserApi, UserApi: NTQQUserApi,
GroupApi: NTQQGroupApi GroupApi: NTQQGroupApi