Skip to content

Commit

Permalink
fix(emojimix): connection issue in some regions
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed May 2, 2024
1 parent 68fee35 commit 1971e22
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions plugin/emojimix/mix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
package emojimix

import (
"bytes"
"encoding/base64"
"fmt"
"io"
"net/http"
"strconv"

"github.com/FloatTech/floatbox/binary"
ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
Expand All @@ -31,21 +35,29 @@ func init() {
u2 := fmt.Sprintf(bed, emojis[r2], r2, r2, r1)
logrus.Debugln("[emojimix] u1:", u1)
logrus.Debugln("[emojimix] u2:", u2)
resp1, err := http2.Head(u1)
if err == nil {
resp1.Body.Close()
if resp1.StatusCode == http.StatusOK {
ctx.SendChain(message.Image(u1))
buf := bytes.NewBuffer(make([]byte, 0, 65536))
buf.WriteString("base64://")
resp, err := http2.Get(u1)

Check failure on line 40 in plugin/emojimix/mix.go

View workflow job for this annotation

GitHub Actions / lint

response body must be closed (bodyclose)
sendandclose := func(resp *http.Response) {
enc := base64.NewEncoder(base64.StdEncoding, buf)
_, err = io.Copy(enc, resp.Body)
if err != nil {
return
}
_ = enc.Close()
_ = resp.Body.Close()
ctx.SendChain(message.Image(binary.BytesToString(buf.Bytes())))
}
resp2, err := http2.Head(u2)
if err == nil {
resp2.Body.Close()
if resp2.StatusCode == http.StatusOK {
ctx.SendChain(message.Image(u2))
return
}
sendandclose(resp)
return
}
buf.Reset()
buf.WriteString("base64://")
resp, err = http2.Head(u2)

Check failure on line 57 in plugin/emojimix/mix.go

View workflow job for this annotation

GitHub Actions / lint

response body must be closed (bodyclose)
if err == nil {
sendandclose(resp)
return
}
})
}
Expand Down

0 comments on commit 1971e22

Please sign in to comment.