Skip to content

Commit

Permalink
fix(discord): embed typing
Browse files Browse the repository at this point in the history
  • Loading branch information
XxLittleCxX committed Mar 18, 2021
1 parent a976035 commit 7da0784
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/adapter-discord/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class DiscordBot extends Bot<'discord'> {
})
sentMessageId = r.id
}
if (type === 'image' || type === 'video') {
if (type === 'image' || type === 'video' && data.url) {
if (data.url.startsWith('http://') || data.url.startsWith('https://')) {
const a = await axios({
url: data.url,
Expand Down
7 changes: 7 additions & 0 deletions packages/adapter-discord/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Adapter } from 'koishi-core'
import { AxiosRequestConfig } from 'axios'
import { DiscordBot } from './bot'
import WsClient from './ws'
import { Embed } from './types'

export * from './bot'
export * as dc from './types'
Expand All @@ -15,6 +16,12 @@ declare module 'koishi-core' {
discord?: DiscordOptions
}

interface Session {
discord?: {
embeds: Embed[]
}
}

namespace Bot {
interface Platforms {
discord: DiscordBot
Expand Down
6 changes: 4 additions & 2 deletions packages/adapter-discord/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const adaptAuthor = (author: DC.Author): AuthorInfo => ({
nickname: author.username,
})

export async function adaptMessage(bot: DiscordBot, meta: DC.DiscordMessage, session: MessageInfo = {}) {
export async function adaptMessage(bot: DiscordBot, meta: DC.DiscordMessage, session: Partial<Session.Payload<Session.MessageAction>> = {}) {
if (meta.author) {
session.author = adaptAuthor(meta.author)
session.userId = meta.author.id
Expand Down Expand Up @@ -90,7 +90,9 @@ export async function adaptMessage(bot: DiscordBot, meta: DC.DiscordMessage, ses
session.content += segment('video', { url: embed.video.url, proxy_url: embed.video.proxy_url })
}
}
session.content = meta.embeds.map(v => segment('embed', { data: JSON.stringify(v) })).join('') + session.content
session.discord = {
embeds: meta.embeds
}
return session
}

Expand Down

0 comments on commit 7da0784

Please sign in to comment.