Skip to content

Commit

Permalink
feat(qq): support passive element (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilharp authored Dec 21, 2023
1 parent aaea140 commit acd5acf
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions adapters/qq/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class QQGuildMessageEncoder<C extends Context = Context> extends MessageE
private file: Buffer
private filename: string
fileUrl: string
private passiveId: string
reference: string
private retry = false
private resource: Dict
Expand All @@ -31,6 +32,7 @@ export class QQGuildMessageEncoder<C extends Context = Context> extends MessageE
if (this.options?.session && (Date.now() - this.options?.session?.timestamp) > MSG_TIMEOUT) {
msg_id = null
}
if (this.passiveId) msg_id = this.passiveId

let r: Partial<QQ.Message.Response>
this.bot.logger.debug('use form data %s', useFormData)
Expand Down Expand Up @@ -165,6 +167,8 @@ export class QQGuildMessageEncoder<C extends Context = Context> extends MessageE
} else if (type === 'quote') {
this.reference = attrs.id
await this.flush()
} else if (type === 'passive') {
this.passiveId = attrs.id
} else if (type === 'image' && attrs.url) {
await this.flush()
await this.resolveFile(attrs)
Expand All @@ -183,6 +187,8 @@ const MSG_TIMEOUT = 5 * 60 * 1000 - 2000// 5 mins

export class QQMessageEncoder<C extends Context = Context> extends MessageEncoder<C, QQBot<C>> {
private content: string = ''
private passiveId: string
private passiveSeq: number
private useMarkdown = false
private rows: QQ.Button[][] = []
private attachedFile: QQ.Message.File.Response
Expand All @@ -197,6 +203,8 @@ export class QQMessageEncoder<C extends Context = Context> extends MessageEncode
msg_id = this.options.session.messageId
msg_seq = ++this.options.session['seq']
}
if (this.passiveId) msg_id = this.passiveId
if (this.passiveSeq) msg_seq = this.passiveSeq
const data: QQ.Message.Request = {
content: this.content,
msg_type: QQ.Message.Type.TEXT,
Expand Down Expand Up @@ -360,6 +368,9 @@ export class QQMessageEncoder<C extends Context = Context> extends MessageEncode
const { type, attrs, children } = element
if (type === 'text') {
this.content += attrs.content
} else if (type === 'passive') {
this.passiveId = attrs.id
this.passiveSeq = Number(attrs.seq)
} else if (type === 'image' && attrs.url) {
await this.flush()
const data = await this.sendFile(type, attrs)
Expand Down

0 comments on commit acd5acf

Please sign in to comment.