diff --git a/src/core b/src/core index f22a4cee..7dbc5263 160000 --- a/src/core +++ b/src/core @@ -1 +1 @@ -Subproject commit f22a4cee7dd1e41073b8e1ad7e99ada33c863992 +Subproject commit 7dbc52632549d238dedc0f9b724d4a86eeb87dce diff --git a/src/onebot11/action/index.ts b/src/onebot11/action/index.ts index 61e8f6d8..56959ee2 100644 --- a/src/onebot11/action/index.ts +++ b/src/onebot11/action/index.ts @@ -51,6 +51,7 @@ import { GetRobotUinRange } from './extends/GetRobotUinRange'; import { SetOnlineStatus } from './extends/SetOnlineStatus'; import { GetGroupNotice } from './group/GetGroupNotice'; import { GetGroupEssence } from './group/GetGroupEssence'; +import { ForwardFriendSingleMsg, ForwardGroupSingleMsg } from '@/onebot11/action/msg/ForwardSingleMsg'; export const actionHandlers = [ new GetFile(), @@ -58,6 +59,8 @@ export const actionHandlers = [ // new GetConfigAction(), // new SetConfigAction(), // new GetGroupAddRequest(), + new ForwardFriendSingleMsg(), + new ForwardGroupSingleMsg(), new MarkGroupMsgAsRead(), new MarkPrivateMsgAsRead(), new SetQQAvatar(), diff --git a/src/onebot11/action/msg/ForwardSingleMsg.ts b/src/onebot11/action/msg/ForwardSingleMsg.ts new file mode 100644 index 00000000..fc7b3884 --- /dev/null +++ b/src/onebot11/action/msg/ForwardSingleMsg.ts @@ -0,0 +1,53 @@ +import BaseAction from '../BaseAction'; +import { NTQQMsgApi } from '@/core/apis'; +import { ChatType, Peer } from '@/core/entities'; +import { dbUtil } from '@/core/utils/db'; +import { getUidByUin } from '@/core/data'; +import { ActionName } from '../types'; + +interface Payload { + message_id: number + group_id: number + user_id?: number +} + +class ForwardSingleMsg extends BaseAction { + protected async getTargetPeer(payload: Payload): Promise { + if (payload.user_id) { + const peerUid = getUidByUin(payload.user_id.toString()); + if (!peerUid){ + throw new Error(`无法找到私聊对象${payload.user_id}`); + } + return { chatType: ChatType.friend, peerUid }; + } + 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){ + throw new Error(`无法找到消息${payload.message_id}`); + } + const peer = await this.getTargetPeer(payload); + const ret = await NTQQMsgApi.forwardMsg( + { + chatType: msg.chatType, + peerUid: msg.peerUid, + }, + peer, + [msg.msgId], + ); + if (ret.result !== 0){ + throw new Error(`转发消息失败 ${ret.errMsg}`); + } + return null; + } +} + +export class ForwardFriendSingleMsg extends ForwardSingleMsg { + actionName = ActionName.ForwardFriendSingleMsg; +} + +export class ForwardGroupSingleMsg extends ForwardSingleMsg { + actionName = ActionName.ForwardGroupSingleMsg; +} diff --git a/src/onebot11/action/system/GetStatus.ts b/src/onebot11/action/system/GetStatus.ts index 6f250bf3..affbe13f 100644 --- a/src/onebot11/action/system/GetStatus.ts +++ b/src/onebot11/action/system/GetStatus.ts @@ -1,7 +1,7 @@ import BaseAction from '../BaseAction'; import { OB11Status } from '../../types'; import { ActionName } from '../types'; -import { selfInfo } from '@/core/data'; +import { selfInfo, stat } from '@/core/data'; export default class GetStatus extends BaseAction { @@ -10,7 +10,8 @@ export default class GetStatus extends BaseAction { protected async _handle(payload: any): Promise { return { online: !!selfInfo.online, - good: true + good: true, + stat }; } } diff --git a/src/onebot11/action/types.ts b/src/onebot11/action/types.ts index f2026129..67f7b76c 100644 --- a/src/onebot11/action/types.ts +++ b/src/onebot11/action/types.ts @@ -21,6 +21,8 @@ export enum ActionName { SetConfig = 'set_config', Debug = 'debug', GetFile = 'get_file', + ForwardFriendSingleMsg = 'forward_friend_single_msg', + ForwardGroupSingleMsg = 'forward_group_single_msg', // onebot 11 SendLike = 'send_like', GetLoginInfo = 'get_login_info', diff --git a/src/onebot11/action/user/GetCookies.ts b/src/onebot11/action/user/GetCookies.ts index ecd8808c..cf80156e 100644 --- a/src/onebot11/action/user/GetCookies.ts +++ b/src/onebot11/action/user/GetCookies.ts @@ -8,13 +8,15 @@ interface Payload { domain: string } interface Response { - Pskey: object; - Skey: string; + cookies: string } export class GetCookies extends BaseAction { actionName = ActionName.GetCookies; protected async _handle(payload: Payload) { + if (!payload.domain){ + throw new Error('缺少参数 domain'); + } const _Skey = await NTQQUserApi.getSkey(); // 取Skey // 先NodeIKernelTicketService.forceFetchClientKey('') @@ -29,7 +31,7 @@ export class GetCookies extends BaseAction { // } // request https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=1627126029&clientkey=key // &u1=https%3A%2F%2Fh5.qzone.qq.com%2Fqqnt%2Fqzoneinpcqq%2Ffriend%3Frefresh%3D0%26clientuin%3D0%26darkMode%3D0&keyindex=keyIndex - const _PSkey = await NTQQUserApi.getPSkey([payload.domain]); + const _PSkey = (await NTQQUserApi.getPSkey([payload.domain]))[payload.domain]; // 取Pskey // NodeIKernelTipOffService.getPskey([ 'qun.qq.com' ], true ) // { @@ -42,6 +44,9 @@ export class GetCookies extends BaseAction { if (!_PSkey || !_Skey) { throw new Error('获取Cookies失败'); } - return { Pskey: _PSkey, Skey: _Skey }; + const cookies = `pskey=${_PSkey}; skey=${_Skey}`; + return { + cookies + }; } } diff --git a/src/onebot11/types.ts b/src/onebot11/types.ts index 698cd2fb..9303ba53 100644 --- a/src/onebot11/types.ts +++ b/src/onebot11/types.ts @@ -1,6 +1,7 @@ import { PicSubType, RawMessage } from '@/core'; import { EventType } from './event/OB11BaseEvent'; import { CustomMusicSignPostData, IdMusicSignPostData } from '@/core/apis/sign'; +import { stat } from '@/core/data'; export interface OB11User { user_id: number; @@ -264,6 +265,7 @@ export interface OB11Version { export interface OB11Status { online: boolean | null, - good: boolean + good: boolean, + stat: typeof stat }