Skip to content

Commit

Permalink
feat(satori): support config.token
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Oct 13, 2023
1 parent 7e53297 commit f3a8497
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions adapters/satori/src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ export class SatoriAdapter extends Adapter.WsClientBase<SatoriBot> {
private sequence?: number
private timeout?: NodeJS.Timeout

constructor(public ctx: Context, config: SatoriAdapter.Config) {
constructor(public ctx: Context, public config: SatoriAdapter.Config) {
super(ctx, config)
this.http = ctx.http.extend(config)
this.http = ctx.http.extend({
endpoint: config.endpoint,
headers: {
'Authorization': `Bearer ${config.token}`,
},
})
ctx.on('ready', () => this.start())
ctx.on('dispose', () => this.stop())
}
Expand Down Expand Up @@ -56,6 +61,7 @@ export class SatoriAdapter extends Adapter.WsClientBase<SatoriBot> {
this.socket.send(JSON.stringify({
op: Universal.Opcode.IDENTIFY,
body: {
token: this.config.token,
sequence: this.sequence,
},
}))
Expand Down Expand Up @@ -111,11 +117,13 @@ export class SatoriAdapter extends Adapter.WsClientBase<SatoriBot> {
export namespace SatoriAdapter {
export interface Config extends Adapter.WsClientConfig {
endpoint: string
token?: string
}

export const Config: Schema<Config> = Schema.intersect([
Schema.object({
endpoint: Schema.string().description('API 终结点。').required(),
token: Schema.string().description('API 访问令牌。'),
}),
Adapter.WsClientConfig,
] as const)
Expand Down

0 comments on commit f3a8497

Please sign in to comment.