From 30ec964325dfb94419cf6c7d87afb189e0e89746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Sat, 20 Jul 2024 17:33:26 +0800 Subject: [PATCH] feat: new api --- docs/changelogs/CHANGELOG.v1.6.7.md | 9 +++++++-- src/core/src/apis/msg.ts | 3 +++ src/core/src/services/NodeIKernelMsgService.ts | 8 ++++---- src/onebot11/action/index.ts | 5 +++-- src/onebot11/action/msg/MarkMsgAsRead.ts | 9 +++++++++ src/onebot11/action/types.ts | 3 ++- src/onebot11/cqcode.ts | 8 ++++++++ 7 files changed, 36 insertions(+), 9 deletions(-) diff --git a/docs/changelogs/CHANGELOG.v1.6.7.md b/docs/changelogs/CHANGELOG.v1.6.7.md index 8cd25cea..854e70af 100644 --- a/docs/changelogs/CHANGELOG.v1.6.7.md +++ b/docs/changelogs/CHANGELOG.v1.6.7.md @@ -9,12 +9,17 @@ QQ Version: Windows 9.9.12-26000 / Linux 3.2.9-26000 启动方式: WayBoot.03 (Electron Main进程为Node 直接注入代码 同理项目: LiteLoader) ## 修复与优化 -1. 尝试修复卡顿问题 -2. 修复 精华消息被设置/一起听 接受时的报错 +1. 尝试 修复 卡顿问题 +2. 尝试 修复 精华消息被设置/一起听 接受时的报错 +3. 优化 Uin与Uid 转换速度 +4. 修复CQCode可能存在的解码问题 ## 新增与调整 1. 戳一戳上报raw 2. 精华消息设置通知事件 3. 新增设置/删除群精华API +4. 新增最近联系列表API(RAW 不稳定) +5. 上报群精华设置事件 +6. 新增设置所有消息已读API(非标准) 新增的 API 详细见[API文档](https://napneko.github.io/zh-CN/develop/extends_api) diff --git a/src/core/src/apis/msg.ts b/src/core/src/apis/msg.ts index f6333129..0deb5b1d 100644 --- a/src/core/src/apis/msg.ts +++ b/src/core/src/apis/msg.ts @@ -228,4 +228,7 @@ export class NTQQMsgApi { } ); } + static async markallMsgAsRead() { + return napCatCore.session.getMsgService().setAllC2CAndGroupMsgRead(); + } } diff --git a/src/core/src/services/NodeIKernelMsgService.ts b/src/core/src/services/NodeIKernelMsgService.ts index b77055b1..d883745c 100644 --- a/src/core/src/services/NodeIKernelMsgService.ts +++ b/src/core/src/services/NodeIKernelMsgService.ts @@ -299,7 +299,7 @@ export interface NodeIKernelMsgService { setMsgRead(peer: Peer): Promise; - setAllC2CAndGroupMsgRead(...args: unknown[]): unknown; + setAllC2CAndGroupMsgRead(): Promise; setGuildMsgRead(...args: unknown[]): unknown; @@ -355,8 +355,8 @@ export interface NodeIKernelMsgService { getFileThumbSavePathForSend(...args: unknown[]): unknown; getFileThumbSavePath(...args: unknown[]): unknown; - - translatePtt2Text(j2: string, e2: {}, e3: {}): unknown; + //猜测居多 + translatePtt2Text(MsgId: string, Peer: {}, MsgElement: {}): unknown; setPttPlayedState(...args: unknown[]): unknown; @@ -406,7 +406,7 @@ export interface NodeIKernelMsgService { getEmojiResourcePath(...args: unknown[]): unknown; - JoinDragonGroupEmoji(...args: unknown[]): unknown; + JoinDragonGroupEmoji(JoinDragonGroupEmojiReq: any/*joinDragonGroupEmojiReq*/): unknown; getMsgAbstracts(...args: unknown[]): unknown; diff --git a/src/onebot11/action/index.ts b/src/onebot11/action/index.ts index 5cdd6594..97a05acb 100644 --- a/src/onebot11/action/index.ts +++ b/src/onebot11/action/index.ts @@ -34,7 +34,7 @@ import SetGroupAdmin from './group/SetGroupAdmin'; import SetGroupCard from './group/SetGroupCard'; import GetImage from './file/GetImage'; import GetRecord from './file/GetRecord'; -import { GoCQHTTPMarkMsgAsRead, MarkGroupMsgAsRead, MarkPrivateMsgAsRead } from './msg/MarkMsgAsRead'; +import { GoCQHTTPMarkMsgAsRead, MarkAllMsgAsRead, MarkGroupMsgAsRead, MarkPrivateMsgAsRead } from './msg/MarkMsgAsRead'; import CleanCache from './system/CleanCache'; import GoCQHTTPUploadGroupFile from './go-cqhttp/UploadGroupFile'; import { GetConfigAction, SetConfigAction } from '@/onebot11/action/extends/Config'; @@ -153,7 +153,8 @@ export const actionHandlers = [ new GetGroupSystemMsg(), new DelEssenceMsg(), new SetEssenceMsg(), - new GetRecentContact() + new GetRecentContact(), + new MarkAllMsgAsRead() ]; function initActionMap() { diff --git a/src/onebot11/action/msg/MarkMsgAsRead.ts b/src/onebot11/action/msg/MarkMsgAsRead.ts index 10452aef..740be9cf 100644 --- a/src/onebot11/action/msg/MarkMsgAsRead.ts +++ b/src/onebot11/action/msg/MarkMsgAsRead.ts @@ -60,3 +60,12 @@ export class GoCQHTTPMarkMsgAsRead extends BaseAction { return null; } } + +export class MarkAllMsgAsRead extends BaseAction { + actionName = ActionName._MarkAllMsgAsRead; + + protected async _handle(payload: Payload): Promise { + await NTQQMsgApi.markallMsgAsRead(); + return null; + } +} diff --git a/src/onebot11/action/types.ts b/src/onebot11/action/types.ts index 740cbfd3..2b0ed444 100644 --- a/src/onebot11/action/types.ts +++ b/src/onebot11/action/types.ts @@ -96,5 +96,6 @@ export enum ActionName { SetLongNick = 'set_self_longnick', SetEssenceMsg = "set_essence_msg", DelEssenceMsg = "delete_essence_msg", - GetRecentContact = "get_recent_contact" + GetRecentContact = "get_recent_contact", + _MarkAllMsgAsRead = "_mark_all_as_read" } diff --git a/src/onebot11/cqcode.ts b/src/onebot11/cqcode.ts index 4a525e3c..3928ce1e 100644 --- a/src/onebot11/cqcode.ts +++ b/src/onebot11/cqcode.ts @@ -67,6 +67,14 @@ export function encodeCQCode(data: OB11MessageData) { let result = '[CQ:' + data.type; for (const name in data.data) { const value = data.data[name]; + try { + // Check if the value can be converted to a string + value.toString(); + } catch (error) { + // If it can't be converted, skip this name-value pair + // console.warn(`Skipping problematic name-value pair. Name: ${name}, Value: ${value}`); + continue; + } result += `,${name}=${CQCodeEscape(value)}`; } result += ']';