chore: 所有扩展接口就绪

This commit is contained in:
手瓜一十雪 2024-08-09 17:01:29 +08:00
parent 4eed603d36
commit dfb31b78d9
9 changed files with 10 additions and 13 deletions

View File

@ -8,7 +8,7 @@ import { MsgListener, ProfileListener } from "./listeners";
import { sleep } from "@/common/utils/helper";
import { SelfInfo, LineDevice, SelfStatusInfo } from "./entities";
import { LegacyNTEventWrapper } from "@/common/framework/event-legacy";
import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, NTQQUserApi, NTQQWebApi } from "./apis";
import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, NTQQSystemApi, NTQQUserApi, NTQQWebApi } from "./apis";
import os from "node:os";
import { NTQQCollectionApi } from "./apis/collection";
export enum NapCatCoreWorkingEnv {
@ -43,6 +43,7 @@ export class NapCatCore {
this.eventWrapper = new LegacyNTEventWrapper(context.wrapper, context.session);
this.initNapCatCoreListeners().then().catch(console.error);
this.ApiContext = {
SystemApi:new NTQQSystemApi(this.context, this),
CollectionApi:new NTQQCollectionApi(this.context, this),
WebApi: new NTQQWebApi(this.context, this),
FriendApi: new NTQQFriendApi(this.context, this),

View File

@ -4,7 +4,7 @@ import { NapCatCoreWorkingEnv } from "@/core";
import { SelfInfo } from "../entities";
import { NodeIKernelLoginService } from "../services";
import { WrapperNodeApi, NodeIQQNTWrapperSession } from "@/core";
import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, NTQQUserApi, NTQQWebApi } from "../apis";
import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, NTQQSystemApi, NTQQUserApi, NTQQWebApi } from "../apis";
import { NTQQCollectionApi } from "../apis/collection";
export interface InstanceContext {
@ -16,6 +16,7 @@ export interface InstanceContext {
readonly basicInfoWrapper: QQBasicInfoWrapper;
}
export interface NTApiContext {
SystemApi: NTQQSystemApi,
CollectionApi: NTQQCollectionApi,
WebApi: NTQQWebApi,
FriendApi: NTQQFriendApi,

View File

@ -2,7 +2,6 @@
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { NTQQMsgApi } from '@/core/apis';
import { MessageUnique } from '@/common/utils/MessageUnique';
const SchemaData = {
type: 'object',

View File

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

View File

@ -26,13 +26,13 @@ export default class SetGroupHeader extends BaseAction<Payload, any> {
}
protected async _handle(payload: Payload): Promise<any> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
const { path, isLocal, errMsg,success } = (await uri2local(payload.file));
const { path, isLocal, errMsg, success } = (await uri2local(this.CoreContext.NapCatTempPath, payload.file));
if (!success) {
throw `头像${payload.file}设置失败,file字段可能格式不正确`;
}
if (path) {
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃需要提前判断
const ret = await NTQQGroupApi.setGroupAvatar(payload.groupCode,path);
const ret = await NTQQGroupApi.setGroupAvatar(payload.groupCode, path);
if (!isLocal) {
fs.unlink(path, () => { });
}

View File

@ -1,10 +1,7 @@
import BaseAction from '../BaseAction';
import { ActionName, BaseCheckResult } from '../types';
import * as fs from 'node:fs';
import { NTQQUserApi } from '@/core/apis/user';
import { checkFileReceived, uri2local } from '@/common/utils/file';
// import { log } from "../../../common/utils";
interface Payload {
file: string
}
@ -25,7 +22,7 @@ export default class SetAvatar extends BaseAction<Payload, null> {
}
protected async _handle(payload: Payload): Promise<null> {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const { path, isLocal, errMsg,success } = (await uri2local(payload.file));
const { path, isLocal, errMsg, success } = (await uri2local(this.CoreContext.NapCatTempPath, payload.file));
if (!success) {
throw `头像${payload.file}设置失败,file字段可能格式不正确`;
}

View File

@ -1,7 +1,6 @@
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { NTQQUserApi } from '@/core/apis';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
const SchemaData = {

View File

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

View File

@ -40,7 +40,6 @@ export class shareGroupEx extends BaseAction<PayloadGroupEx, any> {
actionName = ActionName.ShareGroupEx;
PayloadSchema = SchemaDataGroupEx;
protected async _handle(payload: PayloadGroupEx) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
return await NTQQGroupApi.getArkJsonGroupShare(payload.group_id);
}