Skip to content

Commit

Permalink
fix: fix resource element impl
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 16, 2024
1 parent 2d86b1f commit 535689d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "koishi-plugin-adapter-onebot",
"version": "6.3.0",
"version": "6.4.0",
"description": "OneBot Adapter for Koishi",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -52,12 +52,12 @@
"esbuild": "^0.18.20",
"esbuild-register": "^3.5.0",
"eslint": "^8.55.0",
"koishi": "^4.16.1",
"koishi": "^4.16.4",
"typescript": "^5.3.2",
"yml-register": "^1.1.0"
},
"peerDependencies": {
"koishi": "^4.16.1"
"koishi": "^4.16.4"
},
"dependencies": {
"qface": "^1.4.1"
Expand Down
1 change: 1 addition & 0 deletions src/bot/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { OneBotMessageEncoder } from './message'

export class BaseBot<C extends Context = Context, T extends BaseBot.Config = BaseBot.Config> extends Bot<C, T> {
static MessageEncoder = OneBotMessageEncoder
static inject = ['http']

public parent?: BaseBot
public internal: OneBot.Internal
Expand Down
6 changes: 4 additions & 2 deletions src/bot/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,12 @@ export class OneBotMessageEncoder<C extends Context = Context> extends MessageEn
} else if (type === 'a') {
await this.render(children)
if (attrs.href) this.text(` (${attrs.href}) `)
} else if (['video', 'audio', 'image'].includes(type)) {
} else if (['video', 'audio', 'image', 'img'].includes(type)) {
if (type === 'audio') type = 'record'
if (type === 'img') type = 'image'
attrs = { ...attrs }
attrs.file = attrs.url
attrs.file = attrs.src || attrs.url
delete attrs.src
delete attrs.url
if (attrs.cache) {
attrs.cache = 1
Expand Down
23 changes: 22 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,29 @@ export async function adaptMessage(
h.image(qface.getUrl(id)),
])
},
image(attrs) {
return h('img', {
src: attrs.url || attrs.file,
...attrs,
})
},
record(attrs) {
return h('audio', attrs)
return h('audio', {
src: attrs.url || attrs.file,
...attrs,
})
},
video(attrs) {
return h('video', {
src: attrs.url || attrs.file,
...attrs,
})
},
file(attrs) {
return h('file', {
src: attrs.url || attrs.file,
...attrs,
})
},
})
const [guildId, channelId] = decodeGuildChannelId(data)
Expand Down

0 comments on commit 535689d

Please sign in to comment.