Skip to content

Commit

Permalink
fix: image
Browse files Browse the repository at this point in the history
  • Loading branch information
xjd committed Feb 10, 2024
1 parent 6e54e79 commit 9b69e36
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var StreamRequestOutTime = os.Getenv("STREAM_REQUEST_OUT_TIME")

var DebugEnabled = os.Getenv("DEBUG") == "true"

var Version = "v3.2.1" // this hard coding will be replaced automatically when building, no need to manually change
var Version = "v3.2.2" // this hard coding will be replaced automatically when building, no need to manually change

const (
RequestIdKey = "X-Request-Id"
Expand Down
10 changes: 10 additions & 0 deletions discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"net/url"
"os"
"os/signal"
"regexp"
"strconv"
"strings"
"syscall"
Expand Down Expand Up @@ -287,6 +288,15 @@ func processMessageForOpenAI(m *discordgo.MessageUpdate) model.OpenAIChatComplet
func processMessageForOpenAIImage(m *discordgo.MessageUpdate) model.OpenAIImagesGenerationResponse {
var response model.OpenAIImagesGenerationResponse

re := regexp.MustCompile(`]\((https?://\S+)\)`)
submatches := re.FindAllStringSubmatch(m.Content, -1)

for _, match := range submatches {
response.Data = append(response.Data, struct {
URL string `json:"url"`
}{URL: match[1]})
}

if len(m.Embeds) != 0 {
for _, embed := range m.Embeds {
if embed.Image != nil && !strings.Contains(m.Content, embed.Image.URL) {
Expand Down

0 comments on commit 9b69e36

Please sign in to comment.