diff --git a/adapters/qq/src/message.ts b/adapters/qq/src/message.ts index 958430fc..cc02a2cf 100644 --- a/adapters/qq/src/message.ts +++ b/adapters/qq/src/message.ts @@ -2,7 +2,6 @@ import * as QQ from './types' import { Context, Dict, h, MessageEncoder, Quester } from '@satorijs/satori' import { QQBot } from './bot' import { QQGuildBot } from './bot/guild' -import { Entry } from '@satorijs/server-temp' export const escapeMarkdown = (val: string) => val @@ -301,16 +300,7 @@ export class QQMessageEncoder extends MessageEncode } async sendFile(type: string, attrs: Dict) { - let url = attrs.src || attrs.url, entry: Entry | undefined - if (await this.bot.ctx.http.isLocal(url)) { - const temp = this.bot.ctx.get('server.temp') - if (!temp) { - return this.bot.logger.warn('missing temporary file service, cannot send assets with private url') - } - entry = await temp.create(url) - url = entry.url - } - await this.flush() + const url = attrs.src || attrs.url let file_type = 0 if (type === 'img' || type === 'image') file_type = 1 else if (type === 'video') file_type = 2 @@ -318,9 +308,16 @@ export class QQMessageEncoder extends MessageEncode else return const data: QQ.Message.File.Request = { file_type, - url, srv_send_msg: false, } + const capture = /^data:([\w/-]+);base64,(.*)$/.exec(url) + if (capture?.[2]) { + data.file_data = capture[2] + } else if (await this.bot.ctx.http.isLocal(url)) { + data.file_data = Buffer.from((await this.bot.ctx.http.file(url)).data).toString('base64') + } else { + data.url = url + } let res: QQ.Message.File.Response try { if (this.session.isDirect) { @@ -337,7 +334,6 @@ export class QQMessageEncoder extends MessageEncode await this.sendFile(type, attrs) } } - entry?.dispose?.() this.retry = false return res } diff --git a/adapters/qq/src/types.ts b/adapters/qq/src/types.ts index fb0b437d..b63946df 100644 --- a/adapters/qq/src/types.ts +++ b/adapters/qq/src/types.ts @@ -455,7 +455,7 @@ export namespace Message { } export interface Request { file_type: Type - url: string + url?: string srv_send_msg: boolean file_data?: unknown }