build: 1.3.5-beta32

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

View File

@ -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<typeof SchemaData>;
export default class SetGroupKick extends BaseAction<Payload, null> {
actionName = ActionName.SetGroupKick;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<null> {
const member = await getGroupMember(payload.group_id, payload.user_id);
if (!member) {

View File

@ -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<typeof SchemaData>;
export default class SetGroupLeave extends BaseAction<Payload, any> {
actionName = ActionName.SetGroupLeave;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<any> {
try {
await NTQQGroupApi.quitGroup(payload.group_id.toString());

View File

@ -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<typeof SchemaData>;
export default class SetGroupName extends BaseAction<Payload, null> {
actionName = ActionName.SetGroupName;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<null> {
await NTQQGroupApi.setGroupName(payload.group_id.toString(), payload.group_name);

View File

@ -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<typeof SchemaData>;
export default class SetGroupWholeBan extends BaseAction<Payload, null> {
actionName = ActionName.SetGroupWholeBan;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<null> {
const enable = payload.enable.toString() === 'true';
await NTQQGroupApi.banGroup(payload.group_id.toString(), enable);

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) {

View File

@ -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<typeof SchemaData>;
export class Reboot extends BaseAction<Payload, null> {
actionName = ActionName.Reboot;

View File

@ -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<typeof SchemaData>;
export class GetCookies extends BaseAction<Payload, Response> {
actionName = ActionName.GetCookies;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
if (!payload.domain){
throw new Error('缺少参数 domain');

View File

@ -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<typeof SchemaData>;
export default class GetFriendList extends BaseAction<Payload, OB11User[]> {
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) {

View File

@ -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<typeof SchemaData>;
export default class SendLike extends BaseAction<Payload, null> {
actionName = ActionName.SendLike;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<null> {
logDebug('点赞参数', payload);
try {

View File

@ -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<typeof SchemaData>;
export default class SetFriendAddRequest extends BaseAction<Payload, null> {
actionName = ActionName.SetFriendAddRequest;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<null> {
const approve = payload.approve.toString() === 'true';
const request = friendRequests[payload.flag];