mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
feat: forward single msg
feat: statistic sent receive msg count by api get_status
This commit is contained in:
2
src/core
2
src/core
Submodule src/core updated: f22a4cee7d...7dbc526325
@@ -51,6 +51,7 @@ import { GetRobotUinRange } from './extends/GetRobotUinRange';
|
|||||||
import { SetOnlineStatus } from './extends/SetOnlineStatus';
|
import { SetOnlineStatus } from './extends/SetOnlineStatus';
|
||||||
import { GetGroupNotice } from './group/GetGroupNotice';
|
import { GetGroupNotice } from './group/GetGroupNotice';
|
||||||
import { GetGroupEssence } from './group/GetGroupEssence';
|
import { GetGroupEssence } from './group/GetGroupEssence';
|
||||||
|
import { ForwardFriendSingleMsg, ForwardGroupSingleMsg } from '@/onebot11/action/msg/ForwardSingleMsg';
|
||||||
|
|
||||||
export const actionHandlers = [
|
export const actionHandlers = [
|
||||||
new GetFile(),
|
new GetFile(),
|
||||||
@@ -58,6 +59,8 @@ export const actionHandlers = [
|
|||||||
// new GetConfigAction(),
|
// new GetConfigAction(),
|
||||||
// new SetConfigAction(),
|
// new SetConfigAction(),
|
||||||
// new GetGroupAddRequest(),
|
// new GetGroupAddRequest(),
|
||||||
|
new ForwardFriendSingleMsg(),
|
||||||
|
new ForwardGroupSingleMsg(),
|
||||||
new MarkGroupMsgAsRead(),
|
new MarkGroupMsgAsRead(),
|
||||||
new MarkPrivateMsgAsRead(),
|
new MarkPrivateMsgAsRead(),
|
||||||
new SetQQAvatar(),
|
new SetQQAvatar(),
|
||||||
|
53
src/onebot11/action/msg/ForwardSingleMsg.ts
Normal file
53
src/onebot11/action/msg/ForwardSingleMsg.ts
Normal 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;
|
||||||
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from '../BaseAction';
|
import BaseAction from '../BaseAction';
|
||||||
import { OB11Status } from '../../types';
|
import { OB11Status } from '../../types';
|
||||||
import { ActionName } 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> {
|
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> {
|
protected async _handle(payload: any): Promise<OB11Status> {
|
||||||
return {
|
return {
|
||||||
online: !!selfInfo.online,
|
online: !!selfInfo.online,
|
||||||
good: true
|
good: true,
|
||||||
|
stat
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,8 @@ export enum ActionName {
|
|||||||
SetConfig = 'set_config',
|
SetConfig = 'set_config',
|
||||||
Debug = 'debug',
|
Debug = 'debug',
|
||||||
GetFile = 'get_file',
|
GetFile = 'get_file',
|
||||||
|
ForwardFriendSingleMsg = 'forward_friend_single_msg',
|
||||||
|
ForwardGroupSingleMsg = 'forward_group_single_msg',
|
||||||
// onebot 11
|
// onebot 11
|
||||||
SendLike = 'send_like',
|
SendLike = 'send_like',
|
||||||
GetLoginInfo = 'get_login_info',
|
GetLoginInfo = 'get_login_info',
|
||||||
|
@@ -8,13 +8,15 @@ interface Payload {
|
|||||||
domain: string
|
domain: string
|
||||||
}
|
}
|
||||||
interface Response {
|
interface Response {
|
||||||
Pskey: object;
|
cookies: string
|
||||||
Skey: string;
|
|
||||||
}
|
}
|
||||||
export class GetCookies extends BaseAction<Payload, Response> {
|
export class GetCookies extends BaseAction<Payload, Response> {
|
||||||
actionName = ActionName.GetCookies;
|
actionName = ActionName.GetCookies;
|
||||||
|
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
|
if (!payload.domain){
|
||||||
|
throw new Error('缺少参数 domain');
|
||||||
|
}
|
||||||
const _Skey = await NTQQUserApi.getSkey();
|
const _Skey = await NTQQUserApi.getSkey();
|
||||||
// 取Skey
|
// 取Skey
|
||||||
// 先NodeIKernelTicketService.forceFetchClientKey('')
|
// 先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
|
// 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
|
// &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
|
// 取Pskey
|
||||||
// NodeIKernelTipOffService.getPskey([ 'qun.qq.com' ], true )
|
// NodeIKernelTipOffService.getPskey([ 'qun.qq.com' ], true )
|
||||||
// {
|
// {
|
||||||
@@ -42,6 +44,9 @@ export class GetCookies extends BaseAction<Payload, Response> {
|
|||||||
if (!_PSkey || !_Skey) {
|
if (!_PSkey || !_Skey) {
|
||||||
throw new Error('获取Cookies失败');
|
throw new Error('获取Cookies失败');
|
||||||
}
|
}
|
||||||
return { Pskey: _PSkey, Skey: _Skey };
|
const cookies = `pskey=${_PSkey}; skey=${_Skey}`;
|
||||||
|
return {
|
||||||
|
cookies
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import { PicSubType, RawMessage } from '@/core';
|
import { PicSubType, RawMessage } from '@/core';
|
||||||
import { EventType } from './event/OB11BaseEvent';
|
import { EventType } from './event/OB11BaseEvent';
|
||||||
import { CustomMusicSignPostData, IdMusicSignPostData } from '@/core/apis/sign';
|
import { CustomMusicSignPostData, IdMusicSignPostData } from '@/core/apis/sign';
|
||||||
|
import { stat } from '@/core/data';
|
||||||
|
|
||||||
export interface OB11User {
|
export interface OB11User {
|
||||||
user_id: number;
|
user_id: number;
|
||||||
@@ -264,6 +265,7 @@ export interface OB11Version {
|
|||||||
|
|
||||||
export interface OB11Status {
|
export interface OB11Status {
|
||||||
online: boolean | null,
|
online: boolean | null,
|
||||||
good: boolean
|
good: boolean,
|
||||||
|
stat: typeof stat
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user