From 12d1f87ad56aa39ed957b7573dc9f6f3d1a5fe12 Mon Sep 17 00:00:00 2001 From: linyuchen Date: Thu, 22 Feb 2024 23:02:23 +0800 Subject: [PATCH 1/4] fix: message id int32 --- src/common/data.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/data.ts b/src/common/data.ts index 3422cab..5c27f9e 100644 --- a/src/common/data.ts +++ b/src/common/data.ts @@ -5,7 +5,7 @@ export let groups: Group[] = [] export let friends: Friend[] = [] export let msgHistory: Record = {} // msgId: RawMessage -let globalMsgId = Date.now() +let globalMsgId = Date.now() / 1000; export function addHistoryMsg(msg: RawMessage): boolean{ let existMsg = msgHistory[msg.msgId] From 8dfc71ab6dbb2929319111c6b3beb329e927b0c8 Mon Sep 17 00:00:00 2001 From: linyuchen Date: Thu, 22 Feb 2024 23:05:07 +0800 Subject: [PATCH 2/4] fix: message id int32 --- src/common/data.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/data.ts b/src/common/data.ts index 5c27f9e..ffba6b3 100644 --- a/src/common/data.ts +++ b/src/common/data.ts @@ -5,7 +5,7 @@ export let groups: Group[] = [] export let friends: Friend[] = [] export let msgHistory: Record = {} // msgId: RawMessage -let globalMsgId = Date.now() / 1000; +let globalMsgId = Math.floor(Date.now() / 1000); export function addHistoryMsg(msg: RawMessage): boolean{ let existMsg = msgHistory[msg.msgId] From 30e488aeaf21f8c9c74fcc16326350ed8cdb727d Mon Sep 17 00:00:00 2001 From: Misa Liu Date: Fri, 23 Feb 2024 10:22:42 +0800 Subject: [PATCH 3/4] fix: Fix var type of `echo` --- src/common/utils.ts | 4 ++++ src/onebot11/action/BaseAction.ts | 2 +- src/onebot11/action/utils.ts | 11 ++++++----- src/onebot11/server/ws/ReverseWebsocket.ts | 4 ++-- src/onebot11/server/ws/WebsocketServer.ts | 6 +++--- src/onebot11/server/ws/reply.ts | 4 ++-- src/onebot11/types.ts | 2 +- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/common/utils.ts b/src/common/utils.ts index b34b1f2..af781e8 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -193,4 +193,8 @@ export async function encodeSilk(filePath: string) { log("convert silk failed", error.stack); return {}; } +} + +export function isNull(value: any) { + return value === undefined || value === null; } \ No newline at end of file diff --git a/src/onebot11/action/BaseAction.ts b/src/onebot11/action/BaseAction.ts index 373bc45..efadd9b 100644 --- a/src/onebot11/action/BaseAction.ts +++ b/src/onebot11/action/BaseAction.ts @@ -23,7 +23,7 @@ class BaseAction { } } - public async websocketHandle(payload: PayloadType, echo: string): Promise> { + public async websocketHandle(payload: PayloadType, echo: any): Promise> { const result = await this.check(payload) if (!result.valid) { return OB11Response.error(result.message, 1400) diff --git a/src/onebot11/action/utils.ts b/src/onebot11/action/utils.ts index b7f71d7..3f4e590 100644 --- a/src/onebot11/action/utils.ts +++ b/src/onebot11/action/utils.ts @@ -1,4 +1,5 @@ import {OB11Return} from '../types'; +import {isNull} from '../../common/utils'; export class OB11Response { static res(data: T, status: string, retcode: number, message: string = ""): OB11Return { @@ -8,21 +9,21 @@ export class OB11Response { data: data, message: message, wording: message, - echo: "" + echo: null } } - static ok(data: T, echo: string = "") { + static ok(data: T, echo: any = null) { let res = OB11Response.res(data, "ok", 0) - if (echo) { + if (!isNull(echo)) { res.echo = echo; } return res; } - static error(err: string, retcode: number, echo: string = "") { + static error(err: string, retcode: number, echo: any = null) { let res = OB11Response.res(null, "failed", retcode, err) - if (echo) { + if (!isNull(echo)) { res.echo = echo; } return res; diff --git a/src/onebot11/server/ws/ReverseWebsocket.ts b/src/onebot11/server/ws/ReverseWebsocket.ts index d95a9a4..0a6721e 100644 --- a/src/onebot11/server/ws/ReverseWebsocket.ts +++ b/src/onebot11/server/ws/ReverseWebsocket.ts @@ -33,8 +33,8 @@ export class ReverseWebsocket { } public async onmessage(msg: string) { - let receiveData: { action: ActionName, params: any, echo?: string } = {action: null, params: {}} - let echo = "" + let receiveData: { action: ActionName, params: any, echo?: any } = {action: null, params: {}} + let echo = null try { receiveData = JSON.parse(msg.toString()) echo = receiveData.echo diff --git a/src/onebot11/server/ws/WebsocketServer.ts b/src/onebot11/server/ws/WebsocketServer.ts index 9bfb761..4690265 100644 --- a/src/onebot11/server/ws/WebsocketServer.ts +++ b/src/onebot11/server/ws/WebsocketServer.ts @@ -18,7 +18,7 @@ class OB11WebsocketServer extends WebsocketServerBase { wsClient.send(JSON.stringify(OB11Response.res(null, "failed", 1403, "token验证失败"))) } - async handleAction(wsClient: WebSocket, actionName: string, params: any, echo?: string) { + async handleAction(wsClient: WebSocket, actionName: string, params: any, echo?: any) { const action: BaseAction = actionMap.get(actionName); if (!action) { return wsReply(wsClient, OB11Response.error("不支持的api " + actionName, 1404, echo)) @@ -34,8 +34,8 @@ class OB11WebsocketServer extends WebsocketServerBase { onConnect(wsClient: WebSocket, url: string, req: IncomingMessage) { if (url == "/api" || url == "/api/" || url == "/") { wsClient.on("message", async (msg) => { - let receiveData: { action: ActionName, params: any, echo?: string } = {action: null, params: {}} - let echo = "" + let receiveData: { action: ActionName, params: any, echo?: any } = {action: null, params: {}} + let echo = null try { receiveData = JSON.parse(msg.toString()) echo = receiveData.echo diff --git a/src/onebot11/server/ws/reply.ts b/src/onebot11/server/ws/reply.ts index f4acaca..ce85622 100644 --- a/src/onebot11/server/ws/reply.ts +++ b/src/onebot11/server/ws/reply.ts @@ -1,13 +1,13 @@ import * as websocket from "ws"; import {OB11Response} from "../../action/utils"; import {PostEventType} from "../postevent"; -import {log} from "../../../common/utils"; +import {isNull, log} from "../../../common/utils"; export function wsReply(wsClient: websocket.WebSocket, data: OB11Response | PostEventType) { try { let packet = Object.assign({ }, data); - if (!packet["echo"]){ + if (isNull(packet["echo"])){ delete packet["echo"]; } wsClient.send(JSON.stringify(packet)) diff --git a/src/onebot11/types.ts b/src/onebot11/types.ts index ab23fbd..1919dac 100644 --- a/src/onebot11/types.ts +++ b/src/onebot11/types.ts @@ -77,7 +77,7 @@ export interface OB11Return { retcode: number data: DataType message: string, - echo?: string, // ws调用api才有此字段 + echo?: any, // ws调用api才有此字段 wording?: string, // go-cqhttp字段,错误信息 } From f4fe26fbe15548670b015432cac53dc6fab9dab7 Mon Sep 17 00:00:00 2001 From: Misa Liu Date: Fri, 23 Feb 2024 10:33:15 +0800 Subject: [PATCH 4/4] fix: Fix `app_version` in `get_version_info` --- src/common/data.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/data.ts b/src/common/data.ts index ffba6b3..2f38353 100644 --- a/src/common/data.ts +++ b/src/common/data.ts @@ -87,4 +87,4 @@ export function getUidByUin(uin: string) { } } -export const version = "v3.6.0" +export const version = "3.6.0"