feat: forward single msg

feat: statistic sent receive msg count by api get_status
This commit is contained in:
linyuchen 2024-05-03 00:59:07 +08:00
parent d361683d79
commit 9cd5708948
7 changed files with 74 additions and 8 deletions

@ -1 +1 @@
Subproject commit f22a4cee7dd1e41073b8e1ad7e99ada33c863992
Subproject commit 7dbc52632549d238dedc0f9b724d4a86eeb87dce

View File

@ -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(),

View File

@ -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<Payload, null> {
protected async getTargetPeer(payload: Payload): Promise<Peer> {
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<null> {
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;
}

View File

@ -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<any, OB11Status> {
@ -10,7 +10,8 @@ export default class GetStatus extends BaseAction<any, OB11Status> {
protected async _handle(payload: any): Promise<OB11Status> {
return {
online: !!selfInfo.online,
good: true
good: true,
stat
};
}
}

View File

@ -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',

View File

@ -8,13 +8,15 @@ interface Payload {
domain: string
}
interface Response {
Pskey: object;
Skey: string;
cookies: string
}
export class GetCookies extends BaseAction<Payload, Response> {
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<Payload, Response> {
// }
// 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<Payload, Response> {
if (!_PSkey || !_Skey) {
throw new Error('获取Cookies失败');
}
return { Pskey: _PSkey, Skey: _Skey };
const cookies = `pskey=${_PSkey}; skey=${_Skey}`;
return {
cookies
};
}
}

View File

@ -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
}