mirror of
https://github.com/jackmerrill/hampbot.git
synced 2025-04-18 09:30:47 -04:00
fix: upload dalle image to discord
This commit is contained in:
parent
40f286f29d
commit
a95b599bd3
@ -3,9 +3,11 @@ package fun
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/jackmerrill/hampbot/internal/utils/config"
|
"github.com/jackmerrill/hampbot/internal/utils/config"
|
||||||
"github.com/jackmerrill/hampbot/internal/utils/embed"
|
"github.com/jackmerrill/hampbot/internal/utils/embed"
|
||||||
"github.com/sashabaranov/go-openai"
|
"github.com/sashabaranov/go-openai"
|
||||||
@ -68,10 +70,31 @@ func (c *Dalle) Exec(ctx shireikan.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.ReplyEmbed(embed.NewSuccessEmbed(ctx).
|
// fetch image from url
|
||||||
SetTitle("DALL-E").
|
img, err := http.Get(resp.Data[0].URL)
|
||||||
SetDescription(prompt).
|
if err != nil {
|
||||||
SetImage(resp.Data[0].URL).
|
ctx.ReplyEmbed(embed.NewErrorEmbed(ctx).SetDescription("Failed to fetch image.").MessageEmbed)
|
||||||
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
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user