Skip to content

Commit

Permalink
feat(discord): support base64 image and video (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReiKohaku committed Mar 31, 2021
1 parent 217fbcd commit 2e94f45
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/adapter-discord/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
})
Expand Down

0 comments on commit 2e94f45

Please sign in to comment.