mirror of
https://github.com/jackmerrill/hampbot.git
synced 2024-12-04 13:02:59 -08:00
fix: upload dalle image to discord
This commit is contained in:
parent
40f286f29d
commit
a95b599bd3
|
@ -3,9 +3,11 @@ package fun
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/jackmerrill/hampbot/internal/utils/config"
|
||||
"github.com/jackmerrill/hampbot/internal/utils/embed"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
|
@ -68,10 +70,31 @@ func (c *Dalle) Exec(ctx shireikan.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
ctx.ReplyEmbed(embed.NewSuccessEmbed(ctx).
|
||||
SetTitle("DALL-E").
|
||||
SetDescription(prompt).
|
||||
SetImage(resp.Data[0].URL).
|
||||
MessageEmbed)
|
||||
// fetch image from url
|
||||
img, err := http.Get(resp.Data[0].URL)
|
||||
if err != nil {
|
||||
ctx.ReplyEmbed(embed.NewErrorEmbed(ctx).SetDescription("Failed to fetch image.").MessageEmbed)
|
||||
return err
|
||||
}
|
||||
|
||||
ctx.GetSession().ChannelMessageSendComplex(ctx.GetChannel().ID, &discordgo.MessageSend{
|
||||
Content: "Generated image",
|
||||
Embed: &discordgo.MessageEmbed{
|
||||
Title: "Generated image",
|
||||
Description: fmt.Sprintf("Prompt: `%s`", prompt),
|
||||
Image: &discordgo.MessageEmbedImage{
|
||||
URL: "attachment://image.png",
|
||||
},
|
||||
Color: 0x00ff00,
|
||||
},
|
||||
Reference: ctx.GetMessage().Reference(),
|
||||
Files: []*discordgo.File{
|
||||
{
|
||||
Name: "image.png",
|
||||
ContentType: "image/png",
|
||||
Reader: img.Body,
|
||||
},
|
||||
},
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user