build: 1.3.5-beta32

This commit is contained in:
手瓜一十雪
2024-05-18 12:56:03 +08:00
parent b5fba09f0d
commit 3e8d8817bb
15 changed files with 176 additions and 79 deletions

View File

@@ -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<typeof SchemaData>;
class DeleteMsg extends BaseAction<Payload, void> {
actionName = ActionName.DeleteMsg;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const msg = await dbUtil.getMsgByShortId(payload.message_id);
if (msg) {

View File

@@ -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<typeof SchemaData>;
class ForwardSingleMsg extends BaseAction<Payload, null> {
protected async getTargetPeer(payload: Payload): Promise<Peer> {
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<null> {
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<Payload, null> {
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<Payload, null> {
}
export class ForwardFriendSingleMsg extends ForwardSingleMsg {
PayloadSchema = SchemaData;
actionName = ActionName.ForwardFriendSingleMsg;
}
export class ForwardGroupSingleMsg extends ForwardSingleMsg {
PayloadSchema = SchemaData;
actionName = ActionName.ForwardGroupSingleMsg;
}

View File

@@ -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<PayloadType, OB11Message> {
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<typeof SchemaData>;
class GetMsg extends BaseAction<Payload, OB11Message> {
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不能为空');

View File

@@ -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<Payload, null> {
type PlayloadType = FromSchema<typeof SchemaData>;
async getPeer(payload: Payload): Promise<Peer> {
class MarkMsgAsRead extends BaseAction<PlayloadType, null> {
async getPeer(payload: PlayloadType): Promise<Peer> {
if (payload.user_id) {
const peerUid = getUidByUin(payload.user_id.toString());
if (!peerUid) {
@@ -25,7 +30,7 @@ class MarkMsgAsRead extends BaseAction<Payload, null> {
}
return { chatType: ChatType.group, peerUid: payload.group_id.toString() };
}
protected async _handle(payload: Payload): Promise<null> {
protected async _handle(payload: PlayloadType): Promise<null> {
// 调用API
const ret = await NTQQMsgApi.setMsgRead(await this.getPeer(payload));
if (ret.result != 0) {
@@ -36,9 +41,11 @@ class MarkMsgAsRead extends BaseAction<Payload, null> {
}
// 以下为非标准实现
export class MarkPrivateMsgAsRead extends MarkMsgAsRead {
PayloadSchema = SchemaData;
actionName = ActionName.MarkPrivateMsgAsRead;
}
export class MarkGroupMsgAsRead extends MarkMsgAsRead {
PayloadSchema = SchemaData;
actionName = ActionName.MarkGroupMsgAsRead;
}

View File

@@ -1,7 +1,7 @@
import SendMsg from './SendMsg';
import { ActionName, BaseCheckResult } from '../types';
import { OB11PostSendMsg } from '../../types';
// 未检测参数
class SendPrivateMsg extends SendMsg {
actionName = ActionName.SendPrivateMsg;

View File

@@ -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<typeof SchemaData>;
export class SetMsgEmojiLike extends BaseAction<Payload, any> {
actionName = ActionName.SetMsgEmojiLike;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const msg = await dbUtil.getMsgByShortId(payload.message_id);
if (!msg) {