From aaccb3990567264adf499274600b1448a97aaac2 Mon Sep 17 00:00:00 2001 From: ReiKohaku Date: Wed, 31 Mar 2021 19:16:01 +0800 Subject: [PATCH] discord-adapter: support base64 image and video --- packages/adapter-discord/src/bot.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/adapter-discord/src/bot.ts b/packages/adapter-discord/src/bot.ts index a467f2aa29..9bfcc71131 100644 --- a/packages/adapter-discord/src/bot.ts +++ b/packages/adapter-discord/src/bot.ts @@ -5,7 +5,7 @@ import { Bot, MessageInfo } from 'koishi-core' import * as DC from './types' import { DiscordChannel, DiscordMessage, DiscordUser, ExecuteWebhookBody, GuildMember, PartialGuild } from './types' import { adaptChannel, adaptGroup, adaptMessage, adaptUser } from './utils' -import { readFileSync } from 'fs' +import { readFileSync, existsSync } from 'fs' import { segment } from 'koishi-utils' import FormData from 'form-data' import FileType from 'file-type' @@ -116,7 +116,13 @@ export class DiscordBot extends Bot<'discord'> { ...addition, }) sentMessageId = r.id - } else { + } else if (data.url.startsWith('base64://')) { + const a = Buffer.from(data.url.substring('base64://'.length), 'base64') + const r = await this.sendEmbedMessage(requestUrl, a, { + ...addition, + }) + sentMessageId = r.id + } else if (existsSync(data.url)) { const r = await this.sendEmbedMessage(requestUrl, readFileSync(data.url), { ...addition, })