Skip to content

Commit

Permalink
fix(core): remove incorrect ctx.broadcast() impl, fix #462
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 17, 2022
1 parent ef3be19 commit 11fc702
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
16 changes: 2 additions & 14 deletions packages/koishi/src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export abstract class Assets extends Service {
super(ctx, 'assets')
}

public transform(content: string) {
return segment.transformAsync(content, Object.fromEntries(this.types.map((type) => {
public async transform(content: string) {
return await segment.transformAsync(content, Object.fromEntries(this.types.map((type) => {
return [type, async (data) => segment(type, { url: await this.upload(data.url, data.file) })]
})))
}
Expand Down Expand Up @@ -62,15 +62,3 @@ export namespace Assets {
filename: string
}
}

const { broadcast } = Context.prototype
Context.prototype.broadcast = async function (this: Context, ...args: any[]) {
const index = Array.isArray(args[0]) ? 1 : 0
args[index] = await segment.transformAsync(args[index], Object.fromEntries(Assets.types.map((type) => {
return [type, async (data) => {
const buffer = await this.http.get<ArrayBuffer>(data.url, { responseType: 'arraybuffer' })
return segment(type, { url: 'base64://' + Buffer.from(buffer).toString('base64') })
}]
})))
return broadcast.apply(this, args)
}
2 changes: 1 addition & 1 deletion plugins/common/broadcast/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ before(async () => {

describe('@koishijs/plugin-broadcast', () => {
it('basic support', async () => {
const send = jest.fn<any, any[]>()
const send = jest.fn<Promise<string[]>, [string, string, string?]>(async () => [])
app.bots.forEach(bot => bot.sendMessage = send)

await client.shouldReply('broadcast', '请输入要发送的文本。')
Expand Down

0 comments on commit 11fc702

Please sign in to comment.