Skip to content

Commit

Permalink
fix(protocol): fix adapter satori content encoding, fix #177
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 29, 2024
1 parent 1bd24ac commit ff233e1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion adapters/satori/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@satorijs/adapter-satori",
"description": "Satori Adapter for Satorijs",
"version": "1.0.3",
"version": "1.0.8",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand Down
15 changes: 10 additions & 5 deletions adapters/satori/src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bot, Context, Quester, snakeCase, Universal } from '@satorijs/satori'
import { Bot, Context, h, Quester, snakeCase, Universal } from '@satorijs/satori'

export function transformKey(source: any, callback: (key: string) => string) {
if (!source || typeof source !== 'object') return source
Expand Down Expand Up @@ -28,17 +28,22 @@ export class SatoriBot<C extends Context = Context> extends Bot<C, Universal.Log
public internal = createInternal(this)

constructor(ctx: C, config: Universal.Login) {
super(ctx, config)
super(ctx, config, 'satori')
Object.assign(this, config)
}
}

for (const [key, method] of Object.entries(Universal.Methods)) {
SatoriBot.prototype[key] = function (this: SatoriBot, ...args: any[]) {
SatoriBot.prototype[method.name] = function (this: SatoriBot, ...args: any[]) {
const payload = {}
for (const { name } of method.fields) {
payload[name] = transformKey(args.shift(), snakeCase)
if (name === 'content') {
payload[name] = h.normalize(args.shift()).join('')
} else {
payload[name] = transformKey(args.shift(), snakeCase)
}
}
return this.http.post('/' + key, payload)
this.logger.debug('[request]', key, payload)
return this.http.post('/v1/' + key, payload)
}
}
3 changes: 3 additions & 0 deletions adapters/satori/src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ export class SatoriAdapter<C extends Context = Context> extends Adapter.WsClient
return bot.dispose()
}
const session = bot.session(parsed.body)
if (parsed.body.message?.content) {
session.content = parsed.body.message.content
}
if (parsed.body._type && parsed.body.type !== 'internal') {
session.setInternal(parsed.body._type, parsed.body._data)
}
Expand Down

0 comments on commit ff233e1

Please sign in to comment.