From c521269409a4e818891bb2c329c640bf96d3152b Mon Sep 17 00:00:00 2001 From: student_2333 Date: Fri, 10 May 2024 21:38:39 +0800 Subject: [PATCH 1/5] fix: custom music card content --- .gitignore | 3 ++- src/onebot11/action/msg/SendMsg.ts | 6 +++++- src/onebot11/types.ts | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 1d58e147..a395f4da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Develop node_modules/ package-lock.json +pnpm-lock.yaml out/ dist/ src/core.lib/common/ @@ -13,4 +14,4 @@ test # Build *.db -checkVersion.sh \ No newline at end of file +checkVersion.sh diff --git a/src/onebot11/action/msg/SendMsg.ts b/src/onebot11/action/msg/SendMsg.ts index baf4bd45..a81ea617 100644 --- a/src/onebot11/action/msg/SendMsg.ts +++ b/src/onebot11/action/msg/SendMsg.ts @@ -314,6 +314,11 @@ export async function createSendElements(messageData: OB11MessageData[], group: break; } } + const postData = { ...sendMsg.data } as IdMusicSignPostData | CustomMusicSignPostData; + if (sendMsg.data.type === 'custom' && sendMsg.data.content) { + (postData as CustomMusicSignPostData).singer = sendMsg.data.content; + delete (postData as OB11MessageCustomMusic['data']).content; + } const musicMsgElement = await genMusicElement(sendMsg.data); logDebug('生成音乐消息', musicMsgElement); if (musicMsgElement) { @@ -321,7 +326,6 @@ export async function createSendElements(messageData: OB11MessageData[], group: } } } - } return { diff --git a/src/onebot11/types.ts b/src/onebot11/types.ts index d0346c41..8918101e 100644 --- a/src/onebot11/types.ts +++ b/src/onebot11/types.ts @@ -212,7 +212,7 @@ export interface OB11MessageIdMusic { } export interface OB11MessageCustomMusic { type: OB11MessageDataType.music - data: CustomMusicSignPostData + data: Omit & { content?: string } } export interface OB11MessageJson { From 0435409870d10bc499dcbf59354a8e7b706c0353 Mon Sep 17 00:00:00 2001 From: student_2333 Date: Fri, 10 May 2024 21:41:06 +0800 Subject: [PATCH 2/5] fix --- src/onebot11/action/msg/SendMsg.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/onebot11/action/msg/SendMsg.ts b/src/onebot11/action/msg/SendMsg.ts index a81ea617..43a384e5 100644 --- a/src/onebot11/action/msg/SendMsg.ts +++ b/src/onebot11/action/msg/SendMsg.ts @@ -319,7 +319,7 @@ export async function createSendElements(messageData: OB11MessageData[], group: (postData as CustomMusicSignPostData).singer = sendMsg.data.content; delete (postData as OB11MessageCustomMusic['data']).content; } - const musicMsgElement = await genMusicElement(sendMsg.data); + const musicMsgElement = await genMusicElement(postData); logDebug('生成音乐消息', musicMsgElement); if (musicMsgElement) { sendElements.push(musicMsgElement); From c0a5ac2ac5706d61d2b487cdaaa317af7662e206 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: Fri, 10 May 2024 23:40:07 +0800 Subject: [PATCH 3/5] feat: ServerRkeyWrapper --- src/onebot11/main.ts | 3 ++- src/onebot11/rkey.ts | 58 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/onebot11/rkey.ts diff --git a/src/onebot11/main.ts b/src/onebot11/main.ts index fb630bb1..f906937a 100644 --- a/src/onebot11/main.ts +++ b/src/onebot11/main.ts @@ -86,7 +86,8 @@ export class NapCatOnebot11 { // console.log('ob11 onRecvMsg', JSON.stringify(msg, null, 2)); logDebug('收到消息', msg); for (const m of msg) { - if (this.bootTime > parseInt(m.msgTime)) { + // try: 减掉3s 试图修复消息半天收不到 + if (this.bootTime - 3> parseInt(m.msgTime)) { logDebug(`消息时间${m.msgTime}早于启动时间${this.bootTime},忽略上报`); continue; } diff --git a/src/onebot11/rkey.ts b/src/onebot11/rkey.ts new file mode 100644 index 00000000..b60a2677 --- /dev/null +++ b/src/onebot11/rkey.ts @@ -0,0 +1,58 @@ +//远端rkey获取 +class ServerRkeyWrapper { + serverUrl: string = ""; + GroupRkey: string = ""; + PrivateRkey: string = ""; + expired_time: number = 0; + async Init(ServerUrl: string) { + this.serverUrl = ServerUrl; + } + async GetGroupRkey(): Promise { + if (await this.IsRkeyExpired()) { + await this.RefreshRkey(); + } + return this.GroupRkey; + } + async GetPrivateRkey(): Promise { + if (await this.IsRkeyExpired()) { + await this.RefreshRkey(); + } + return this.PrivateRkey; + } + async IsRkeyExpired(): Promise { + return new Promise((resolve, reject) => { + let now = new Date().getTime(); + if (now > this.expired_time || this.expired_time == 0) { + resolve(true); + } else { + resolve(false); + } + reject("error"); + }); + } + async RefreshRkey(): Promise { + //刷新rkey + let data = await this.Internal_RefreshRkey(); + this.GroupRkey = data.group_rkey; + this.PrivateRkey = data.private_rkey; + this.expired_time = data.expired_time; + } + async Internal_RefreshRkey(): Promise { + return new Promise((resolve, reject) => { + fetch(this.serverUrl) + .then(response => { + if (!response.ok) { + reject(response.statusText); // 请求失败,返回错误信息 + } + return response.json(); // 解析 JSON 格式的响应体 + }) + .then(data => { + resolve(data); + }) + .catch(error => { + reject(error); + }); + }); + } +} +export const serverRkey = new ServerRkeyWrapper(); \ No newline at end of file From 4c25e4ddee54aa229d9bdd6d9dd5da13b82ce527 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: Fri, 10 May 2024 23:52:18 +0800 Subject: [PATCH 4/5] build: 1.3.2-beta1 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d009ae1c..9dd64f2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ QQ Version: Windows 9.9.9-23424 / Linux 3.2.7-23361 ## 修复与优化 +* 重置Rkey获取机制,使用接口分发Rkey ## 新增与调整 * 新增获取好友列表Api /get_friend_category From 780078c3aa63790a6692274aeb46acc5557ddc83 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, 11 May 2024 10:15:08 +0800 Subject: [PATCH 5/5] build: 1.3.0-beta2 --- src/core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core b/src/core index 934d336b..85d0256d 160000 --- a/src/core +++ b/src/core @@ -1 +1 @@ -Subproject commit 934d336bbdd2ac59a2b5d025bf4c0d7b2879bf54 +Subproject commit 85d0256dbcc9cf0d1773da3f10cfc180be1ab56b