Skip to content

Commit

Permalink
fix(qq): http of qqguild bot not updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Hieuzest committed Nov 9, 2024
1 parent 12e89f0 commit 66b317d
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions adapters/qq/src/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ export class QQBot<C extends Context = Context> extends Bot<C, QQBot.Config> {
endpoint = endpoint.replace(/^(https?:\/\/)/, '$1sandbox.')
}
// 如果是 bot 类型, 使用固定 token
if (this.config.authType === 'bot') {
this.http = this.ctx.http.extend({
endpoint,
headers: {
'Authorization': `Bot ${this.config.id}.${this.config.token}`,
'X-Union-Appid': this.config.id,
},
})
}
this.http = this.ctx.http.extend({
endpoint,
headers: {
'Authorization': this.config.authType === 'bot' ? `Bot ${this.config.id}.${this.config.token}` : '',
'X-Union-Appid': this.config.id,
},
})

this.ctx.plugin(QQGuildBot, {
parent: this,
Expand Down Expand Up @@ -76,18 +74,10 @@ export class QQBot<C extends Context = Context> extends Bot<C, QQBot.Config> {
this.logger.warn(`POST https://bots.qq.com/app/getAppAccessToken response: %o, trace id: %s`, result.data, result.headers.get('x-tps-trace-id'))
throw new Error('failed to refresh access token')
}
let endpoint = this.config.endpoint
if (this.config.sandbox) {
endpoint = endpoint.replace(/^(https?:\/\/)/, '$1sandbox.')
}

this._token = result.data.access_token
this.http = this.ctx.http.extend({
endpoint,
headers: {
'Authorization': `QQBot ${this._token}`,
'X-Union-Appid': this.config.id,
},
})
this.http.config.headers.Authorization = `QQBot ${this._token}`

// 在上一个 access_token 接近过期的 60 秒内
// 重新请求可以获取到一个新的 access_token
this._timer = setTimeout(() => {
Expand Down

0 comments on commit 66b317d

Please sign in to comment.