Skip to content

Commit

Permalink
fix(cqhttp): fix wrong ctx.broadcast implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Aug 31, 2020
1 parent 314a729 commit a16a8cc
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/adapter-cqhttp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ Server.types.undefined = CQHTTP
const { broadcast } = Context.prototype
const imageRE = /\[CQ:image,file=([^,]+),url=([^\]]+)\]/

Context.prototype.broadcast = async function (this: Context, message, forced) {
Context.prototype.broadcast = async function (this: Context, ...args: any[]) {
const index = Array.isArray(args[0]) ? 1 : 0
let message = args[index] as string
let output = ''
let capture: RegExpExecArray
// eslint-disable-next-line no-cond-assign
Expand All @@ -63,8 +65,8 @@ Context.prototype.broadcast = async function (this: Context, message, forced) {
const { data } = await axios.get<ArrayBuffer>(url, { responseType: 'arraybuffer' })
output += `[CQ:image,file=base64://${Buffer.from(data).toString('base64')}]`
}
message = output + message
return broadcast.call(this, message, forced)
args[index] = output + message
return broadcast.apply(this, args)
}

Session.prototype.$send = async function $send(this: Session, message: string, autoEscape = false) {
Expand Down

0 comments on commit a16a8cc

Please sign in to comment.