From 44974034ecddb535a68efe926c9b58843ac48b63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Sat, 18 May 2024 12:56:03 +0800 Subject: [PATCH] build: 1.3.5-beta32 --- src/onebot11/action/group/SetGroupKick.ts | 20 +++++++++----- src/onebot11/action/group/SetGroupLeave.ts | 17 +++++++----- src/onebot11/action/group/SetGroupName.ts | 16 +++++++---- src/onebot11/action/group/SetGroupWholeBan.ts | 17 ++++++++---- src/onebot11/action/msg/DeleteMsg.ts | 16 +++++++---- src/onebot11/action/msg/ForwardSingleMsg.ts | 27 ++++++++++++------- src/onebot11/action/msg/GetMsg.ts | 21 ++++++++++----- src/onebot11/action/msg/MarkMsgAsRead.ts | 21 ++++++++++----- src/onebot11/action/msg/SendPrivateMsg.ts | 2 +- src/onebot11/action/msg/SetMsgEmojiLike.ts | 17 ++++++++---- src/onebot11/action/system/Reboot.ts | 13 ++++++--- src/onebot11/action/user/GetCookies.ts | 16 ++++++++--- src/onebot11/action/user/GetFriendList.ts | 16 +++++++---- src/onebot11/action/user/SendLike.ts | 17 ++++++++---- .../action/user/SetFriendAddRequest.ts | 19 ++++++++----- 15 files changed, 176 insertions(+), 79 deletions(-) diff --git a/src/onebot11/action/group/SetGroupKick.ts b/src/onebot11/action/group/SetGroupKick.ts index 87eac375..d32cb5c9 100644 --- a/src/onebot11/action/group/SetGroupKick.ts +++ b/src/onebot11/action/group/SetGroupKick.ts @@ -2,16 +2,24 @@ import BaseAction from '../BaseAction'; import { getGroupMember } from '@/core/data'; import { ActionName } from '../types'; import { NTQQGroupApi } from '@/core/apis/group'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; -interface Payload { - group_id: number, - user_id: number, - reject_add_request: boolean -} + +const SchemaData = { + type: 'object', + properties: { + group_id: { type: 'number' }, + user_id: { type: 'number' }, + reject_add_request: { type: 'boolean' } + }, + required: ['group_id', 'user_id', 'reject_add_request'] +} as const satisfies JSONSchema; + +type Payload = FromSchema; export default class SetGroupKick extends BaseAction { actionName = ActionName.SetGroupKick; - + PayloadSchema = SchemaData; protected async _handle(payload: Payload): Promise { const member = await getGroupMember(payload.group_id, payload.user_id); if (!member) { diff --git a/src/onebot11/action/group/SetGroupLeave.ts b/src/onebot11/action/group/SetGroupLeave.ts index e5378bb4..9505f901 100644 --- a/src/onebot11/action/group/SetGroupLeave.ts +++ b/src/onebot11/action/group/SetGroupLeave.ts @@ -2,15 +2,20 @@ import BaseAction from '../BaseAction'; import { ActionName } from '../types'; import { NTQQGroupApi } from '@/core/apis/group'; import { log, logError } from '@/common/utils/log'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; +const SchemaData = { + type: 'object', + properties: { + group_id: { type: 'number' }, + is_dismiss: { type: 'boolean' } + }, + required: ['group_id', 'is_dismiss'] +} as const satisfies JSONSchema; -interface Payload { - group_id: number, - is_dismiss: boolean -} - +type Payload = FromSchema; export default class SetGroupLeave extends BaseAction { actionName = ActionName.SetGroupLeave; - + PayloadSchema = SchemaData; protected async _handle(payload: Payload): Promise { try { await NTQQGroupApi.quitGroup(payload.group_id.toString()); diff --git a/src/onebot11/action/group/SetGroupName.ts b/src/onebot11/action/group/SetGroupName.ts index 77630edf..bc211161 100644 --- a/src/onebot11/action/group/SetGroupName.ts +++ b/src/onebot11/action/group/SetGroupName.ts @@ -1,15 +1,21 @@ +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; import BaseAction from '../BaseAction'; import { ActionName } from '../types'; import { NTQQGroupApi } from '@/core/apis/group'; -interface Payload { - group_id: number, - group_name: string -} +const SchemaData = { + type: 'object', + properties: { + group_id: { type: 'number' }, + group_name: { type: 'string' } + }, + required: ['group_id', 'group_name'] +} as const satisfies JSONSchema; +type Payload = FromSchema; export default class SetGroupName extends BaseAction { actionName = ActionName.SetGroupName; - + PayloadSchema = SchemaData; protected async _handle(payload: Payload): Promise { await NTQQGroupApi.setGroupName(payload.group_id.toString(), payload.group_name); diff --git a/src/onebot11/action/group/SetGroupWholeBan.ts b/src/onebot11/action/group/SetGroupWholeBan.ts index 25ea1ae2..ecab51b7 100644 --- a/src/onebot11/action/group/SetGroupWholeBan.ts +++ b/src/onebot11/action/group/SetGroupWholeBan.ts @@ -1,15 +1,22 @@ +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; import BaseAction from '../BaseAction'; import { ActionName } from '../types'; import { NTQQGroupApi } from '@/core/apis/group'; -interface Payload { - group_id: number, - enable: boolean -} +const SchemaData = { + type: 'object', + properties: { + group_id: { type: 'number' }, + enable: { type: 'boolean' } + }, + required: ['group_id', 'enable'] +} as const satisfies JSONSchema; + +type Payload = FromSchema; export default class SetGroupWholeBan extends BaseAction { actionName = ActionName.SetGroupWholeBan; - + PayloadSchema = SchemaData; protected async _handle(payload: Payload): Promise { const enable = payload.enable.toString() === 'true'; await NTQQGroupApi.banGroup(payload.group_id.toString(), enable); diff --git a/src/onebot11/action/msg/DeleteMsg.ts b/src/onebot11/action/msg/DeleteMsg.ts index be55c7bf..560dfd32 100644 --- a/src/onebot11/action/msg/DeleteMsg.ts +++ b/src/onebot11/action/msg/DeleteMsg.ts @@ -2,15 +2,21 @@ import { NTQQMsgApi } from '@/core/apis'; import { ActionName } from '../types'; import BaseAction from '../BaseAction'; import { dbUtil } from '@/core/utils/db'; -import { napCatCore } from '@/core'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; -interface Payload { - message_id: number -} +const SchemaData = { + type: 'object', + properties: { + message_id: { type: 'number' }, + }, + required: ['message_id'] +} as const satisfies JSONSchema; + +type Payload = FromSchema; class DeleteMsg extends BaseAction { actionName = ActionName.DeleteMsg; - + PayloadSchema = SchemaData; protected async _handle(payload: Payload) { const msg = await dbUtil.getMsgByShortId(payload.message_id); if (msg) { diff --git a/src/onebot11/action/msg/ForwardSingleMsg.ts b/src/onebot11/action/msg/ForwardSingleMsg.ts index fc7b3884..c33e12f6 100644 --- a/src/onebot11/action/msg/ForwardSingleMsg.ts +++ b/src/onebot11/action/msg/ForwardSingleMsg.ts @@ -4,28 +4,35 @@ import { ChatType, Peer } from '@/core/entities'; import { dbUtil } from '@/core/utils/db'; import { getUidByUin } from '@/core/data'; import { ActionName } from '../types'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; -interface Payload { - message_id: number - group_id: number - user_id?: number -} +const SchemaData = { + type: 'object', + properties: { + message_id: { type: 'number' }, + group_id: { type: 'number' }, + user_id: { type: 'number' } + }, + required: ['message_id'] +} as const satisfies JSONSchema; + +type Payload = FromSchema; class ForwardSingleMsg extends BaseAction { protected async getTargetPeer(payload: Payload): Promise { if (payload.user_id) { const peerUid = getUidByUin(payload.user_id.toString()); - if (!peerUid){ + if (!peerUid) { throw new Error(`无法找到私聊对象${payload.user_id}`); } return { chatType: ChatType.friend, peerUid }; } - return { chatType: ChatType.group, peerUid: payload.group_id.toString() }; + return { chatType: ChatType.group, peerUid: payload.group_id!.toString() }; } protected async _handle(payload: Payload): Promise { const msg = await dbUtil.getMsgByShortId(payload.message_id); - if (!msg){ + if (!msg) { throw new Error(`无法找到消息${payload.message_id}`); } const peer = await this.getTargetPeer(payload); @@ -37,7 +44,7 @@ class ForwardSingleMsg extends BaseAction { peer, [msg.msgId], ); - if (ret.result !== 0){ + if (ret.result !== 0) { throw new Error(`转发消息失败 ${ret.errMsg}`); } return null; @@ -45,9 +52,11 @@ class ForwardSingleMsg extends BaseAction { } export class ForwardFriendSingleMsg extends ForwardSingleMsg { + PayloadSchema = SchemaData; actionName = ActionName.ForwardFriendSingleMsg; } export class ForwardGroupSingleMsg extends ForwardSingleMsg { + PayloadSchema = SchemaData; actionName = ActionName.ForwardGroupSingleMsg; } diff --git a/src/onebot11/action/msg/GetMsg.ts b/src/onebot11/action/msg/GetMsg.ts index 716dd43c..42cf1846 100644 --- a/src/onebot11/action/msg/GetMsg.ts +++ b/src/onebot11/action/msg/GetMsg.ts @@ -3,18 +3,25 @@ import { OB11Constructor } from '../../constructor'; import BaseAction from '../BaseAction'; import { ActionName } from '../types'; import { dbUtil } from '@/core/utils/db'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; -export interface PayloadType { - message_id: number -} - export type ReturnDataType = OB11Message -class GetMsg extends BaseAction { - actionName = ActionName.GetMsg; +const SchemaData = { + type: 'object', + properties: { + message_id: { type: 'number' }, + }, + required: ['message_id'] +} as const satisfies JSONSchema; - protected async _handle(payload: PayloadType) { +type Payload = FromSchema; + +class GetMsg extends BaseAction { + actionName = ActionName.GetMsg; + PayloadSchema = SchemaData; + protected async _handle(payload: Payload) { // log("history msg ids", Object.keys(msgHistory)); if (!payload.message_id) { throw Error('参数message_id不能为空'); diff --git a/src/onebot11/action/msg/MarkMsgAsRead.ts b/src/onebot11/action/msg/MarkMsgAsRead.ts index 1b521715..6e4f2964 100644 --- a/src/onebot11/action/msg/MarkMsgAsRead.ts +++ b/src/onebot11/action/msg/MarkMsgAsRead.ts @@ -3,15 +3,20 @@ import BaseAction from '../BaseAction'; import { ActionName } from '../types'; import { NTQQMsgApi } from '@/core/apis'; import { getFriend, getUidByUin } from '@/core/data'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; -interface Payload { - user_id: number; - group_id?: number; -} +const SchemaData = { + type: 'object', + properties: { + user_id: { type: 'number' }, + group_id: { type: 'number' } + } +} as const satisfies JSONSchema; -class MarkMsgAsRead extends BaseAction { +type PlayloadType = FromSchema; - async getPeer(payload: Payload): Promise { +class MarkMsgAsRead extends BaseAction { + async getPeer(payload: PlayloadType): Promise { if (payload.user_id) { const peerUid = getUidByUin(payload.user_id.toString()); if (!peerUid) { @@ -25,7 +30,7 @@ class MarkMsgAsRead extends BaseAction { } return { chatType: ChatType.group, peerUid: payload.group_id.toString() }; } - protected async _handle(payload: Payload): Promise { + protected async _handle(payload: PlayloadType): Promise { // 调用API const ret = await NTQQMsgApi.setMsgRead(await this.getPeer(payload)); if (ret.result != 0) { @@ -36,9 +41,11 @@ class MarkMsgAsRead extends BaseAction { } // 以下为非标准实现 export class MarkPrivateMsgAsRead extends MarkMsgAsRead { + PayloadSchema = SchemaData; actionName = ActionName.MarkPrivateMsgAsRead; } export class MarkGroupMsgAsRead extends MarkMsgAsRead { + PayloadSchema = SchemaData; actionName = ActionName.MarkGroupMsgAsRead; } diff --git a/src/onebot11/action/msg/SendPrivateMsg.ts b/src/onebot11/action/msg/SendPrivateMsg.ts index e8053307..836a71b2 100644 --- a/src/onebot11/action/msg/SendPrivateMsg.ts +++ b/src/onebot11/action/msg/SendPrivateMsg.ts @@ -1,7 +1,7 @@ import SendMsg from './SendMsg'; import { ActionName, BaseCheckResult } from '../types'; import { OB11PostSendMsg } from '../../types'; - +// 未检测参数 class SendPrivateMsg extends SendMsg { actionName = ActionName.SendPrivateMsg; diff --git a/src/onebot11/action/msg/SetMsgEmojiLike.ts b/src/onebot11/action/msg/SetMsgEmojiLike.ts index 9420ba19..038edea6 100644 --- a/src/onebot11/action/msg/SetMsgEmojiLike.ts +++ b/src/onebot11/action/msg/SetMsgEmojiLike.ts @@ -2,15 +2,22 @@ import { ActionName } from '../types'; import BaseAction from '../BaseAction'; import { dbUtil } from '@/core/utils/db'; import { NTQQMsgApi } from '@/core/apis'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; -interface Payload { - message_id: number, - emoji_id: string -} +const SchemaData = { + type: 'object', + properties: { + message_id: { type: 'number' }, + emoji_id: { type: 'string' } + }, + required: ['message_id', 'emoji_id'] +} as const satisfies JSONSchema; + +type Payload = FromSchema; export class SetMsgEmojiLike extends BaseAction { actionName = ActionName.SetMsgEmojiLike; - + PayloadSchema = SchemaData; protected async _handle(payload: Payload) { const msg = await dbUtil.getMsgByShortId(payload.message_id); if (!msg) { diff --git a/src/onebot11/action/system/Reboot.ts b/src/onebot11/action/system/Reboot.ts index 0dc52ee2..4d2cb34c 100644 --- a/src/onebot11/action/system/Reboot.ts +++ b/src/onebot11/action/system/Reboot.ts @@ -2,10 +2,17 @@ import { rebootWithNormolLogin, rebootWithQuickLogin } from '@/common/utils/rebo import BaseAction from '../BaseAction'; import { ActionName } from '../types'; import { selfInfo } from '@/core/data'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; -interface Payload { - delay: number -} +const SchemaData = { + type: 'object', + properties: { + delay: { type: 'number' } + }, + required: ['delay'] +} as const satisfies JSONSchema; + +type Payload = FromSchema; export class Reboot extends BaseAction { actionName = ActionName.Reboot; diff --git a/src/onebot11/action/user/GetCookies.ts b/src/onebot11/action/user/GetCookies.ts index b395824d..63cdcf1a 100644 --- a/src/onebot11/action/user/GetCookies.ts +++ b/src/onebot11/action/user/GetCookies.ts @@ -4,15 +4,23 @@ import { friends, selfInfo } from '@/core/data'; import BaseAction from '../BaseAction'; import { ActionName } from '../types'; import { NTQQUserApi } from '@/core/apis'; -interface Payload { - domain: string -} +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; interface Response { cookies: string } +const SchemaData = { + type: 'object', + properties: { + domain: { type: 'string' } + }, + required: ['domain'] +} as const satisfies JSONSchema; + +type Payload = FromSchema; + export class GetCookies extends BaseAction { actionName = ActionName.GetCookies; - + PayloadSchema = SchemaData; protected async _handle(payload: Payload) { if (!payload.domain){ throw new Error('缺少参数 domain'); diff --git a/src/onebot11/action/user/GetFriendList.ts b/src/onebot11/action/user/GetFriendList.ts index 5f406dd1..140f926c 100644 --- a/src/onebot11/action/user/GetFriendList.ts +++ b/src/onebot11/action/user/GetFriendList.ts @@ -4,17 +4,23 @@ import { friends } from '@/core/data'; import BaseAction from '../BaseAction'; import { ActionName } from '../types'; import { NTQQFriendApi } from '@/core'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; -interface Payload{ - no_cache: boolean | string -} +// no_cache get时传字符串 +const SchemaData = { + type: 'object', + properties: { + no_cache: { type: 'boolean' }, + } +} as const satisfies JSONSchema; +type Payload = FromSchema; export default class GetFriendList extends BaseAction { actionName = ActionName.GetFriendList; - + PayloadSchema = SchemaData; protected async _handle(payload: Payload) { - if (friends.size === 0 || payload?.no_cache === true || payload?.no_cache === 'true') { + if (friends.size === 0 || payload?.no_cache === true /*|| payload?.no_cache === 'true'*/) { const _friends = await NTQQFriendApi.getFriends(true); // log('强制刷新好友列表,结果: ', _friends) if (_friends.length > 0) { diff --git a/src/onebot11/action/user/SendLike.ts b/src/onebot11/action/user/SendLike.ts index 14183377..74d37bb4 100644 --- a/src/onebot11/action/user/SendLike.ts +++ b/src/onebot11/action/user/SendLike.ts @@ -3,15 +3,22 @@ import BaseAction from '../BaseAction'; import { getFriend, getUidByUin, uid2UinMap } from '@/core/data'; import { ActionName } from '../types'; import { log, logDebug } from '@/common/utils/log'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; -interface Payload { - user_id: number, - times: number -} +const SchemaData = { + type: 'object', + properties: { + user_id: { type: 'number' }, + times: { type: 'number' } + }, + required: ['user_id', 'times'] +} as const satisfies JSONSchema; + +type Payload = FromSchema; export default class SendLike extends BaseAction { actionName = ActionName.SendLike; - + PayloadSchema = SchemaData; protected async _handle(payload: Payload): Promise { logDebug('点赞参数', payload); try { diff --git a/src/onebot11/action/user/SetFriendAddRequest.ts b/src/onebot11/action/user/SetFriendAddRequest.ts index 7fa91298..20385369 100644 --- a/src/onebot11/action/user/SetFriendAddRequest.ts +++ b/src/onebot11/action/user/SetFriendAddRequest.ts @@ -1,17 +1,24 @@ +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; import BaseAction from '../BaseAction'; import { ActionName } from '../types'; import { NTQQFriendApi } from '@/core/apis/friend'; import { friendRequests } from '@/core/data'; -interface Payload { - flag: string, - approve: boolean, - remark?: string, -} +const SchemaData = { + type: 'object', + properties: { + flag: { type: 'string' }, + approve: { type: 'boolean' }, + remark: { type: 'string' } + }, + required: ['flag','approve'] +} as const satisfies JSONSchema; + +type Payload = FromSchema; export default class SetFriendAddRequest extends BaseAction { actionName = ActionName.SetFriendAddRequest; - + PayloadSchema = SchemaData; protected async _handle(payload: Payload): Promise { const approve = payload.approve.toString() === 'true'; const request = friendRequests[payload.flag];