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/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 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 diff --git a/src/onebot11/action/msg/SendMsg.ts b/src/onebot11/action/msg/SendMsg.ts index baf4bd45..43a384e5 100644 --- a/src/onebot11/action/msg/SendMsg.ts +++ b/src/onebot11/action/msg/SendMsg.ts @@ -314,14 +314,18 @@ export async function createSendElements(messageData: OB11MessageData[], group: break; } } - const musicMsgElement = await genMusicElement(sendMsg.data); + 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(postData); logDebug('生成音乐消息', musicMsgElement); if (musicMsgElement) { sendElements.push(musicMsgElement); } } } - } return { 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 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 {