Skip to content

Commit 6a0f145

Browse files
authored
fix: 修复部分接口action未被正确替换的问题 (#601)
* fix: 修复部分接口action未被正确替换的问题 * fix: 类型
1 parent 3605147 commit 6a0f145

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

packages/onebot/src/http/http.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,16 @@ export class OneBotHttp extends OneBotCore {
127127
params: OneBotApi[T]['params'],
128128
timeout: number = this._options.timeout
129129
): Promise<OneBotApi[T]['response']> {
130-
const host = `${this._options.httpHost}/${action}`
130+
const realAction = this._formatAction(action)
131+
const host = `${this._options.httpHost}/${realAction}`
131132
const request = JSON.stringify(params)
132-
this.emit(OneBotEventKey.SEND_API, { action, params, request, echo: '' })
133+
this.emit(OneBotEventKey.SEND_API, { action: realAction, params, request, echo: '' })
133134
const data = await http.post(host, request, { timeout, headers: this._options.headers })
134135

135136
if (data.data.status === 'ok') {
136137
return data.data.data
137138
} else {
138-
throw this._formatApiError(action, request, data.data)
139+
throw this._formatApiError(realAction, request, data.data)
139140
}
140141
}
141142

packages/onebot/src/ws/base.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,15 @@ export abstract class OneBotWsBase extends OneBotCore {
105105
timeout: number = this._options.timeout
106106
): Promise<OneBotApi[T]['response']> {
107107
const echo = (++this.echo).toString()
108-
const request = JSON.stringify({ echo, action, params })
108+
const realAction = this._formatAction(action)
109+
const request = JSON.stringify({ echo, action: realAction, params })
109110

110111
return new Promise((resolve, reject) => {
111112
const timeoutId = setTimeout(() => {
112-
reject(this._formatApiError(action, request, '请求超时'))
113+
reject(this._formatApiError(realAction, request, '请求超时'))
113114
}, timeout * 1000)
114115

115-
this.emit(OneBotEventKey.SEND_API, { echo, action, params, request })
116+
this.emit(OneBotEventKey.SEND_API, { echo, action: realAction, params, request })
116117
this._socket.send(request)
117118
this.once(`echo:${echo}`, data => {
118119
/** 停止监听器 */
@@ -121,10 +122,10 @@ export abstract class OneBotWsBase extends OneBotCore {
121122
if (data.status === 'ok') {
122123
resolve(data.data as OneBotApi[T]['response'])
123124
} else {
124-
reject(this._formatApiError(action, request, data))
125+
reject(this._formatApiError(realAction, request, data))
125126
}
126127

127-
this.emit(OneBotEventKey.RESPONSE, { echo, action, params, request, data })
128+
this.emit(OneBotEventKey.RESPONSE, { echo, action: realAction, params, request, data })
128129
})
129130
})
130131
}

0 commit comments

Comments
 (0)