Skip to content

Commit

Permalink
build: 1.3.5-beta32
Browse files Browse the repository at this point in the history
  • Loading branch information
MliKiowa committed May 18, 2024
1 parent d6175ac commit 4497403
Show file tree
Hide file tree
Showing 15 changed files with 176 additions and 79 deletions.
20 changes: 14 additions & 6 deletions src/onebot11/action/group/SetGroupKick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 11 additions & 6 deletions src/onebot11/action/group/SetGroupLeave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
16 changes: 11 additions & 5 deletions src/onebot11/action/group/SetGroupName.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
17 changes: 12 additions & 5 deletions src/onebot11/action/group/SetGroupWholeBan.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
16 changes: 11 additions & 5 deletions src/onebot11/action/msg/DeleteMsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
27 changes: 18 additions & 9 deletions src/onebot11/action/msg/ForwardSingleMsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -37,17 +44,19 @@ class ForwardSingleMsg extends BaseAction<Payload, null> {
peer,
[msg.msgId],
);
if (ret.result !== 0){
if (ret.result !== 0) {
throw new Error(`转发消息失败 ${ret.errMsg}`);
}
return null;
}
}

export class ForwardFriendSingleMsg extends ForwardSingleMsg {
PayloadSchema = SchemaData;
actionName = ActionName.ForwardFriendSingleMsg;
}

export class ForwardGroupSingleMsg extends ForwardSingleMsg {
PayloadSchema = SchemaData;
actionName = ActionName.ForwardGroupSingleMsg;
}
21 changes: 14 additions & 7 deletions src/onebot11/action/msg/GetMsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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不能为空');
Expand Down
21 changes: 14 additions & 7 deletions src/onebot11/action/msg/MarkMsgAsRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/onebot11/action/msg/SendPrivateMsg.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SendMsg from './SendMsg';
import { ActionName, BaseCheckResult } from '../types';
import { OB11PostSendMsg } from '../../types';

// 未检测参数
class SendPrivateMsg extends SendMsg {
actionName = ActionName.SendPrivateMsg;

Expand Down
17 changes: 12 additions & 5 deletions src/onebot11/action/msg/SetMsgEmojiLike.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 10 additions & 3 deletions src/onebot11/action/system/Reboot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 12 additions & 4 deletions src/onebot11/action/user/GetCookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Loading

0 comments on commit 4497403

Please sign in to comment.