Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
linyuchen committed May 11, 2024
2 parents 1e252b7 + 780078c commit 698649f
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Develop
node_modules/
package-lock.json
pnpm-lock.yaml
out/
dist/
src/core.lib/common/
Expand All @@ -13,4 +14,4 @@ test

# Build
*.db
checkVersion.sh
checkVersion.sh
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
QQ Version: Windows 9.9.9-23424 / Linux 3.2.7-23361

## 修复与优化
* 重置Rkey获取机制,使用接口分发Rkey

## 新增与调整
* 新增获取好友列表Api /get_friend_category
Expand Down
2 changes: 1 addition & 1 deletion src/core
Submodule core updated from 934d33 to 85d025
8 changes: 6 additions & 2 deletions src/onebot11/action/msg/SendMsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/onebot11/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
58 changes: 58 additions & 0 deletions src/onebot11/rkey.ts
Original file line number Diff line number Diff line change
@@ -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<string> {
if (await this.IsRkeyExpired()) {
await this.RefreshRkey();
}
return this.GroupRkey;
}
async GetPrivateRkey(): Promise<string> {
if (await this.IsRkeyExpired()) {
await this.RefreshRkey();
}
return this.PrivateRkey;
}
async IsRkeyExpired(): Promise<boolean> {
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<any> {
//刷新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<any> {
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();
2 changes: 1 addition & 1 deletion src/onebot11/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export interface OB11MessageIdMusic {
}
export interface OB11MessageCustomMusic {
type: OB11MessageDataType.music
data: CustomMusicSignPostData
data: Omit<CustomMusicSignPostData, 'singer'> & { content?: string }
}

export interface OB11MessageJson {
Expand Down

0 comments on commit 698649f

Please sign in to comment.