mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-01-16 05:10:34 +00:00
feat: check action data 3
This commit is contained in:
parent
62eee5f05c
commit
d6175acd38
@ -6,17 +6,23 @@ import { ChatType, SendFileElement } from '@/core/entities';
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { NTQQMsgApi } from '@/core/apis/msg';
|
import { NTQQMsgApi } from '@/core/apis/msg';
|
||||||
import { uri2local } from '@/common/utils/file';
|
import { uri2local } from '@/common/utils/file';
|
||||||
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
|
const SchemaData = {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
group_id: { type: 'number' },
|
||||||
|
file: { type: 'string' },
|
||||||
|
name: { type: 'string' },
|
||||||
|
folder: { type: 'string' }
|
||||||
|
},
|
||||||
|
required: ['group_id', 'file', 'name', 'folder']
|
||||||
|
} as const satisfies JSONSchema;
|
||||||
|
|
||||||
interface Payload {
|
type Payload = FromSchema<typeof SchemaData>;
|
||||||
group_id: number;
|
|
||||||
file: string;
|
|
||||||
name: string;
|
|
||||||
folder: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class GoCQHTTPUploadGroupFile extends BaseAction<Payload, null> {
|
export default class GoCQHTTPUploadGroupFile extends BaseAction<Payload, null> {
|
||||||
actionName = ActionName.GoCQHTTP_UploadGroupFile;
|
actionName = ActionName.GoCQHTTP_UploadGroupFile;
|
||||||
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
const group = await getGroup(payload.group_id.toString());
|
const group = await getGroup(payload.group_id.toString());
|
||||||
if (!group) {
|
if (!group) {
|
||||||
|
|||||||
@ -5,16 +5,23 @@ import BaseAction from '../BaseAction';
|
|||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { NTQQMsgApi } from '@/core/apis/msg';
|
import { NTQQMsgApi } from '@/core/apis/msg';
|
||||||
import { GroupEssenceMsgRet, WebApi } from '@/core/apis/webapi';
|
import { GroupEssenceMsgRet, WebApi } from '@/core/apis/webapi';
|
||||||
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
|
|
||||||
interface PayloadType {
|
const SchemaData = {
|
||||||
group_id: number;
|
type: 'object',
|
||||||
pages: number;
|
properties: {
|
||||||
}
|
group_id: { type: 'number' },
|
||||||
|
pages: { type: 'number' },
|
||||||
|
},
|
||||||
|
required: ['group_id', 'pages']
|
||||||
|
} as const satisfies JSONSchema;
|
||||||
|
|
||||||
export class GetGroupEssence extends BaseAction<PayloadType, GroupEssenceMsgRet> {
|
type Payload = FromSchema<typeof SchemaData>;
|
||||||
|
|
||||||
|
export class GetGroupEssence extends BaseAction<Payload, GroupEssenceMsgRet> {
|
||||||
actionName = ActionName.GoCQHTTP_GetEssenceMsg;
|
actionName = ActionName.GoCQHTTP_GetEssenceMsg;
|
||||||
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: PayloadType) {
|
protected async _handle(payload: Payload) {
|
||||||
const ret = await WebApi.getGroupEssenceMsg(payload.group_id.toString(), payload.pages.toString());
|
const ret = await WebApi.getGroupEssenceMsg(payload.group_id.toString(), payload.pages.toString());
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
throw new Error('获取失败');
|
throw new Error('获取失败');
|
||||||
|
|||||||
@ -3,15 +3,22 @@ import { OB11Group } from '../../types';
|
|||||||
import { OB11Constructor } from '../../constructor';
|
import { OB11Constructor } from '../../constructor';
|
||||||
import BaseAction from '../BaseAction';
|
import BaseAction from '../BaseAction';
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
|
|
||||||
interface PayloadType {
|
const SchemaData = {
|
||||||
group_id: number
|
type: 'object',
|
||||||
}
|
properties: {
|
||||||
|
group_id: { type: 'number' },
|
||||||
|
},
|
||||||
|
required: ['group_id']
|
||||||
|
} as const satisfies JSONSchema;
|
||||||
|
|
||||||
class GetGroupInfo extends BaseAction<PayloadType, OB11Group> {
|
type Payload = FromSchema<typeof SchemaData>;
|
||||||
|
|
||||||
|
class GetGroupInfo extends BaseAction<Payload, OB11Group> {
|
||||||
actionName = ActionName.GetGroupInfo;
|
actionName = ActionName.GetGroupInfo;
|
||||||
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: PayloadType) {
|
protected async _handle(payload: Payload) {
|
||||||
const group = await getGroup(payload.group_id.toString());
|
const group = await getGroup(payload.group_id.toString());
|
||||||
if (group) {
|
if (group) {
|
||||||
return OB11Constructor.group(group);
|
return OB11Constructor.group(group);
|
||||||
|
|||||||
@ -6,17 +6,23 @@ import { groups } from '@/core/data';
|
|||||||
import { NTQQGroupApi } from '@/core/apis';
|
import { NTQQGroupApi } from '@/core/apis';
|
||||||
import { Group } from '@/core/entities';
|
import { Group } from '@/core/entities';
|
||||||
import { log } from '@/common/utils/log';
|
import { log } from '@/common/utils/log';
|
||||||
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
|
// no_cache get时传字符串
|
||||||
|
const SchemaData = {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
no_cache: { type: 'boolean' },
|
||||||
|
}
|
||||||
|
} as const satisfies JSONSchema;
|
||||||
|
|
||||||
interface Payload {
|
type Payload = FromSchema<typeof SchemaData>;
|
||||||
no_cache: boolean | string;
|
|
||||||
}
|
|
||||||
|
|
||||||
class GetGroupList extends BaseAction<Payload, OB11Group[]> {
|
class GetGroupList extends BaseAction<Payload, OB11Group[]> {
|
||||||
actionName = ActionName.GetGroupList;
|
actionName = ActionName.GetGroupList;
|
||||||
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
let groupList: Group[] = Array.from(groups.values());
|
let groupList: Group[] = Array.from(groups.values());
|
||||||
if (groupList.length === 0 || payload?.no_cache === true || payload?.no_cache === 'true') {
|
if (groupList.length === 0 || payload?.no_cache === true /*|| payload.no_cache === 'true'*/) {
|
||||||
groupList = await NTQQGroupApi.getGroups(true);
|
groupList = await NTQQGroupApi.getGroups(true);
|
||||||
// log('get groups', groups);
|
// log('get groups', groups);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,24 +8,31 @@ import { log, logDebug } from '@/common/utils/log';
|
|||||||
import { isNull } from '../../../common/utils/helper';
|
import { isNull } from '../../../common/utils/helper';
|
||||||
import { WebApi } from '@/core/apis/webapi';
|
import { WebApi } from '@/core/apis/webapi';
|
||||||
import { NTQQGroupApi } from '@/core';
|
import { NTQQGroupApi } from '@/core';
|
||||||
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
|
|
||||||
|
// no_cache get时传字符串
|
||||||
|
const SchemaData = {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
group_id: { type: 'number' },
|
||||||
|
user_id: { type: 'number' },
|
||||||
|
no_cache: { type: 'boolean' },
|
||||||
|
},
|
||||||
|
required: ['group_id', 'user_id']
|
||||||
|
} as const satisfies JSONSchema;
|
||||||
|
|
||||||
export interface PayloadType {
|
type Payload = FromSchema<typeof SchemaData>;
|
||||||
group_id: number;
|
|
||||||
user_id: number;
|
|
||||||
no_cache?: boolean | string;
|
|
||||||
}
|
|
||||||
|
|
||||||
class GetGroupMemberInfo extends BaseAction<PayloadType, OB11GroupMember> {
|
class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
|
||||||
actionName = ActionName.GetGroupMemberInfo;
|
actionName = ActionName.GetGroupMemberInfo;
|
||||||
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: PayloadType) {
|
protected async _handle(payload: Payload) {
|
||||||
const group = await getGroup(payload.group_id.toString());
|
const group = await getGroup(payload.group_id.toString());
|
||||||
if (!group) {
|
if (!group) {
|
||||||
throw (`群(${payload.group_id})不存在`);
|
throw (`群(${payload.group_id})不存在`);
|
||||||
}
|
}
|
||||||
const webGroupMembers = await WebApi.getGroupMembers(payload.group_id.toString());
|
const webGroupMembers = await WebApi.getGroupMembers(payload.group_id.toString());
|
||||||
if (payload.no_cache == true || payload.no_cache === 'true') {
|
if (payload.no_cache == true /*|| payload.no_cache === 'true'*/) {
|
||||||
groupMembers.set(group.groupCode, await NTQQGroupApi.getGroupMembers(payload.group_id.toString()));
|
groupMembers.set(group.groupCode, await NTQQGroupApi.getGroupMembers(payload.group_id.toString()));
|
||||||
}
|
}
|
||||||
const member = await getGroupMember(payload.group_id.toString(), payload.user_id.toString());
|
const member = await getGroupMember(payload.group_id.toString(), payload.user_id.toString());
|
||||||
|
|||||||
@ -6,24 +6,29 @@ import { ActionName } from '../types';
|
|||||||
import { napCatCore, NTQQGroupApi } from '@/core';
|
import { napCatCore, NTQQGroupApi } from '@/core';
|
||||||
import { WebApi } from '@/core/apis/webapi';
|
import { WebApi } from '@/core/apis/webapi';
|
||||||
import { logDebug } from '@/common/utils/log';
|
import { logDebug } from '@/common/utils/log';
|
||||||
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
|
const SchemaData = {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
group_id: { type: 'number' },
|
||||||
|
no_cache: { type: 'boolean' },
|
||||||
|
},
|
||||||
|
required: ['group_id', 'user_id']
|
||||||
|
} as const satisfies JSONSchema;
|
||||||
|
|
||||||
export interface PayloadType {
|
type Payload = FromSchema<typeof SchemaData>;
|
||||||
group_id: number,
|
|
||||||
no_cache?: boolean | string
|
|
||||||
}
|
|
||||||
|
|
||||||
|
class GetGroupMemberList extends BaseAction<Payload, OB11GroupMember[]> {
|
||||||
class GetGroupMemberList extends BaseAction<PayloadType, OB11GroupMember[]> {
|
|
||||||
actionName = ActionName.GetGroupMemberList;
|
actionName = ActionName.GetGroupMemberList;
|
||||||
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: PayloadType) {
|
protected async _handle(payload: Payload) {
|
||||||
const MemberMap: Map<number, OB11GroupMember> = new Map<number, OB11GroupMember>();
|
const MemberMap: Map<number, OB11GroupMember> = new Map<number, OB11GroupMember>();
|
||||||
const webGroupMembers = await WebApi.getGroupMembers(payload.group_id.toString());
|
const webGroupMembers = await WebApi.getGroupMembers(payload.group_id.toString());
|
||||||
const group = await getGroup(payload.group_id.toString());
|
const group = await getGroup(payload.group_id.toString());
|
||||||
if (!group) {
|
if (!group) {
|
||||||
throw (`群${payload.group_id}不存在`);
|
throw (`群${payload.group_id}不存在`);
|
||||||
}
|
}
|
||||||
if (payload.no_cache == true || payload.no_cache === 'true') {
|
if (payload.no_cache == true /*|| payload.no_cache === 'true'*/) {
|
||||||
// webGroupMembers = await WebApi.getGroupMembers(payload.group_id.toString());
|
// webGroupMembers = await WebApi.getGroupMembers(payload.group_id.toString());
|
||||||
const _groupMembers = await NTQQGroupApi.getGroupMembers(payload.group_id.toString());
|
const _groupMembers = await NTQQGroupApi.getGroupMembers(payload.group_id.toString());
|
||||||
groupMembers.set(group.groupCode, _groupMembers);
|
groupMembers.set(group.groupCode, _groupMembers);
|
||||||
|
|||||||
@ -1,10 +1,7 @@
|
|||||||
import { WebApi, WebApiGroupNoticeFeed, WebApiGroupNoticeRet } from '@/core/apis/webapi';
|
import { WebApi, WebApiGroupNoticeFeed, WebApiGroupNoticeRet } from '@/core/apis/webapi';
|
||||||
import BaseAction from '../BaseAction';
|
import BaseAction from '../BaseAction';
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
interface PayloadType {
|
|
||||||
group_id: number
|
|
||||||
}
|
|
||||||
interface GroupNotice {
|
interface GroupNotice {
|
||||||
sender_id: number
|
sender_id: number
|
||||||
publish_time: number
|
publish_time: number
|
||||||
@ -17,11 +14,22 @@ interface GroupNotice {
|
|||||||
}>
|
}>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
type ApiGroupNotice = GroupNotice & WebApiGroupNoticeFeed;
|
|
||||||
export class GetGroupNotice extends BaseAction<PayloadType, GroupNotice[]> {
|
|
||||||
actionName = ActionName.GoCQHTTP_GetGroupNotice;
|
|
||||||
|
|
||||||
protected async _handle(payload: PayloadType) {
|
const SchemaData = {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
group_id: { type: 'number' },
|
||||||
|
},
|
||||||
|
required: ['group_id']
|
||||||
|
} as const satisfies JSONSchema;
|
||||||
|
|
||||||
|
type Payload = FromSchema<typeof SchemaData>;
|
||||||
|
|
||||||
|
type ApiGroupNotice = GroupNotice & WebApiGroupNoticeFeed;
|
||||||
|
export class GetGroupNotice extends BaseAction<Payload, GroupNotice[]> {
|
||||||
|
actionName = ActionName.GoCQHTTP_GetGroupNotice;
|
||||||
|
PayloadSchema = SchemaData;
|
||||||
|
protected async _handle(payload: Payload) {
|
||||||
const group = payload.group_id.toString();
|
const group = payload.group_id.toString();
|
||||||
const ret = await WebApi.getGrouptNotice(group);
|
const ret = await WebApi.getGrouptNotice(group);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import SendMsg from '../msg/SendMsg';
|
|||||||
import { ActionName, BaseCheckResult } from '../types';
|
import { ActionName, BaseCheckResult } from '../types';
|
||||||
import { OB11PostSendMsg } from '../../types';
|
import { OB11PostSendMsg } from '../../types';
|
||||||
|
|
||||||
|
// 未检测参数
|
||||||
class SendGroupMsg extends SendMsg {
|
class SendGroupMsg extends SendMsg {
|
||||||
actionName = ActionName.SendGroupMsg;
|
actionName = ActionName.SendGroupMsg;
|
||||||
|
|
||||||
|
|||||||
@ -3,18 +3,23 @@ import { GroupRequestOperateTypes } from '@/core/entities';
|
|||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { NTQQGroupApi } from '@/core/apis/group';
|
import { NTQQGroupApi } from '@/core/apis/group';
|
||||||
import { groupNotifies } from '@/core/data';
|
import { groupNotifies } from '@/core/data';
|
||||||
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
|
|
||||||
interface Payload {
|
const SchemaData = {
|
||||||
flag: string,
|
type: 'object',
|
||||||
// sub_type: "add" | "invite",
|
properties: {
|
||||||
// type: "add" | "invite"
|
flag: { type: 'string' },
|
||||||
approve: boolean,
|
approve: { type: 'boolean' },
|
||||||
reason: string
|
reason: { type: 'string' }
|
||||||
}
|
},
|
||||||
|
required: ['flag', 'approve', 'reson']
|
||||||
|
} as const satisfies JSONSchema;
|
||||||
|
|
||||||
|
type Payload = FromSchema<typeof SchemaData>;
|
||||||
|
|
||||||
export default class SetGroupAddRequest extends BaseAction<Payload, null> {
|
export default class SetGroupAddRequest extends BaseAction<Payload, null> {
|
||||||
actionName = ActionName.SetGroupAddRequest;
|
actionName = ActionName.SetGroupAddRequest;
|
||||||
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
const flag = payload.flag.toString();
|
const flag = payload.flag.toString();
|
||||||
const approve = payload.approve.toString() === 'true';
|
const approve = payload.approve.toString() === 'true';
|
||||||
|
|||||||
@ -3,18 +3,26 @@ import { getGroupMember } from '@/core/data';
|
|||||||
import { GroupMemberRole } from '@/core/entities';
|
import { GroupMemberRole } from '@/core/entities';
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { NTQQGroupApi } from '@/core/apis/group';
|
import { NTQQGroupApi } from '@/core/apis/group';
|
||||||
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
|
|
||||||
interface Payload {
|
const SchemaData = {
|
||||||
group_id: number,
|
type: 'object',
|
||||||
user_id: number,
|
properties: {
|
||||||
enable: boolean
|
group_id: { type: 'number' },
|
||||||
}
|
user_id: { type: 'number' },
|
||||||
|
enable: { type: 'boolean' }
|
||||||
|
},
|
||||||
|
required: ['group_id', 'user_id', 'enable']
|
||||||
|
} as const satisfies JSONSchema;
|
||||||
|
|
||||||
|
type Payload = FromSchema<typeof SchemaData>;
|
||||||
|
|
||||||
export default class SetGroupAdmin extends BaseAction<Payload, null> {
|
export default class SetGroupAdmin extends BaseAction<Payload, null> {
|
||||||
actionName = ActionName.SetGroupAdmin;
|
actionName = ActionName.SetGroupAdmin;
|
||||||
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
const member = await getGroupMember(payload.group_id, payload.user_id);
|
const member = await getGroupMember(payload.group_id, payload.user_id);
|
||||||
|
// 已经前置验证类型
|
||||||
const enable = payload.enable.toString() === 'true';
|
const enable = payload.enable.toString() === 'true';
|
||||||
if (!member) {
|
if (!member) {
|
||||||
throw `群成员${payload.user_id}不存在`;
|
throw `群成员${payload.user_id}不存在`;
|
||||||
|
|||||||
@ -2,16 +2,23 @@ import BaseAction from '../BaseAction';
|
|||||||
import { getGroupMember } from '@/core/data';
|
import { getGroupMember } from '@/core/data';
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { NTQQGroupApi } from '@/core/apis/group';
|
import { NTQQGroupApi } from '@/core/apis/group';
|
||||||
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
|
|
||||||
interface Payload {
|
const SchemaData = {
|
||||||
group_id: number,
|
type: 'object',
|
||||||
user_id: number,
|
properties: {
|
||||||
duration: number
|
group_id: { type: 'number' },
|
||||||
}
|
user_id: { type: 'number' },
|
||||||
|
duration: { type: 'number' }
|
||||||
|
},
|
||||||
|
required: ['group_id', 'user_id', 'duration']
|
||||||
|
} as const satisfies JSONSchema;
|
||||||
|
|
||||||
|
type Payload = FromSchema<typeof SchemaData>;
|
||||||
|
|
||||||
export default class SetGroupBan extends BaseAction<Payload, null> {
|
export default class SetGroupBan extends BaseAction<Payload, null> {
|
||||||
actionName = ActionName.SetGroupBan;
|
actionName = ActionName.SetGroupBan;
|
||||||
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
const member = await getGroupMember(payload.group_id, payload.user_id);
|
const member = await getGroupMember(payload.group_id, payload.user_id);
|
||||||
if (!member) {
|
if (!member) {
|
||||||
|
|||||||
@ -2,16 +2,23 @@ import BaseAction from '../BaseAction';
|
|||||||
import { getGroupMember } from '@/core/data';
|
import { getGroupMember } from '@/core/data';
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { NTQQGroupApi } from '@/core/apis/group';
|
import { NTQQGroupApi } from '@/core/apis/group';
|
||||||
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
|
|
||||||
interface Payload {
|
const SchemaData = {
|
||||||
group_id: number,
|
type: 'object',
|
||||||
user_id: number,
|
properties: {
|
||||||
card: string
|
group_id: { type: 'number' },
|
||||||
}
|
user_id: { type: 'number' },
|
||||||
|
card: { type: 'string' }
|
||||||
|
},
|
||||||
|
required: ['group_id', 'user_id', 'card']
|
||||||
|
} as const satisfies JSONSchema;
|
||||||
|
|
||||||
|
type Payload = FromSchema<typeof SchemaData>;
|
||||||
|
|
||||||
export default class SetGroupCard extends BaseAction<Payload, null> {
|
export default class SetGroupCard extends BaseAction<Payload, null> {
|
||||||
actionName = ActionName.SetGroupCard;
|
actionName = ActionName.SetGroupCard;
|
||||||
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
const member = await getGroupMember(payload.group_id, payload.user_id);
|
const member = await getGroupMember(payload.group_id, payload.user_id);
|
||||||
if (!member) {
|
if (!member) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user