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

View File

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

View File

@@ -185,8 +185,8 @@ export class NTQQMusicSignApi {
// "view": "eventshare", // "view": "eventshare",
// "ver": "0.0.0.1" // "ver": "0.0.0.1"
// }; // };
const data = (await this.core.getApiContext().UserApi.getQzoneCookies()); const data = (await this.core.apis.UserApi.getQzoneCookies());
const Bkn = this.core.getApiContext().WebApi.getBknFromCookie(data.p_skey); 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; 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); uid = (await this.context.session.getUixConvertService().getUid([Uin])).uidInfo.get(Uin);
if (uid) return uid; if (uid) return uid;
// console.log((await this.core.getApiContext().FriendApi.getBuddyIdMapCache(true))); // 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; 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; if (uid) return uid;
const unveifyUid = (await this.getUserDetailInfoByUinV2(Uin)).detail.uid;//从QQ Native 特殊转换 const unveifyUid = (await this.getUserDetailInfoByUinV2(Uin)).detail.uid;//从QQ Native 特殊转换
if (unveifyUid.indexOf('*') == -1) uid = unveifyUid; if (unveifyUid.indexOf('*') == -1) uid = unveifyUid;
@@ -256,9 +256,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 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; 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; 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

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

View File

@@ -28,7 +28,7 @@ export function loadQQWrapper(QQVersion: string): WrapperNodeApi {
export class NapCatCore { export class NapCatCore {
readonly context: InstanceContext; readonly context: InstanceContext;
readonly ApiContext: NTApiContext; readonly apis: NTApiContext;
readonly eventWrapper: LegacyNTEventWrapper; readonly eventWrapper: LegacyNTEventWrapper;
// readonly eventChannel: NTEventChannel; // readonly eventChannel: NTEventChannel;
NapCatDataPath: string; NapCatDataPath: string;
@@ -43,7 +43,7 @@ export class NapCatCore {
this.context = context; this.context = context;
this.util = new this.context.wrapper.NodeQQNTWrapperUtil(); this.util = new this.context.wrapper.NodeQQNTWrapperUtil();
this.eventWrapper = new LegacyNTEventWrapper(context.wrapper, context.session); this.eventWrapper = new LegacyNTEventWrapper(context.wrapper, context.session);
this.ApiContext = { this.apis = {
FileApi: new NTQQFileApi(this.context, this), FileApi: new NTQQFileApi(this.context, this),
SystemApi: new NTQQSystemApi(this.context, this), SystemApi: new NTQQSystemApi(this.context, this),
CollectionApi: new NTQQCollectionApi(this.context, this), CollectionApi: new NTQQCollectionApi(this.context, this),
@@ -63,10 +63,6 @@ export class NapCatCore {
this.initNapCatCoreListeners().then().catch(this.context.logger.logError); this.initNapCatCoreListeners().then().catch(this.context.logger.logError);
} }
getApiContext() {
return this.ApiContext;
}
get dataPath(): string { get dataPath(): string {
let result = this.util.getNTUserDataInfoConfig(); let result = this.util.getNTUserDataInfoConfig();
if (!result) { if (!result) {
@@ -107,13 +103,13 @@ export class NapCatCore {
groupListener.onGroupListUpdate = (updateType, groupList) => { groupListener.onGroupListUpdate = (updateType, groupList) => {
// console.log("onGroupListUpdate", updateType, groupList) // console.log("onGroupListUpdate", updateType, groupList)
groupList.map(g => { groupList.map(g => {
const existGroup = this.ApiContext.GroupApi.groupCache.get(g.groupCode); const existGroup = this.apis.GroupApi.groupCache.get(g.groupCode);
//群成员数量变化 应该刷新缓存 //群成员数量变化 应该刷新缓存
if (existGroup && g.memberCount === existGroup.memberCount) { if (existGroup && g.memberCount === existGroup.memberCount) {
Object.assign(existGroup, g); Object.assign(existGroup, g);
} }
else { else {
this.ApiContext.GroupApi.groupCache.set(g.groupCode, g); this.apis.GroupApi.groupCache.set(g.groupCode, g);
// 获取群成员 // 获取群成员
} }
const sceneId = this.context.session.getGroupService().createMemberListScene(g.groupCode, 'groupMemberList_MainWindow'); const sceneId = this.context.session.getGroupService().createMemberListScene(g.groupCode, 'groupMemberList_MainWindow');
@@ -128,8 +124,8 @@ export class NapCatCore {
groupListener.onMemberListChange = (arg) => { groupListener.onMemberListChange = (arg) => {
// todo: 应该加一个内部自己维护的成员变动callback用于判断成员变化通知 // todo: 应该加一个内部自己维护的成员变动callback用于判断成员变化通知
const groupCode = arg.sceneId.split('_')[0]; const groupCode = arg.sceneId.split('_')[0];
if (this.ApiContext.GroupApi.groupMemberCache.has(groupCode)) { if (this.apis.GroupApi.groupMemberCache.has(groupCode)) {
const existMembers = this.ApiContext.GroupApi.groupMemberCache.get(groupCode)!; const existMembers = this.apis.GroupApi.groupMemberCache.get(groupCode)!;
arg.infos.forEach((member, uid) => { arg.infos.forEach((member, uid) => {
//console.log('onMemberListChange', member); //console.log('onMemberListChange', member);
const existMember = existMembers.get(uid); const existMember = existMembers.get(uid);
@@ -146,7 +142,7 @@ export class NapCatCore {
}); });
} }
else { else {
this.ApiContext.GroupApi.groupMemberCache.set(groupCode, arg.infos); this.apis.GroupApi.groupMemberCache.set(groupCode, arg.infos);
} }
// console.log('onMemberListChange', groupCode, arg); // console.log('onMemberListChange', groupCode, arg);
}; };
@@ -155,11 +151,11 @@ export class NapCatCore {
if (changeType === 0 && members.get(this.selfInfo.uid)?.isDelete) { if (changeType === 0 && members.get(this.selfInfo.uid)?.isDelete) {
// 自身退群或者被踢退群 5s用于Api操作 之后不再出现 // 自身退群或者被踢退群 5s用于Api操作 之后不再出现
setTimeout(() => { setTimeout(() => {
this.ApiContext.GroupApi.groupCache.delete(groupCode); this.apis.GroupApi.groupCache.delete(groupCode);
}, 5000); }, 5000);
} }
const existMembers = this.ApiContext.GroupApi.groupMemberCache.get(groupCode); const existMembers = this.apis.GroupApi.groupMemberCache.get(groupCode);
if (existMembers) { if (existMembers) {
members.forEach((member, uid) => { members.forEach((member, uid) => {
const existMember = existMembers.get(uid); const existMember = existMembers.get(uid);
@@ -179,7 +175,7 @@ export class NapCatCore {
}); });
} }
else { else {
this.ApiContext.GroupApi.groupMemberCache.set(groupCode, members); this.apis.GroupApi.groupMemberCache.set(groupCode, members);
} }
}; };
} }

View File

@@ -18,7 +18,7 @@ export class CreateCollection extends BaseAction<Payload, any> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
return await this.CoreContext.getApiContext().CollectionApi.createCollection( return await this.CoreContext.apis.CollectionApi.createCollection(
this.CoreContext.selfInfo.uin, this.CoreContext.selfInfo.uin,
this.CoreContext.selfInfo.uid, this.CoreContext.selfInfo.uid,
this.CoreContext.selfInfo.nick, this.CoreContext.selfInfo.nick,

View File

@@ -17,7 +17,7 @@ export class FetchCustomFace extends BaseAction<Payload, string[]> {
async _handle(payload: Payload) { async _handle(payload: Payload) {
//48 可能正好是QQ需要的一个页面的数量 Tagged Mlikiowa //48 可能正好是QQ需要的一个页面的数量 Tagged Mlikiowa
const ret = await this.CoreContext.getApiContext().MsgApi.fetchFavEmojiList(payload.count || 48); const ret = await this.CoreContext.apis.MsgApi.fetchFavEmojiList(payload.count || 48);
return ret.emojiInfoList.map(e => e.url); return ret.emojiInfoList.map(e => e.url);
} }
} }

View File

@@ -24,7 +24,7 @@ export class FetchEmojiLike extends BaseAction<Payload, any> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi; const NTQQMsgApi = this.CoreContext.apis.MsgApi;
const msgIdPeer = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString())); const msgIdPeer = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
if (!msgIdPeer) throw new Error('消息不存在'); if (!msgIdPeer) throw new Error('消息不存在');
const msg = (await NTQQMsgApi.getMsgsByMsgId(msgIdPeer.Peer, [msgIdPeer.MsgId])).msgList[0]; const msg = (await NTQQMsgApi.getMsgsByMsgId(msgIdPeer.Peer, [msgIdPeer.MsgId])).msgList[0];

View File

@@ -18,7 +18,7 @@ export class GetCollectionList extends BaseAction<Payload, any> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQCollectionApi = this.CoreContext.getApiContext().CollectionApi; const NTQQCollectionApi = this.CoreContext.apis.CollectionApi;
return await NTQQCollectionApi.getAllCollection(payload.category, payload.count); return await NTQQCollectionApi.getAllCollection(payload.category, payload.count);
} }
} }

View File

@@ -8,7 +8,7 @@ export class GetFriendWithCategory extends BaseAction<void, any> {
async _handle(payload: void) { async _handle(payload: void) {
if (this.CoreContext.context.basicInfoWrapper.requireMinNTQQBuild('26702')) { if (this.CoreContext.context.basicInfoWrapper.requireMinNTQQBuild('26702')) {
//全新逻辑 //全新逻辑
return OB11Constructor.friendsV2(await this.CoreContext.getApiContext().FriendApi.getBuddyV2ExWithCate(true)); return OB11Constructor.friendsV2(await this.CoreContext.apis.FriendApi.getBuddyV2ExWithCate(true));
} else { } else {
throw new Error('this ntqq version not support, must be 26702 or later'); throw new Error('this ntqq version not support, must be 26702 or later');
} }

View File

@@ -11,7 +11,7 @@ export default class GetGroupAddRequest extends BaseAction<null, OB11GroupReques
actionName = ActionName.GetGroupIgnoreAddRequest; actionName = ActionName.GetGroupIgnoreAddRequest;
async _handle(payload: null): Promise<OB11GroupRequestNotify[] | null> { async _handle(payload: null): Promise<OB11GroupRequestNotify[] | null> {
const data = await this.CoreContext.getApiContext().GroupApi.getGroupIgnoreNotifies(); const data = await this.CoreContext.apis.GroupApi.getGroupIgnoreNotifies();
// log(data); // log(data);
// const notifies: GroupNotify[] = data.notifies.filter(notify => notify.status === GroupNotifyStatus.WAIT_HANDLE); // const notifies: GroupNotify[] = data.notifies.filter(notify => notify.status === GroupNotifyStatus.WAIT_HANDLE);
// const returnData: OB11GroupRequestNotify[] = []; // const returnData: OB11GroupRequestNotify[] = [];

View File

@@ -5,7 +5,7 @@ export class GetProfileLike extends BaseAction<void, any> {
actionName = ActionName.GetProfileLike; actionName = ActionName.GetProfileLike;
async _handle(payload: void) { async _handle(payload: void) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
const ret = await NTQQUserApi.getProfileLike(this.CoreContext.selfInfo.uid); const ret = await NTQQUserApi.getProfileLike(this.CoreContext.selfInfo.uid);
const listdata: any[] = ret.info.userLikeInfos[0].favoriteInfo.userInfos; const listdata: any[] = ret.info.userLikeInfos[0].favoriteInfo.userInfos;
for (let i = 0; i < listdata.length; i++) { for (let i = 0; i < listdata.length; i++) {

View File

@@ -6,7 +6,7 @@ export class GetRobotUinRange extends BaseAction<void, Array<any>> {
async _handle(payload: void) { async _handle(payload: void) {
// console.log(await NTQQUserApi.getRobotUinRange()); // console.log(await NTQQUserApi.getRobotUinRange());
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
return await NTQQUserApi.getRobotUinRange(); return await NTQQUserApi.getRobotUinRange();
} }
} }

View File

@@ -19,7 +19,7 @@ export class OCRImage extends BaseAction<Payload, any> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQSystemApi = this.CoreContext.getApiContext().SystemApi; const NTQQSystemApi = this.CoreContext.apis.SystemApi;
const { path, isLocal, errMsg, success } = (await uri2local(this.CoreContext.NapCatTempPath, payload.image)); const { path, isLocal, errMsg, success } = (await uri2local(this.CoreContext.NapCatTempPath, payload.image));
if (!success) { if (!success) {
throw `OCR ${payload.image}失败,image字段可能格式不正确`; throw `OCR ${payload.image}失败,image字段可能格式不正确`;

View File

@@ -27,7 +27,7 @@ export default class SetGroupHeader extends BaseAction<Payload, any> {
} }
async _handle(payload: Payload): Promise<any> { async _handle(payload: Payload): Promise<any> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
const { path, isLocal, errMsg, success } = (await uri2local(this.CoreContext.NapCatTempPath, payload.file)); const { path, isLocal, errMsg, success } = (await uri2local(this.CoreContext.NapCatTempPath, payload.file));
if (!success) { if (!success) {
throw `头像${payload.file}设置失败,file字段可能格式不正确`; throw `头像${payload.file}设置失败,file字段可能格式不正确`;

View File

@@ -17,7 +17,7 @@ export class SetLongNick extends BaseAction<Payload, any> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
const ret = await NTQQUserApi.setLongNick(payload.longNick); const ret = await NTQQUserApi.setLongNick(payload.longNick);
return ret; return ret;
} }

View File

@@ -26,7 +26,7 @@ export class SetOnlineStatus extends BaseAction<Payload, null> {
// { status: 50, extStatus: 0, batteryStatus: 0 } // { status: 50, extStatus: 0, batteryStatus: 0 }
// { status: 60, extStatus: 0, batteryStatus: 0 } // { status: 60, extStatus: 0, batteryStatus: 0 }
// { status: 70, extStatus: 0, batteryStatus: 0 } // { status: 70, extStatus: 0, batteryStatus: 0 }
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
const ret = await NTQQUserApi.setSelfOnlineStatus(payload.status, payload.extStatus, payload.batteryStatus); const ret = await NTQQUserApi.setSelfOnlineStatus(payload.status, payload.extStatus, payload.batteryStatus);
if (ret.result !== 0) { if (ret.result !== 0) {
throw new Error('设置在线状态失败'); throw new Error('设置在线状态失败');

View File

@@ -24,7 +24,7 @@ export default class SetAvatar extends BaseAction<Payload, null> {
} }
async _handle(payload: Payload): Promise<null> { async _handle(payload: Payload): Promise<null> {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
const { path, isLocal, errMsg, success } = (await uri2local(this.CoreContext.NapCatTempPath, payload.file)); const { path, isLocal, errMsg, success } = (await uri2local(this.CoreContext.NapCatTempPath, payload.file));
if (!success) { if (!success) {
throw `头像${payload.file}设置失败,file字段可能格式不正确`; throw `头像${payload.file}设置失败,file字段可能格式不正确`;

View File

@@ -19,7 +19,7 @@ export class SetSelfProfile extends BaseAction<Payload, any | null> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
const ret = await NTQQUserApi.modifySelfProfile({ const ret = await NTQQUserApi.modifySelfProfile({
nick: payload.nick, nick: payload.nick,
longNick: payload.longNick, longNick: payload.longNick,

View File

@@ -19,8 +19,8 @@ export class SharePeer extends BaseAction<Payload, any> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
if (payload.group_id) { if (payload.group_id) {
return await NTQQGroupApi.getGroupRecommendContactArkJson(payload.group_id); return await NTQQGroupApi.getGroupRecommendContactArkJson(payload.group_id);
} else if (payload.user_id) { } else if (payload.user_id) {
@@ -44,7 +44,7 @@ export class ShareGroupEx extends BaseAction<PayloadGroupEx, any> {
PayloadSchema = SchemaDataGroupEx; PayloadSchema = SchemaDataGroupEx;
async _handle(payload: PayloadGroupEx) { async _handle(payload: PayloadGroupEx) {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
return await NTQQGroupApi.getArkJsonGroupShare(payload.group_id); return await NTQQGroupApi.getArkJsonGroupShare(payload.group_id);
} }
} }

View File

@@ -20,7 +20,7 @@ export class TranslateEnWordToZn extends BaseAction<Payload, Array<any> | null>
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQSystemApi = this.CoreContext.getApiContext().SystemApi; const NTQQSystemApi = this.CoreContext.apis.SystemApi;
const ret = await NTQQSystemApi.translateEnWordToZn(payload.words); const ret = await NTQQSystemApi.translateEnWordToZn(payload.words);
if (ret.result !== 0) { if (ret.result !== 0) {
throw new Error('翻译失败'); throw new Error('翻译失败');

View File

@@ -18,7 +18,7 @@ export class DelGroupFile extends BaseAction<Payload, any> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
return await NTQQGroupApi.DelGroupFile(payload.group_id.toString(), [payload.file_id]); return await NTQQGroupApi.DelGroupFile(payload.group_id.toString(), [payload.file_id]);
} }
} }

View File

@@ -18,7 +18,7 @@ export class DelGroupFileFolder extends BaseAction<Payload, any> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
return (await NTQQGroupApi.DelGroupFileFolder(payload.group_id.toString(), payload.folder_id)).groupFileCommonResult; return (await NTQQGroupApi.DelGroupFileFolder(payload.group_id.toString(), payload.folder_id)).groupFileCommonResult;
} }
} }

View File

@@ -42,11 +42,11 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
} }
async _handle(payload: GetFilePayload): Promise<GetFileResponse> { async _handle(payload: GetFilePayload): Promise<GetFileResponse> {
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi; const NTQQFriendApi = this.CoreContext.apis.FriendApi;
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi; const NTQQMsgApi = this.CoreContext.apis.MsgApi;
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
const NTQQFileApi = this.CoreContext.getApiContext().FileApi; const NTQQFileApi = this.CoreContext.apis.FileApi;
let UuidData: { let UuidData: {
high: string; high: string;
low: string; low: string;

View File

@@ -17,7 +17,7 @@ export class GetGroupFileCount extends BaseAction<Payload, { count: number }> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
const ret = await NTQQGroupApi.GetGroupFileCount([payload.group_id?.toString()]); const ret = await NTQQGroupApi.GetGroupFileCount([payload.group_id?.toString()]);
return { count: ret.groupFileCounts[0] }; return { count: ret.groupFileCounts[0] };
} }

View File

@@ -19,7 +19,7 @@ export class GetGroupFileList extends BaseAction<Payload, { FileList: Array<any>
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi; const NTQQMsgApi = this.CoreContext.apis.MsgApi;
const ret = await NTQQMsgApi.getGroupFileList(payload.group_id.toString(), { const ret = await NTQQMsgApi.getGroupFileList(payload.group_id.toString(), {
sortType: 1, sortType: 1,
fileCount: payload.file_count, fileCount: payload.file_count,

View File

@@ -18,7 +18,7 @@ export class SetGroupFileFolder extends BaseAction<Payload, any> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
return (await NTQQGroupApi.CreatGroupFileFolder(payload.group_id.toString(), payload.folder_name)).resultWithGroupItem; return (await NTQQGroupApi.CreatGroupFileFolder(payload.group_id.toString(), payload.folder_name)).resultWithGroupItem;
} }
} }

View File

@@ -24,7 +24,7 @@ export class GoCQHTTPGetForwardMsgAction extends BaseAction<Payload, any> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload): Promise<any> { async _handle(payload: Payload): Promise<any> {
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi; const NTQQMsgApi = this.CoreContext.apis.MsgApi;
const msgId = payload.message_id || payload.id; const msgId = payload.message_id || payload.id;
if (!msgId) { if (!msgId) {
throw Error('message_id is required'); throw Error('message_id is required');

View File

@@ -28,9 +28,9 @@ export default class GetFriendMsgHistory extends BaseAction<Payload, Response> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload): Promise<Response> { async _handle(payload: Payload): Promise<Response> {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi; const NTQQMsgApi = this.CoreContext.apis.MsgApi;
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi; const NTQQFriendApi = this.CoreContext.apis.FriendApi;
//处理参数 //处理参数
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString()); const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
const MsgCount = payload.count || 20; const MsgCount = payload.count || 20;

View File

@@ -22,7 +22,7 @@ export class GetGroupHonorInfo extends BaseAction<Payload, Array<any>> {
if (!payload.type) { if (!payload.type) {
payload.type = WebHonorType.ALL; payload.type = WebHonorType.ALL;
} }
const NTQQWebApi = this.CoreContext.getApiContext().WebApi; const NTQQWebApi = this.CoreContext.apis.WebApi;
return await NTQQWebApi.getGroupHonorInfo(payload.group_id.toString(), payload.type); return await NTQQWebApi.getGroupHonorInfo(payload.group_id.toString(), payload.type);
} }
} }

View File

@@ -28,7 +28,7 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Resp
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload): Promise<Response> { async _handle(payload: Payload): Promise<Response> {
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi; const NTQQMsgApi = this.CoreContext.apis.MsgApi;
//处理参数 //处理参数
const isReverseOrder = payload.reverseOrder || true; const isReverseOrder = payload.reverseOrder || true;
const MsgCount = payload.count || 20; const MsgCount = payload.count || 20;

View File

@@ -15,7 +15,7 @@ export class GetOnlineClient extends BaseAction<void, Array<any>> {
async _handle(payload: void) { async _handle(payload: void) {
//注册监听 //注册监听
const NTQQSystemApi = this.CoreContext.getApiContext().SystemApi; const NTQQSystemApi = this.CoreContext.apis.SystemApi;
NTQQSystemApi.getOnlineDev(); NTQQSystemApi.getOnlineDev();
await sleep(500); await sleep(500);

View File

@@ -19,7 +19,7 @@ export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11Use
actionName = ActionName.GoCQHTTP_GetStrangerInfo; actionName = ActionName.GoCQHTTP_GetStrangerInfo;
async _handle(payload: Payload): Promise<OB11User> { async _handle(payload: Payload): Promise<OB11User> {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
const user_id = payload.user_id.toString(); const user_id = payload.user_id.toString();
const extendData = await NTQQUserApi.getUserDetailInfoByUin(user_id); const extendData = await NTQQUserApi.getUserDetailInfoByUin(user_id);
const uid = (await NTQQUserApi.getUidByUin(user_id))!; const uid = (await NTQQUserApi.getUidByUin(user_id))!;

View File

@@ -22,7 +22,7 @@ export class SendGroupNotice extends BaseAction<Payload, null> {
actionName = ActionName.GoCQHTTP_SendGroupNotice; actionName = ActionName.GoCQHTTP_SendGroupNotice;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
let UploadImage: { id: string, width: number, height: number } | undefined = undefined; let UploadImage: { id: string, width: number, height: number } | undefined = undefined;
if (payload.image) { if (payload.image) {
//公告图逻辑 //公告图逻辑

View File

@@ -24,8 +24,8 @@ export default class GoCQHTTPUploadPrivateFile extends BaseAction<Payload, null>
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async getPeer(payload: Payload): Promise<Peer> { async getPeer(payload: Payload): Promise<Peer> {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi; const NTQQFriendApi = this.CoreContext.apis.FriendApi;
if (payload.user_id) { if (payload.user_id) {
const peerUid = await NTQQUserApi.getUidByUin(payload.user_id.toString()); const peerUid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
if (!peerUid) { if (!peerUid) {

View File

@@ -18,7 +18,7 @@ export default class DelEssenceMsg extends BaseAction<Payload, any> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload): Promise<any> { async _handle(payload: Payload): Promise<any> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString())); const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
if (!msg) { if (!msg) {
throw new Error('msg not found'); throw new Error('msg not found');

View File

@@ -19,7 +19,7 @@ export class GetGroupEssence extends BaseAction<Payload, GroupEssenceMsgRet> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQWebApi = this.CoreContext.getApiContext().WebApi; const NTQQWebApi = this.CoreContext.apis.WebApi;
const ret = await NTQQWebApi.getGroupEssenceMsg(payload.group_id.toString(), payload.pages.toString()); const ret = await NTQQWebApi.getGroupEssenceMsg(payload.group_id.toString(), payload.pages.toString());
if (!ret) { if (!ret) {
throw new Error('获取失败'); throw new Error('获取失败');

View File

@@ -19,7 +19,7 @@ class GetGroupInfo extends BaseAction<Payload, OB11Group> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
const group = (await NTQQGroupApi.getGroups()).find(e => e.groupCode == payload.group_id.toString()); const group = (await NTQQGroupApi.getGroups()).find(e => e.groupCode == payload.group_id.toString());
if (group) { if (group) {
return OB11Constructor.group(group); return OB11Constructor.group(group);

View File

@@ -19,7 +19,7 @@ class GetGroupList extends BaseAction<Payload, OB11Group[]> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
const groupList: Group[] = await NTQQGroupApi.getGroups(payload?.no_cache === true || payload.no_cache === 'true'); const groupList: Group[] = await NTQQGroupApi.getGroups(payload?.no_cache === true || payload.no_cache === 'true');
return OB11Constructor.groups(groupList); return OB11Constructor.groups(groupList);
} }

View File

@@ -21,9 +21,9 @@ class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
const NTQQWebApi = this.CoreContext.getApiContext().WebApi; const NTQQWebApi = this.CoreContext.apis.WebApi;
const isNocache = payload.no_cache == true || payload.no_cache === 'true'; const isNocache = payload.no_cache == true || payload.no_cache === 'true';
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString()); const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
if (!uid) { if (!uid) {

View File

@@ -20,8 +20,8 @@ class GetGroupMemberList extends BaseAction<Payload, OB11GroupMember[]> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
const NTQQWebApi = this.CoreContext.getApiContext().WebApi; const NTQQWebApi = this.CoreContext.apis.WebApi;
const isNocache = payload.no_cache == true || payload.no_cache === 'true'; const isNocache = payload.no_cache == true || payload.no_cache === 'true';
const GroupList = await NTQQGroupApi.getGroups(isNocache); const GroupList = await NTQQGroupApi.getGroups(isNocache);

View File

@@ -33,7 +33,7 @@ export class GetGroupNotice extends BaseAction<Payload, GroupNotice[]> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQWebApi = this.CoreContext.getApiContext().WebApi; const NTQQWebApi = this.CoreContext.apis.WebApi;
const group = payload.group_id.toString(); const group = payload.group_id.toString();
const ret = await NTQQWebApi.getGroupNotice(group); const ret = await NTQQWebApi.getGroupNotice(group);

View File

@@ -15,8 +15,8 @@ export class GetGroupSystemMsg extends BaseAction<void, any> {
actionName = ActionName.GetGroupSystemMsg; actionName = ActionName.GetGroupSystemMsg;
async _handle(payload: void) { async _handle(payload: void) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
// 默认10条 该api未完整实现 包括响应数据规范化 类型规范化 // 默认10条 该api未完整实现 包括响应数据规范化 类型规范化
const SingleScreenNotifies = await NTQQGroupApi.getSingleScreenNotifies(10); const SingleScreenNotifies = await NTQQGroupApi.getSingleScreenNotifies(10);
const retData: any = { InvitedRequest: [], join_requests: [] }; const retData: any = { InvitedRequest: [], join_requests: [] };

View File

@@ -18,7 +18,7 @@ export default class SetEssenceMsg extends BaseAction<Payload, any> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload): Promise<any> { async _handle(payload: Payload): Promise<any> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString())); const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
if (!msg) { if (!msg) {
throw new Error('msg not found'); throw new Error('msg not found');

View File

@@ -20,7 +20,7 @@ export default class SetGroupAddRequest extends BaseAction<Payload, null> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload): Promise<null> { async _handle(payload: Payload): Promise<null> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
const flag = payload.flag.toString(); const flag = payload.flag.toString();
const approve = payload.approve?.toString() !== 'false'; const approve = payload.approve?.toString() !== 'false';
await NTQQGroupApi.handleGroupRequest(flag, await NTQQGroupApi.handleGroupRequest(flag,

View File

@@ -20,8 +20,8 @@ export default class SetGroupAdmin extends BaseAction<Payload, null> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload): Promise<null> { async _handle(payload: Payload): Promise<null> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString()); const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
if (!uid) throw new Error('get Uid Error'); if (!uid) throw new Error('get Uid Error');
await NTQQGroupApi.setMemberRole(payload.group_id.toString(), uid, payload.enable ? GroupMemberRole.admin : GroupMemberRole.normal); await NTQQGroupApi.setMemberRole(payload.group_id.toString(), uid, payload.enable ? GroupMemberRole.admin : GroupMemberRole.normal);

View File

@@ -19,8 +19,8 @@ export default class SetGroupBan extends BaseAction<Payload, null> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload): Promise<null> { async _handle(payload: Payload): Promise<null> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString()); const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
if (!uid) throw new Error('uid error'); if (!uid) throw new Error('uid error');
await NTQQGroupApi.banMember(payload.group_id.toString(), await NTQQGroupApi.banMember(payload.group_id.toString(),

View File

@@ -19,7 +19,7 @@ export default class SetGroupCard extends BaseAction<Payload, null> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload): Promise<null> { async _handle(payload: Payload): Promise<null> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
const member = await NTQQGroupApi.getGroupMember(payload.group_id.toString(), payload.user_id.toString()); const member = await NTQQGroupApi.getGroupMember(payload.group_id.toString(), payload.user_id.toString());
member && await NTQQGroupApi.setMemberCard(payload.group_id.toString(), member.uid, payload.card || ''); member && await NTQQGroupApi.setMemberCard(payload.group_id.toString(), member.uid, payload.card || '');
return null; return null;

View File

@@ -20,8 +20,8 @@ export default class SetGroupKick extends BaseAction<Payload, null> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload): Promise<null> { async _handle(payload: Payload): Promise<null> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
const rejectReq = payload.reject_add_request?.toString() == 'true'; const rejectReq = payload.reject_add_request?.toString() == 'true';
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString()); const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
if (!uid) throw new Error('get Uid Error'); if (!uid) throw new Error('get Uid Error');

View File

@@ -17,7 +17,7 @@ export default class SetGroupLeave extends BaseAction<Payload, any> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload): Promise<any> { async _handle(payload: Payload): Promise<any> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
await NTQQGroupApi.quitGroup(payload.group_id.toString()); await NTQQGroupApi.quitGroup(payload.group_id.toString());
} }
} }

View File

@@ -17,7 +17,7 @@ export default class SetGroupName extends BaseAction<Payload, null> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload): Promise<null> { async _handle(payload: Payload): Promise<null> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
await NTQQGroupApi.setGroupName(payload.group_id.toString(), payload.group_name); await NTQQGroupApi.setGroupName(payload.group_id.toString(), payload.group_name);
return null; return null;
} }

View File

@@ -19,7 +19,7 @@ export default class SetGroupWholeBan extends BaseAction<Payload, null> {
async _handle(payload: Payload): Promise<null> { async _handle(payload: Payload): Promise<null> {
const enable = payload.enable?.toString() !== 'false'; const enable = payload.enable?.toString() !== 'false';
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
await NTQQGroupApi.banGroup(payload.group_id.toString(), enable); await NTQQGroupApi.banGroup(payload.group_id.toString(), enable);
return null; return null;
} }

View File

@@ -24,7 +24,7 @@ class DeleteMsg extends BaseAction<Payload, void> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi; const NTQQMsgApi = this.CoreContext.apis.MsgApi;
const msg = MessageUnique.getMsgIdAndPeerByShortId(Number(payload.message_id)); const msg = MessageUnique.getMsgIdAndPeerByShortId(Number(payload.message_id));
if (msg) { if (msg) {
const ret = this.CoreContext.eventWrapper.RegisterListen<NodeIKernelMsgListener['onMsgInfoListUpdate']> const ret = this.CoreContext.eventWrapper.RegisterListen<NodeIKernelMsgListener['onMsgInfoListUpdate']>

View File

@@ -18,7 +18,7 @@ type Payload = FromSchema<typeof SchemaData>;
class ForwardSingleMsg extends BaseAction<Payload, null> { class ForwardSingleMsg extends BaseAction<Payload, null> {
protected async getTargetPeer(payload: Payload): Promise<Peer> { protected async getTargetPeer(payload: Payload): Promise<Peer> {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
if (payload.user_id) { if (payload.user_id) {
const peerUid = await NTQQUserApi.getUidByUin(payload.user_id.toString()); const peerUid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
if (!peerUid) { if (!peerUid) {
@@ -30,7 +30,7 @@ class ForwardSingleMsg extends BaseAction<Payload, null> {
} }
async _handle(payload: Payload): Promise<null> { async _handle(payload: Payload): Promise<null> {
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi; const NTQQMsgApi = this.CoreContext.apis.MsgApi;
const msg = MessageUnique.getMsgIdAndPeerByShortId(payload.message_id); const msg = MessageUnique.getMsgIdAndPeerByShortId(payload.message_id);
if (!msg) { if (!msg) {
throw new Error(`无法找到消息${payload.message_id}`); throw new Error(`无法找到消息${payload.message_id}`);

View File

@@ -23,7 +23,7 @@ class GetMsg extends BaseAction<Payload, OB11Message> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi; const NTQQMsgApi = this.CoreContext.apis.MsgApi;
// log("history msg ids", Object.keys(msgHistory)); // log("history msg ids", Object.keys(msgHistory));
if (!payload.message_id) { if (!payload.message_id) {
throw Error('参数message_id不能为空'); throw Error('参数message_id不能为空');

View File

@@ -15,8 +15,8 @@ type PlayloadType = FromSchema<typeof SchemaData>;
class MarkMsgAsRead extends BaseAction<PlayloadType, null> { class MarkMsgAsRead extends BaseAction<PlayloadType, null> {
async getPeer(payload: PlayloadType): Promise<Peer> { async getPeer(payload: PlayloadType): Promise<Peer> {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi; const NTQQFriendApi = this.CoreContext.apis.FriendApi;
if (payload.user_id) { if (payload.user_id) {
const peerUid = await NTQQUserApi.getUidByUin(payload.user_id.toString()); const peerUid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
if (!peerUid) { if (!peerUid) {
@@ -32,7 +32,7 @@ class MarkMsgAsRead extends BaseAction<PlayloadType, null> {
} }
async _handle(payload: PlayloadType): Promise<null> { async _handle(payload: PlayloadType): Promise<null> {
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi; const NTQQMsgApi = this.CoreContext.apis.MsgApi;
// 调用API // 调用API
const ret = await NTQQMsgApi.setMsgRead(await this.getPeer(payload)); const ret = await NTQQMsgApi.setMsgRead(await this.getPeer(payload));
if (ret.result != 0) { if (ret.result != 0) {
@@ -70,7 +70,7 @@ export class MarkAllMsgAsRead extends BaseAction<Payload, null> {
actionName = ActionName._MarkAllMsgAsRead; actionName = ActionName._MarkAllMsgAsRead;
async _handle(payload: Payload): Promise<null> { async _handle(payload: Payload): Promise<null> {
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi; const NTQQMsgApi = this.CoreContext.apis.MsgApi;
await NTQQMsgApi.markallMsgAsRead(); await NTQQMsgApi.markallMsgAsRead();
return null; return null;
} }

View File

@@ -54,7 +54,7 @@ const _handlers: {
// then the qq is a group member // then the qq is a group member
// Mlikiowa V2.0.0 Refactor Todo // Mlikiowa V2.0.0 Refactor Todo
const uid = await coreContext.getApiContext().UserApi.getUidByUin(atQQ); const uid = await coreContext.apis.UserApi.getUidByUin(atQQ);
if (!uid) throw new Error('Get Uid Error'); if (!uid) throw new Error('Get Uid Error');
return SendMsgElementConstructor.at(coreContext, atQQ, uid, AtType.atUser, ''); return SendMsgElementConstructor.at(coreContext, atQQ, uid, AtType.atUser, '');
}, },
@@ -64,7 +64,7 @@ const _handlers: {
coreContext.context.logger.logWarn('回复消息不存在', id); coreContext.context.logger.logWarn('回复消息不存在', id);
return undefined; return undefined;
} }
const NTQQMsgApi = coreContext.getApiContext().MsgApi; const NTQQMsgApi = coreContext.apis.MsgApi;
const replyMsg = (await NTQQMsgApi.getMsgsByMsgId( const replyMsg = (await NTQQMsgApi.getMsgsByMsgId(
replyMsgM.Peer, [replyMsgM.MsgId!])).msgList[0]; replyMsgM.Peer, [replyMsgM.MsgId!])).msgList[0];
return replyMsg ? return replyMsg ?

View File

@@ -10,7 +10,7 @@ async function cloneMsg(coreContext: NapCatCore, msg: RawMessage): Promise<RawMe
peerUid: coreContext.selfInfo.uid, peerUid: coreContext.selfInfo.uid,
}; };
const logger = coreContext.context.logger; const logger = coreContext.context.logger;
const NTQQMsgApi = coreContext.getApiContext().MsgApi; const NTQQMsgApi = coreContext.apis.MsgApi;
//logDebug('克隆的目标消息', msg); //logDebug('克隆的目标消息', msg);
const sendElements: SendMessageElement[] = []; const sendElements: SendMessageElement[] = [];
@@ -31,7 +31,7 @@ async function cloneMsg(coreContext: NapCatCore, msg: RawMessage): Promise<RawMe
} }
export async function handleForwardNode(coreContext: NapCatCore, destPeer: Peer, messageNodes: OB11MessageNode[]): Promise<RawMessage | null> { export async function handleForwardNode(coreContext: NapCatCore, destPeer: Peer, messageNodes: OB11MessageNode[]): Promise<RawMessage | null> {
const NTQQMsgApi = coreContext.getApiContext().MsgApi; const NTQQMsgApi = coreContext.apis.MsgApi;
const selfPeer = { const selfPeer = {
chatType: ChatType.friend, chatType: ChatType.friend,
peerUid: coreContext.selfInfo.uid, peerUid: coreContext.selfInfo.uid,

View File

@@ -37,7 +37,7 @@ export function normalize(message: OB11MessageMixType, autoEscape = false): OB11
export { createSendElements }; export { createSendElements };
export async function sendMsg(coreContext: NapCatCore, peer: Peer, sendElements: SendMessageElement[], deleteAfterSentFiles: string[], waitComplete = true) { export async function sendMsg(coreContext: NapCatCore, peer: Peer, sendElements: SendMessageElement[], deleteAfterSentFiles: string[], waitComplete = true) {
const NTQQMsgApi = coreContext.getApiContext().MsgApi; const NTQQMsgApi = coreContext.apis.MsgApi;
const logger = coreContext.context.logger; const logger = coreContext.context.logger;
if (!sendElements.length) { if (!sendElements.length) {
throw ('消息体无法解析, 请检查是否发送了不支持的消息类型'); throw ('消息体无法解析, 请检查是否发送了不支持的消息类型');
@@ -88,9 +88,9 @@ async function createContext(coreContext: NapCatCore, payload: OB11PostSendMsg,
// This function determines the type of message by the existence of user_id / group_id, // This function determines the type of message by the existence of user_id / group_id,
// not message_type. // not message_type.
// This redundant design of Ob11 here should be blamed. // This redundant design of Ob11 here should be blamed.
const NTQQGroupApi = coreContext.getApiContext().GroupApi; const NTQQGroupApi = coreContext.apis.GroupApi;
const NTQQFriendApi = coreContext.getApiContext().FriendApi; const NTQQFriendApi = coreContext.apis.FriendApi;
const NTQQUserApi = coreContext.getApiContext().UserApi; const NTQQUserApi = coreContext.apis.UserApi;
if ((contextMode === ContextMode.Group || contextMode === ContextMode.Normal) && payload.group_id) { if ((contextMode === ContextMode.Group || contextMode === ContextMode.Normal) && payload.group_id) {
const group = (await NTQQGroupApi.getGroups()).find(e => e.groupCode == payload.group_id?.toString()); const group = (await NTQQGroupApi.getGroups()).find(e => e.groupCode == payload.group_id?.toString());
return { return {
@@ -122,9 +122,9 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
contextMode = ContextMode.Normal; contextMode = ContextMode.Normal;
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> { protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi; const NTQQGroupApi = this.CoreContext.apis.GroupApi;
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi; const NTQQFriendApi = this.CoreContext.apis.FriendApi;
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
const messages = normalize(payload.message); const messages = normalize(payload.message);
const nodeElementLength = getSpecialMsgNum(payload, OB11MessageDataType.node); const nodeElementLength = getSpecialMsgNum(payload, OB11MessageDataType.node);
if (nodeElementLength > 0 && nodeElementLength != messages.length) { if (nodeElementLength > 0 && nodeElementLength != messages.length) {

View File

@@ -19,7 +19,7 @@ export class SetMsgEmojiLike extends BaseAction<Payload, any> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi; const NTQQMsgApi = this.CoreContext.apis.MsgApi;
const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString())); const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
if (!msg) { if (!msg) {
throw new Error('msg not found'); throw new Error('msg not found');

View File

@@ -22,8 +22,8 @@ export class GetCookies extends BaseAction<Payload, Response> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
const NTQQWebApi = this.CoreContext.getApiContext().WebApi; const NTQQWebApi = this.CoreContext.apis.WebApi;
// if (!payload.domain) { // if (!payload.domain) {
// throw new Error('缺少参数 domain'); // throw new Error('缺少参数 domain');
// } // }

View File

@@ -19,7 +19,7 @@ export default class GetFriendList extends BaseAction<Payload, OB11User[]> {
async _handle(payload: Payload) { async _handle(payload: Payload) {
//全新逻辑 //全新逻辑
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi; const NTQQFriendApi = this.CoreContext.apis.FriendApi;
return OB11Constructor.friendsV2(await NTQQFriendApi.getBuddyV2(payload?.no_cache === true || payload?.no_cache === 'true')); return OB11Constructor.friendsV2(await NTQQFriendApi.getBuddyV2(payload?.no_cache === true || payload?.no_cache === 'true'));
} }
} }

View File

@@ -17,8 +17,8 @@ export default class GetRecentContact extends BaseAction<Payload, any> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload) { async _handle(payload: Payload) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi; const NTQQMsgApi = this.CoreContext.apis.MsgApi;
const ret = await NTQQUserApi.getRecentContactListSnapShot(parseInt((payload.count || 10).toString())); const ret = await NTQQUserApi.getRecentContactListSnapShot(parseInt((payload.count || 10).toString()));
const data = await Promise.all(ret.info.changedList.map(async (t) => { const data = await Promise.all(ret.info.changedList.map(async (t) => {
const FastMsg = await NTQQMsgApi.getMsgsByMsgId({ chatType: t.chatType, peerUid: t.peerUid }, [t.msgId]); const FastMsg = await NTQQMsgApi.getMsgsByMsgId({ chatType: t.chatType, peerUid: t.peerUid }, [t.msgId]);

View File

@@ -18,7 +18,7 @@ export default class SendLike extends BaseAction<Payload, null> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload): Promise<null> { async _handle(payload: Payload): Promise<null> {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi; const NTQQUserApi = this.CoreContext.apis.UserApi;
//logDebug('点赞参数', payload); //logDebug('点赞参数', payload);
try { try {
const qq = payload.user_id.toString(); const qq = payload.user_id.toString();

View File

@@ -19,7 +19,7 @@ export default class SetFriendAddRequest extends BaseAction<Payload, null> {
PayloadSchema = SchemaData; PayloadSchema = SchemaData;
async _handle(payload: Payload): Promise<null> { async _handle(payload: Payload): Promise<null> {
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi; const NTQQFriendApi = this.CoreContext.apis.FriendApi;
const approve = payload.approve?.toString() !== 'false'; const approve = payload.approve?.toString() !== 'false';
await NTQQFriendApi.handleFriendRequest(payload.flag, approve); await NTQQFriendApi.handleFriendRequest(payload.flag, approve);
return null; return null;

View File

@@ -46,10 +46,10 @@ import { NapCatCore } from '@/core';
export class OB11Constructor { export class OB11Constructor {
static async message(core: NapCatCore, msg: RawMessage, messagePostFormat: any): Promise<OB11Message> { static async message(core: NapCatCore, msg: RawMessage, messagePostFormat: any): Promise<OB11Message> {
const NTQQGroupApi = core.getApiContext().GroupApi; const NTQQGroupApi = core.apis.GroupApi;
const NTQQUserApi = core.getApiContext().UserApi; const NTQQUserApi = core.apis.UserApi;
const NTQQFileApi = core.getApiContext().FileApi; const NTQQFileApi = core.apis.FileApi;
const NTQQMsgApi = core.getApiContext().MsgApi; const NTQQMsgApi = core.apis.MsgApi;
const logger = core.context.logger; const logger = core.context.logger;
const resMsg: OB11Message = { const resMsg: OB11Message = {
self_id: parseInt(core.selfInfo.uin), self_id: parseInt(core.selfInfo.uin),
@@ -362,7 +362,7 @@ export class OB11Constructor {
} }
static async PrivateEvent(core: NapCatCore, msg: RawMessage): Promise<OB11BaseNoticeEvent | undefined> { static async PrivateEvent(core: NapCatCore, msg: RawMessage): Promise<OB11BaseNoticeEvent | undefined> {
const NTQQUserApi = core.getApiContext().UserApi; const NTQQUserApi = core.apis.UserApi;
if (msg.chatType !== ChatType.friend) { if (msg.chatType !== ChatType.friend) {
return; return;
} }
@@ -400,9 +400,9 @@ export class OB11Constructor {
} }
static async GroupEvent(core: NapCatCore, msg: RawMessage): Promise<OB11GroupNoticeEvent | undefined> { static async GroupEvent(core: NapCatCore, msg: RawMessage): Promise<OB11GroupNoticeEvent | undefined> {
const NTQQGroupApi = core.getApiContext().GroupApi; const NTQQGroupApi = core.apis.GroupApi;
const NTQQUserApi = core.getApiContext().UserApi; const NTQQUserApi = core.apis.UserApi;
const NTQQMsgApi = core.getApiContext().MsgApi; const NTQQMsgApi = core.apis.MsgApi;
const logger = core.context.logger; const logger = core.context.logger;
if (msg.chatType !== ChatType.group) { if (msg.chatType !== ChatType.group) {
return; return;

View File

@@ -24,7 +24,7 @@ export async function logOB11Message(coreContext: NapCatCore, ob11Message: OB11M
// group = await coreContext.ApiContext.GroupApi.getGroup(ob11Message.group_id!.toString()); // group = await coreContext.ApiContext.GroupApi.getGroup(ob11Message.group_id!.toString());
prefix += '转发消息[外部来源] '; prefix += '转发消息[外部来源] ';
} else { } else {
group = await coreContext.ApiContext.GroupApi.getGroup(ob11Message.group_id!.toString()); group = await coreContext.apis.GroupApi.getGroup(ob11Message.group_id!.toString());
prefix += `群[${group?.groupName}(${ob11Message.group_id})] `; prefix += `群[${group?.groupName}(${ob11Message.group_id})] `;
} }
} }
@@ -35,7 +35,7 @@ export async function logOB11Message(coreContext: NapCatCore, ob11Message: OB11M
if (segment.type === 'text') { if (segment.type === 'text') {
msgParts.push(segment.data.text); msgParts.push(segment.data.text);
} else if (segment.type === 'at') { } else if (segment.type === 'at') {
const groupMember = await coreContext.ApiContext.GroupApi.getGroupMember(ob11Message.group_id!, segment.data.qq!); const groupMember = await coreContext.apis.GroupApi.getGroupMember(ob11Message.group_id!, segment.data.qq!);
msgParts.push(spSegColor(`[@${groupMember?.cardName || groupMember?.nick}(${segment.data.qq})]`)); msgParts.push(spSegColor(`[@${groupMember?.cardName || groupMember?.nick}(${segment.data.qq})]`));
} else if (segment.type === 'reply') { } else if (segment.type === 'reply') {
msgParts.push(spSegColor(`[回复消息|id:${segment.data.id}]`)); msgParts.push(spSegColor(`[回复消息|id:${segment.data.id}]`));

View File

@@ -80,11 +80,11 @@ export class SendMsgElementConstructor {
} }
static async pic(coreContext: NapCatCore, picPath: string, summary: string = '', subType: 0 | 1 = 0): Promise<SendPicElement> { static async pic(coreContext: NapCatCore, picPath: string, summary: string = '', subType: 0 | 1 = 0): Promise<SendPicElement> {
const NTQQGroupApi = coreContext.getApiContext().GroupApi; const NTQQGroupApi = coreContext.apis.GroupApi;
const NTQQUserApi = coreContext.getApiContext().UserApi; const NTQQUserApi = coreContext.apis.UserApi;
const NTQQFileApi = coreContext.getApiContext().FileApi; const NTQQFileApi = coreContext.apis.FileApi;
const NTQQMsgApi = coreContext.getApiContext().MsgApi; const NTQQMsgApi = coreContext.apis.MsgApi;
const NTQQFriendApi = coreContext.getApiContext().FriendApi; const NTQQFriendApi = coreContext.apis.FriendApi;
const logger = coreContext.context.logger; const logger = coreContext.context.logger;
const { md5, fileName, path, fileSize } = await NTQQFileApi.uploadFile(picPath, ElementType.PIC, subType); const { md5, fileName, path, fileSize } = await NTQQFileApi.uploadFile(picPath, ElementType.PIC, subType);
if (fileSize === 0) { if (fileSize === 0) {
@@ -115,11 +115,11 @@ export class SendMsgElementConstructor {
} }
static async file(coreContext: NapCatCore, filePath: string, fileName: string = '', folderId: string = ''): Promise<SendFileElement> { static async file(coreContext: NapCatCore, filePath: string, fileName: string = '', folderId: string = ''): Promise<SendFileElement> {
const NTQQGroupApi = coreContext.getApiContext().GroupApi; const NTQQGroupApi = coreContext.apis.GroupApi;
const NTQQUserApi = coreContext.getApiContext().UserApi; const NTQQUserApi = coreContext.apis.UserApi;
const NTQQFileApi = coreContext.getApiContext().FileApi; const NTQQFileApi = coreContext.apis.FileApi;
const NTQQMsgApi = coreContext.getApiContext().MsgApi; const NTQQMsgApi = coreContext.apis.MsgApi;
const NTQQFriendApi = coreContext.getApiContext().FriendApi; const NTQQFriendApi = coreContext.apis.FriendApi;
const logger = coreContext.context.logger; const logger = coreContext.context.logger;
const { md5, fileName: _fileName, path, fileSize } = await NTQQFileApi.uploadFile(filePath, ElementType.FILE); const { md5, fileName: _fileName, path, fileSize } = await NTQQFileApi.uploadFile(filePath, ElementType.FILE);
if (fileSize === 0) { if (fileSize === 0) {
@@ -140,11 +140,11 @@ export class SendMsgElementConstructor {
} }
static async video(coreContext: NapCatCore, filePath: string, fileName: string = '', diyThumbPath: string = '', videotype: viedo_type = viedo_type.VIDEO_FORMAT_MP4): Promise<SendVideoElement> { static async video(coreContext: NapCatCore, filePath: string, fileName: string = '', diyThumbPath: string = '', videotype: viedo_type = viedo_type.VIDEO_FORMAT_MP4): Promise<SendVideoElement> {
const NTQQGroupApi = coreContext.getApiContext().GroupApi; const NTQQGroupApi = coreContext.apis.GroupApi;
const NTQQUserApi = coreContext.getApiContext().UserApi; const NTQQUserApi = coreContext.apis.UserApi;
const NTQQFileApi = coreContext.getApiContext().FileApi; const NTQQFileApi = coreContext.apis.FileApi;
const NTQQMsgApi = coreContext.getApiContext().MsgApi; const NTQQMsgApi = coreContext.apis.MsgApi;
const NTQQFriendApi = coreContext.getApiContext().FriendApi; const NTQQFriendApi = coreContext.apis.FriendApi;
const logger = coreContext.context.logger; const logger = coreContext.context.logger;
const { fileName: _fileName, path, fileSize, md5 } = await NTQQFileApi.uploadFile(filePath, ElementType.VIDEO); const { fileName: _fileName, path, fileSize, md5 } = await NTQQFileApi.uploadFile(filePath, ElementType.VIDEO);
if (fileSize === 0) { if (fileSize === 0) {
@@ -228,11 +228,11 @@ export class SendMsgElementConstructor {
} }
static async ptt(coreContext: NapCatCore, pttPath: string): Promise<SendPttElement> { static async ptt(coreContext: NapCatCore, pttPath: string): Promise<SendPttElement> {
const NTQQGroupApi = coreContext.getApiContext().GroupApi; const NTQQGroupApi = coreContext.apis.GroupApi;
const NTQQUserApi = coreContext.getApiContext().UserApi; const NTQQUserApi = coreContext.apis.UserApi;
const NTQQFileApi = coreContext.getApiContext().FileApi; const NTQQFileApi = coreContext.apis.FileApi;
const NTQQMsgApi = coreContext.getApiContext().MsgApi; const NTQQMsgApi = coreContext.apis.MsgApi;
const NTQQFriendApi = coreContext.getApiContext().FriendApi; const NTQQFriendApi = coreContext.apis.FriendApi;
const logger = coreContext.context.logger; const logger = coreContext.context.logger;
const { const {
converted, converted,

View File

@@ -20,7 +20,7 @@ async function handleMsg(coreContext: NapCatCore, msg: OB11Message, quickAction:
const reply = quickAction.reply; const reply = quickAction.reply;
const peer: Peer = { const peer: Peer = {
chatType: ChatType.friend, chatType: ChatType.friend,
peerUid: await coreContext.getApiContext().UserApi.getUidByUin(msg.user_id.toString()) as string, peerUid: await coreContext.apis.UserApi.getUidByUin(msg.user_id.toString()) as string,
}; };
if (msg.message_type == 'private') { if (msg.message_type == 'private') {
if (msg.sub_type === 'group') { if (msg.sub_type === 'group') {
@@ -35,7 +35,7 @@ async function handleMsg(coreContext: NapCatCore, msg: OB11Message, quickAction:
let replyMessage: OB11MessageData[] = []; let replyMessage: OB11MessageData[] = [];
if (msg.message_type == 'group') { if (msg.message_type == 'group') {
group = await coreContext.getApiContext().GroupApi.getGroup(msg.group_id!.toString()); group = await coreContext.apis.GroupApi.getGroup(msg.group_id!.toString());
replyMessage.push({ replyMessage.push({
type: 'reply', type: 'reply',
data: { data: {
@@ -59,7 +59,7 @@ async function handleMsg(coreContext: NapCatCore, msg: OB11Message, quickAction:
async function handleGroupRequest(coreContext: NapCatCore, request: OB11GroupRequestEvent, quickAction: QuickActionGroupRequest) { async function handleGroupRequest(coreContext: NapCatCore, request: OB11GroupRequestEvent, quickAction: QuickActionGroupRequest) {
if (!isNull(quickAction.approve)) { if (!isNull(quickAction.approve)) {
coreContext.getApiContext().GroupApi.handleGroupRequest( coreContext.apis.GroupApi.handleGroupRequest(
request.flag, request.flag,
quickAction.approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject, quickAction.approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
quickAction.reason, quickAction.reason,
@@ -69,7 +69,7 @@ async function handleGroupRequest(coreContext: NapCatCore, request: OB11GroupReq
async function handleFriendRequest(coreContext: NapCatCore, request: OB11FriendRequestEvent, quickAction: QuickActionFriendRequest) { async function handleFriendRequest(coreContext: NapCatCore, request: OB11FriendRequestEvent, quickAction: QuickActionFriendRequest) {
if (!isNull(quickAction.approve)) { if (!isNull(quickAction.approve)) {
coreContext.getApiContext().FriendApi.handleFriendRequest(request.flag, !!quickAction.approve).then().catch(coreContext.context.logger.logError); coreContext.apis.FriendApi.handleFriendRequest(request.flag, !!quickAction.approve).then().catch(coreContext.context.logger.logError);
} }
} }

View File

@@ -2,7 +2,8 @@ import {
BuddyListener, BuddyListener,
BuddyReqType, BuddyReqType,
ChatType, ChatType,
GroupListener, GroupNotifyTypes, GroupListener,
GroupNotifyTypes,
InstanceContext, InstanceContext,
MsgListener, MsgListener,
NapCatCore, NapCatCore,
@@ -12,7 +13,13 @@ import { OB11Config } from './helper/config';
import { NapCatPathWrapper } from '@/common/framework/napcat'; import { NapCatPathWrapper } from '@/common/framework/napcat';
import { OneBotApiContextType } from '@/onebot/types'; import { OneBotApiContextType } from '@/onebot/types';
import { OneBotFriendApi, OneBotGroupApi, OneBotUserApi } from './api'; import { OneBotFriendApi, OneBotGroupApi, OneBotUserApi } from './api';
import { OB11ActiveHttpAdapter, OB11ActiveWebSocketAdapter, OB11NetworkManager, OB11PassiveHttpAdapter, OB11PassiveWebSocketAdapter } from '@/onebot/network'; import {
OB11ActiveHttpAdapter,
OB11ActiveWebSocketAdapter,
OB11NetworkManager,
OB11PassiveHttpAdapter,
OB11PassiveWebSocketAdapter,
} from '@/onebot/network';
import { OB11InputStatusEvent } from '@/onebot/event/notice/OB11InputStatusEvent'; import { OB11InputStatusEvent } from '@/onebot/event/notice/OB11InputStatusEvent';
import { MessageUnique } from '@/common/utils/MessageUnique'; import { MessageUnique } from '@/common/utils/MessageUnique';
import { OB11Constructor } from '@/onebot/helper/data'; import { OB11Constructor } from '@/onebot/helper/data';
@@ -53,7 +60,7 @@ export class NapCatOneBot11Adapter {
} }
async InitOneBot() { async InitOneBot() {
const NTQQUserApi = this.core.getApiContext().UserApi; const NTQQUserApi = this.core.apis.UserApi;
const selfInfo = this.core.selfInfo; const selfInfo = this.core.selfInfo;
const ob11Config = this.config.configData; const ob11Config = this.config.configData;
@@ -117,7 +124,7 @@ export class NapCatOneBot11Adapter {
const msgListener = new MsgListener(); const msgListener = new MsgListener();
msgListener.onInputStatusPush = async data => { msgListener.onInputStatusPush = async data => {
const uin = await this.core.ApiContext.UserApi.getUinByUidV2(data.fromUin); const uin = await this.core.apis.UserApi.getUinByUidV2(data.fromUin);
this.context.logger.log(`[Notice] [输入状态] ${uin} ${data.statusText}`); this.context.logger.log(`[Notice] [输入状态] ${uin} ${data.statusText}`);
await this.networkManager.emitEvent(new OB11InputStatusEvent( await this.networkManager.emitEvent(new OB11InputStatusEvent(
this.core, this.core,
@@ -181,7 +188,7 @@ export class NapCatOneBot11Adapter {
return; return;
} }
try { try {
const requesterUin = await this.core.ApiContext.UserApi.getUinByUidV2(req.friendUid); const requesterUin = await this.core.apis.UserApi.getUinByUidV2(req.friendUid);
await this.networkManager.emitEvent(new OB11FriendRequestEvent( await this.networkManager.emitEvent(new OB11FriendRequestEvent(
this.core, this.core,
parseInt(requesterUin!), parseInt(requesterUin!),
@@ -230,7 +237,7 @@ export class NapCatOneBot11Adapter {
GroupNotifyTypes.ADMIN_UNSET, GroupNotifyTypes.ADMIN_UNSET,
GroupNotifyTypes.ADMIN_UNSET_OTHER GroupNotifyTypes.ADMIN_UNSET_OTHER
].includes(notify.type)) { ].includes(notify.type)) {
const member1 = await this.core.ApiContext.GroupApi.getGroupMember(notify.group.groupCode, notify.user1.uid); const member1 = await this.core.apis.GroupApi.getGroupMember(notify.group.groupCode, notify.user1.uid);
this.context.logger.logDebug('有管理员变动通知'); this.context.logger.logDebug('有管理员变动通知');
// refreshGroupMembers(notify.group.groupCode).then(); // refreshGroupMembers(notify.group.groupCode).then();
@@ -248,16 +255,16 @@ export class NapCatOneBot11Adapter {
this.networkManager.emitEvent(groupAdminNoticeEvent) this.networkManager.emitEvent(groupAdminNoticeEvent)
.catch(e => this.context.logger.logError('处理群管理员变动失败', e)); .catch(e => this.context.logger.logError('处理群管理员变动失败', e));
} else { } else {
this.context.logger.logDebug('获取群通知的成员信息失败', notify, this.core.ApiContext.GroupApi.getGroup(notify.group.groupCode)); this.context.logger.logDebug('获取群通知的成员信息失败', notify, this.core.apis.GroupApi.getGroup(notify.group.groupCode));
} }
} else if (notify.type == GroupNotifyTypes.MEMBER_EXIT || notify.type == GroupNotifyTypes.KICK_MEMBER) { } else if (notify.type == GroupNotifyTypes.MEMBER_EXIT || notify.type == GroupNotifyTypes.KICK_MEMBER) {
this.context.logger.logDebug('有成员退出通知', notify); this.context.logger.logDebug('有成员退出通知', notify);
const member1Uin = (await this.core.ApiContext.UserApi.getUinByUidV2(notify.user1.uid))!; const member1Uin = (await this.core.apis.UserApi.getUinByUidV2(notify.user1.uid))!;
let operatorId = member1Uin; let operatorId = member1Uin;
let subType: GroupDecreaseSubType = 'leave'; let subType: GroupDecreaseSubType = 'leave';
if (notify.user2.uid) { if (notify.user2.uid) {
// 是被踢的 // 是被踢的
const member2Uin = await this.core.ApiContext.UserApi.getUinByUidV2(notify.user2.uid); const member2Uin = await this.core.apis.UserApi.getUinByUidV2(notify.user2.uid);
if (member2Uin) { if (member2Uin) {
operatorId = member2Uin; operatorId = member2Uin;
} }
@@ -278,9 +285,9 @@ export class NapCatOneBot11Adapter {
].includes(notify.type) && notify.status == 1) { ].includes(notify.type) && notify.status == 1) {
this.context.logger.logDebug('有加群请求'); this.context.logger.logDebug('有加群请求');
try { try {
let requestUin = (await this.core.ApiContext.UserApi.getUinByUidV2(notify.user1.uid))!; let requestUin = (await this.core.apis.UserApi.getUinByUidV2(notify.user1.uid))!;
if (isNaN(parseInt(requestUin))) { if (isNaN(parseInt(requestUin))) {
requestUin = (await this.core.ApiContext.UserApi.getUserDetailInfo(notify.user1.uid)).uin; requestUin = (await this.core.apis.UserApi.getUserDetailInfo(notify.user1.uid)).uin;
} }
const groupRequestEvent = new OB11GroupRequestEvent( const groupRequestEvent = new OB11GroupRequestEvent(
this.core, this.core,
@@ -377,7 +384,7 @@ export class NapCatOneBot11Adapter {
let operatorId = message.senderUin; let operatorId = message.senderUin;
for (const element of message.elements) { for (const element of message.elements) {
const operatorUid = element.grayTipElement?.revokeElement.operatorUid; const operatorUid = element.grayTipElement?.revokeElement.operatorUid;
const operator = await this.core.ApiContext.GroupApi.getGroupMember(message.peerUin, operatorUid); const operator = await this.core.apis.GroupApi.getGroupMember(message.peerUin, operatorUid);
operatorId = operator?.uin || message.senderUin; operatorId = operator?.uin || message.senderUin;
} }
const groupRecallEvent = new OB11GroupRecallNoticeEvent( const groupRecallEvent = new OB11GroupRecallNoticeEvent(