refactor: inline getApiContext()

This commit is contained in:
Wesley F. Young
2024-08-11 19:10:42 +08:00
parent 9f9749548a
commit e7e8e99946
71 changed files with 173 additions and 167 deletions

View File

@@ -1,14 +1,17 @@
import {
ChatType,
GeneralCallResult,
Group,
GroupMember,
GroupMemberRole,
GroupNotify,
GroupRequestOperateTypes,
InstanceContext,
MemberExtSourceType,
NapCatCore,
NodeIKernelGroupListener,
NodeIKernelGroupService,
} from '@/core';
import { GeneralCallResult, InstanceContext, NapCatCore, NodeIKernelGroupService } from '@/core';
import { isNumeric, runAllWithTimeout } from '@/common/utils/helper';
export class NTQQGroupApi {
@@ -164,7 +167,7 @@ export class NTQQGroupApi {
async getLatestMsg(GroupCode: string, uins: string[]) {
const uids: Array<string> = [];
for (const uin of uins) {
const uid = await this.core.getApiContext().UserApi.getUidByUin(uin);
const uid = await this.core.apis.UserApi.getUidByUin(uin);
if (uid) {
uids.push(uid);
}
@@ -313,7 +316,7 @@ export class NTQQGroupApi {
//需要异常处理
async uploadGroupBulletinPic(GroupCode: string, imageurl: string) {
const _Pskey = (await this.core.getApiContext().UserApi.getPSkey(['qun.qq.com'])).domainPskeyMap.get('qun.qq.com')!;
const _Pskey = (await this.core.apis.UserApi.getPSkey(['qun.qq.com'])).domainPskeyMap.get('qun.qq.com')!;
return this.context.session.getGroupService().uploadGroupBulletinPic(GroupCode, _Pskey, imageurl);
}
@@ -377,7 +380,7 @@ export class NTQQGroupApi {
width: number,
height: number
} | undefined = undefined, pinned: number = 0, confirmRequired: number = 0) {
const _Pskey = (await this.core.getApiContext().UserApi.getPSkey(['qun.qq.com'])).domainPskeyMap.get('qun.qq.com');
const _Pskey = (await this.core.apis.UserApi.getPSkey(['qun.qq.com'])).domainPskeyMap.get('qun.qq.com');
//text是content内容url编码
const data = {
text: encodeURI(content),

View File

@@ -210,7 +210,7 @@ export class NTQQMsgApi {
async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) {
//唉? !我有个想法
if (peer.chatType === ChatType.temp && peer.guildId && peer.guildId !== '') {
let member = await this.core.ApiContext.GroupApi.getGroupMember(peer.guildId, peer.peerUid!);
let member = await this.core.apis.GroupApi.getGroupMember(peer.guildId, peer.peerUid!);
if (member) {
await this.PrepareTempChat(peer.peerUid, peer.guildId, member.nick);
}

View File

@@ -185,8 +185,8 @@ export class NTQQMusicSignApi {
// "view": "eventshare",
// "ver": "0.0.0.1"
// };
const data = (await this.core.getApiContext().UserApi.getQzoneCookies());
const Bkn = this.core.getApiContext().WebApi.getBknFromCookie(data.p_skey);
const data = (await this.core.apis.UserApi.getQzoneCookies());
const Bkn = this.core.apis.WebApi.getBknFromCookie(data.p_skey);
const CookieValue = 'p_skey=' + data.p_skey + '; skey=' + data.skey + '; p_uin=o' + this.core.selfInfo.uin + '; uin=o' + this.core.selfInfo.uin;

View File

@@ -238,9 +238,9 @@ export class NTQQUserApi {
uid = (await this.context.session.getUixConvertService().getUid([Uin])).uidInfo.get(Uin);
if (uid) return uid;
// console.log((await this.core.getApiContext().FriendApi.getBuddyIdMapCache(true)));
uid = (await this.core.getApiContext().FriendApi.getBuddyIdMapCache(true)).getValue(Uin);//从Buddy缓存获取Uid
uid = (await this.core.apis.FriendApi.getBuddyIdMapCache(true)).getValue(Uin);//从Buddy缓存获取Uid
if (uid) return uid;
uid = (await this.core.getApiContext().FriendApi.getBuddyIdMap(true)).getValue(Uin);
uid = (await this.core.apis.FriendApi.getBuddyIdMap(true)).getValue(Uin);
if (uid) return uid;
const unveifyUid = (await this.getUserDetailInfoByUinV2(Uin)).detail.uid;//从QQ Native 特殊转换
if (unveifyUid.indexOf('*') == -1) uid = unveifyUid;
@@ -256,9 +256,9 @@ export class NTQQUserApi {
if (uin) return uin;
uin = (await this.context.session.getUixConvertService().getUin([Uid])).uinInfo.get(Uid);
if (uin) return uin;
uin = (await this.core.getApiContext().FriendApi.getBuddyIdMapCache(true)).getKey(Uid);//从Buddy缓存获取Uin
uin = (await this.core.apis.FriendApi.getBuddyIdMapCache(true)).getKey(Uid);//从Buddy缓存获取Uin
if (uin) return uin;
uin = (await this.core.getApiContext().FriendApi.getBuddyIdMap(true)).getKey(Uid);
uin = (await this.core.apis.FriendApi.getBuddyIdMap(true)).getKey(Uid);
if (uin) return uin;
uin = (await this.getUserDetailInfo(Uid)).uin; //从QQ Native 转换
return uin;

View File

@@ -19,7 +19,7 @@ export class NTQQWebApi {
}
async shareDigest(groupCode: string, msgSeq: string, msgRandom: string, targetGroupCode: string) {
const cookieObject = await this.core.getApiContext().UserApi.getCookies('qun.qq.com');
const cookieObject = await this.core.apis.UserApi.getCookies('qun.qq.com');
const url = `https://qun.qq.com/cgi-bin/group_digest/share_digest?${
new URLSearchParams({
bkn: this.getBknFromCookie(cookieObject),
@@ -37,7 +37,7 @@ export class NTQQWebApi {
}
async getGroupEssenceMsg(GroupCode: string, page_start: string) {
const cookieObject = await this.core.getApiContext().UserApi.getCookies('qun.qq.com');
const cookieObject = await this.core.apis.UserApi.getCookies('qun.qq.com');
const url = `https://qun.qq.com/cgi-bin/group_digest/digest_list?${
new URLSearchParams({
bkn: this.getBknFromCookie(cookieObject),
@@ -62,7 +62,7 @@ export class NTQQWebApi {
async getGroupMembers(GroupCode: string, cached: boolean = true): Promise<WebApiGroupMember[]> {
//logDebug('webapi 获取群成员', GroupCode);
const memberData: Array<WebApiGroupMember> = new Array<WebApiGroupMember>();
const cookieObject = await this.core.getApiContext().UserApi.getCookies('qun.qq.com');
const cookieObject = await this.core.apis.UserApi.getCookies('qun.qq.com');
const retList: Promise<WebApiGroupMemberRet>[] = [];
const fastRet = await RequestUtil.HttpGetJson<WebApiGroupMemberRet>
(`https://qun.qq.com/cgi-bin/qun_mgr/search_group_members?${
@@ -123,7 +123,7 @@ export class NTQQWebApi {
// }
async setGroupNotice(GroupCode: string, Content: string) {
const cookieObject = await this.core.getApiContext().UserApi.getCookies('qun.qq.com');
const cookieObject = await this.core.apis.UserApi.getCookies('qun.qq.com');
let ret: any = undefined;
try {
ret = await RequestUtil.HttpGetJson<any>
@@ -144,7 +144,7 @@ export class NTQQWebApi {
}
async getGroupNotice(GroupCode: string): Promise<undefined | WebApiGroupNoticeRet> {
const cookieObject = await this.core.getApiContext().UserApi.getCookies('qun.qq.com');
const cookieObject = await this.core.apis.UserApi.getCookies('qun.qq.com');
let ret: WebApiGroupNoticeRet | undefined = undefined;
try {
ret = await RequestUtil.HttpGetJson<WebApiGroupNoticeRet>(`https://web.qun.qq.com/cgi-bin/announce/get_t_list?${
@@ -166,7 +166,7 @@ export class NTQQWebApi {
}
async getGroupHonorInfo(groupCode: string, getType: WebHonorType) {
const cookieObject = await this.core.getApiContext().UserApi.getCookies('qun.qq.com');
const cookieObject = await this.core.apis.UserApi.getCookies('qun.qq.com');
const getDataInternal = async (Internal_groupCode: string, Internal_type: number) => {
const url = `https://qun.qq.com/interactive/honorlist?${
new URLSearchParams({