mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-06 13:05:09 +00:00
chore: obApi
This commit is contained in:
@@ -1,17 +1,15 @@
|
||||
import { requireMinNTQQBuild } from '@/common/utils/QQBasicInfo';
|
||||
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { BuddyCategoryType } from '@/core/entities/';
|
||||
import { NTQQFriendApi } from '@/core';
|
||||
import { OB11Constructor } from '@/onebot11/constructor';
|
||||
import { OB11Constructor } from '@/onebot/helper/constructor';
|
||||
|
||||
export class GetFriendWithCategory extends BaseAction<void, any> {
|
||||
actionName = ActionName.GetFriendsWithCategory;
|
||||
|
||||
protected async _handle(payload: void) {
|
||||
if (requireMinNTQQBuild('26702')) {
|
||||
if (this.CoreContext.context.basicInfoWrapper.requireMinNTQQBuild('26702')) {
|
||||
//全新逻辑
|
||||
return OB11Constructor.friendsV2(await NTQQFriendApi.getBuddyV2ExWithCate(true));
|
||||
return OB11Constructor.friendsV2(await this.CoreContext.getApiContext().FriendApi.getBuddyV2ExWithCate(true));
|
||||
} else {
|
||||
throw new Error('this ntqq version not support, must be 26702 or later');
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { GroupNotify, GroupNotifyStatus } from '@/core/entities';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQUserApi } from '@/core/apis/user';
|
||||
import { NTQQGroupApi } from '@/core/apis/group';
|
||||
|
||||
interface OB11GroupRequestNotify {
|
||||
@@ -14,7 +12,7 @@ export default class GetGroupAddRequest extends BaseAction<null, OB11GroupReques
|
||||
actionName = ActionName.GetGroupIgnoreAddRequest;
|
||||
|
||||
protected async _handle(payload: null): Promise<OB11GroupRequestNotify[] | null> {
|
||||
const data = await NTQQGroupApi.getGroupIgnoreNotifies();
|
||||
const data = await this.CoreContext.getApiContext().GroupApi.getGroupIgnoreNotifies();
|
||||
// log(data);
|
||||
// const notifies: GroupNotify[] = data.notifies.filter(notify => notify.status === GroupNotifyStatus.WAIT_HANDLE);
|
||||
// const returnData: OB11GroupRequestNotify[] = [];
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { selfInfo } from '@/core/data';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQUserApi } from '@/core/apis';
|
||||
|
||||
export class GetProfileLike extends BaseAction<void, any> {
|
||||
actionName = ActionName.GetProfileLike;
|
||||
protected async _handle(payload: void) {
|
||||
const ret = await NTQQUserApi.getProfileLike(selfInfo.uid);
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const ret = await NTQQUserApi.getProfileLike(this.CoreContext.selfInfo.uid);
|
||||
const listdata: any[] = ret.info.userLikeInfos[0].favoriteInfo.userInfos;
|
||||
for (let i = 0; i < listdata.length; i++) {
|
||||
listdata[i].uin = parseInt((await NTQQUserApi.getUinByUid(listdata[i].uid)) || '');
|
||||
|
||||
@@ -6,6 +6,7 @@ export class GetRobotUinRange extends BaseAction<void, Array<any>> {
|
||||
|
||||
protected async _handle(payload: void) {
|
||||
// console.log(await NTQQUserApi.getRobotUinRange());
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
return await NTQQUserApi.getRobotUinRange();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ 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 { NTQQGroupApi } from '@/core';
|
||||
// import { log } from "../../../common/utils";
|
||||
|
||||
interface Payload {
|
||||
@@ -26,6 +25,7 @@ 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));
|
||||
if (!success) {
|
||||
throw `头像${payload.file}设置失败,file字段可能格式不正确`;
|
||||
|
||||
@@ -18,6 +18,7 @@ export class SetLongNick extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.SetLongNick;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const ret = await NTQQUserApi.setLongNick(payload.longNick);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ export class SetOnlineStatus extends BaseAction<Payload, null> {
|
||||
// { status: 50, extStatus: 0, batteryStatus: 0 }
|
||||
// { status: 60, extStatus: 0, batteryStatus: 0 }
|
||||
// { status: 70, extStatus: 0, batteryStatus: 0 }
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const ret = await NTQQUserApi.setSelfOnlineStatus(payload.status, payload.extStatus, payload.batteryStatus);
|
||||
if (ret.result !== 0) {
|
||||
throw new Error('设置在线状态失败');
|
||||
|
||||
@@ -24,6 +24,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));
|
||||
if (!success) {
|
||||
throw `头像${payload.file}设置失败,file字段可能格式不正确`;
|
||||
|
||||
@@ -20,6 +20,7 @@ export class SetSelfProfile extends BaseAction<Payload, any | null> {
|
||||
actionName = ActionName.SetSelfProfile;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const ret = await NTQQUserApi.modifySelfProfile({
|
||||
nick: payload.nick,
|
||||
longNick: payload.longNick,
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName, BaseCheckResult } from '../types';
|
||||
import { napCatCore, NTQQGroupApi } from '@/core';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
cmd: { type: 'string' },
|
||||
param: { type: 'string' }
|
||||
},
|
||||
required: ['cmd', 'param'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export default class TestApi01 extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.TestApi01;
|
||||
// 用不着复杂检测
|
||||
protected async check(payload: Payload): Promise<BaseCheckResult> {
|
||||
return {
|
||||
valid: true,
|
||||
};
|
||||
}
|
||||
protected async _handle(payload: Payload): Promise<any> {
|
||||
return await napCatCore.session.getMsgService().sendSsoCmdReqByContend(payload.cmd, payload.param);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName, BaseCheckResult } from '../types';
|
||||
import { NTQQSystemApi, NTQQUserApi } from '@/core/apis';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQSystemApi } from '@/core/apis';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import Ajv from 'ajv';
|
||||
// 设置在线状态
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { NTQQGroupApi, NTQQUserApi } from '@/core';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { BuddyCategoryType } from '@/core/entities/';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
@@ -20,6 +18,8 @@ export class sharePeer extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.SharePeer;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
if (payload.group_id) {
|
||||
return await NTQQGroupApi.getGroupRecommendContactArkJson(payload.group_id);
|
||||
} else if (payload.user_id) {
|
||||
@@ -40,6 +40,8 @@ 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);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQGroupApi, NTQQMsgApi, NTQQUserApi } from '@/core/apis';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
@@ -18,6 +16,7 @@ export class DelGroupFile extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.DelGroupFile;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
return await NTQQGroupApi.DelGroupFile(payload.group_id.toString(), [payload.file_id]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { OB11ForwardMessage, OB11Message, OB11MessageData } from '../../types';
|
||||
import { NTQQMsgApi } from '@/core/apis';
|
||||
import { OB11Constructor } from '../../constructor';
|
||||
import { OB11Constructor } from '../../helper/constructor';
|
||||
import { ActionName, BaseCheckResult } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
@@ -24,6 +24,7 @@ export class GoCQHTTPGetForwardMsgAction extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.GoCQHTTP_GetForwardMsg;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<any> {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
const msgId = payload.message_id || payload.id;
|
||||
if (!msgId) {
|
||||
throw Error('message_id is required');
|
||||
|
||||
@@ -3,9 +3,8 @@ import { OB11Message, OB11User } from '../../types';
|
||||
import { ActionName } from '../types';
|
||||
import { ChatType, RawMessage } from '@/core/entities';
|
||||
import { NTQQMsgApi } from '@/core/apis/msg';
|
||||
import { OB11Constructor } from '../../constructor';
|
||||
import { OB11Constructor } from '../../helper/constructor';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { NTQQFriendApi, NTQQUserApi } from '@/core';
|
||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
|
||||
interface Response {
|
||||
@@ -29,6 +28,9 @@ export default class GetFriendMsgHistory extends BaseAction<Payload, Response> {
|
||||
actionName = ActionName.GetFriendMsgHistory;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<Response> {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
|
||||
//处理参数
|
||||
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
const MsgCount = payload.count || 20;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { WebApi, WebHonorType } from '@/core/apis';
|
||||
import { WebHonorType } from '@/core/entities';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
@@ -21,6 +21,7 @@ export class GetGroupHonorInfo extends BaseAction<Payload, Array<any>> {
|
||||
if (!payload.type) {
|
||||
payload.type = WebHonorType.ALL;
|
||||
}
|
||||
return await WebApi.getGroupHonorInfo(payload.group_id.toString(), payload.type);
|
||||
const NTQQWebApi = this.CoreContext.getApiContext().WebApi;
|
||||
return await NTQQWebApi.getGroupHonorInfo(payload.group_id.toString(), payload.type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { OB11Message, OB11User } from '../../types';
|
||||
import { getGroup, groups } from '@/core/data';
|
||||
import { ActionName } from '../types';
|
||||
import { ChatType, Peer, RawMessage } from '@/core/entities';
|
||||
import { NTQQMsgApi } from '@/core/apis/msg';
|
||||
import { OB11Constructor } from '../../constructor';
|
||||
import { OB11Constructor } from '../../helper/constructor';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
interface Response {
|
||||
@@ -28,13 +27,11 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Resp
|
||||
actionName = ActionName.GoCQHTTP_GetGroupMsgHistory;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<Response> {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
//处理参数
|
||||
const group = await getGroup(payload.group_id.toString());
|
||||
const isReverseOrder = payload.reverseOrder || true;
|
||||
const MsgCount = payload.count || 20;
|
||||
const peer: Peer = { chatType: ChatType.group, peerUid: payload.group_id.toString() };
|
||||
if (!group) throw `群${payload.group_id}不存在`;
|
||||
|
||||
//拉取消息
|
||||
let msgList: RawMessage[];
|
||||
if (!payload.message_seq || payload.message_seq == 0) {
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { OB11User, OB11UserSex } from '../../types';
|
||||
import { OB11Constructor } from '../../constructor';
|
||||
import { OB11Constructor } from '../../helper/constructor';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQUserApi } from '@/core/apis/user';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { calcQQLevel } from '@/common/utils/qqlevel';
|
||||
import { requireMinNTQQBuild } from '@/common/utils/QQBasicInfo';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
@@ -21,7 +19,7 @@ export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11Use
|
||||
actionName = ActionName.GoCQHTTP_GetStrangerInfo;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<OB11User> {
|
||||
if (!requireMinNTQQBuild('26702')) {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const user_id = payload.user_id.toString();
|
||||
const extendData = await NTQQUserApi.getUserDetailInfoByUin(user_id);
|
||||
const uid = (await NTQQUserApi.getUidByUin(user_id))!;
|
||||
@@ -41,26 +39,5 @@ export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11Use
|
||||
}
|
||||
const data = { ...extendData, ...(await NTQQUserApi.getUserDetailInfo(uid)) };
|
||||
return OB11Constructor.stranger(data);
|
||||
} else {
|
||||
const user_id = payload.user_id.toString();
|
||||
const extendData = await NTQQUserApi.getUserDetailInfoByUinV2(user_id);
|
||||
//console.log(extendData);
|
||||
const uid = (await NTQQUserApi.getUidByUin(user_id))!;
|
||||
if (!uid || uid.indexOf('*') != -1) {
|
||||
const ret = {
|
||||
...extendData,
|
||||
user_id: parseInt(extendData.detail.uin) || 0,
|
||||
nickname: extendData.detail.simpleInfo.coreInfo.nick,
|
||||
sex: OB11UserSex.unknown,
|
||||
age: 0,
|
||||
level: extendData.detail.commonExt.qqLevel && calcQQLevel(extendData.detail.commonExt.qqLevel) || 0,
|
||||
login_days: 0,
|
||||
uid: ''
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
const data = { ...extendData, ...(await NTQQUserApi.getUserDetailInfo(uid)) };
|
||||
return OB11Constructor.stranger(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { log } from '@/common/utils/log';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { QuickAction, QuickActionEvent, handleQuickOperation } from '@/onebot11/server/postOB11Event';
|
||||
|
||||
Reference in New Issue
Block a user