mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 22:00:11 +08:00
fix(emojimix): connection issue in some regions
This commit is contained in:
parent
68fee3532b
commit
1971e2274a
@ -2,10 +2,14 @@
|
|||||||
package emojimix
|
package emojimix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/FloatTech/floatbox/binary"
|
||||||
ctrl "github.com/FloatTech/zbpctrl"
|
ctrl "github.com/FloatTech/zbpctrl"
|
||||||
"github.com/FloatTech/zbputils/control"
|
"github.com/FloatTech/zbputils/control"
|
||||||
"github.com/FloatTech/zbputils/ctxext"
|
"github.com/FloatTech/zbputils/ctxext"
|
||||||
@ -31,21 +35,29 @@ func init() {
|
|||||||
u2 := fmt.Sprintf(bed, emojis[r2], r2, r2, r1)
|
u2 := fmt.Sprintf(bed, emojis[r2], r2, r2, r1)
|
||||||
logrus.Debugln("[emojimix] u1:", u1)
|
logrus.Debugln("[emojimix] u1:", u1)
|
||||||
logrus.Debugln("[emojimix] u2:", u2)
|
logrus.Debugln("[emojimix] u2:", u2)
|
||||||
resp1, err := http2.Head(u1)
|
buf := bytes.NewBuffer(make([]byte, 0, 65536))
|
||||||
if err == nil {
|
buf.WriteString("base64://")
|
||||||
resp1.Body.Close()
|
resp, err := http2.Get(u1)
|
||||||
if resp1.StatusCode == http.StatusOK {
|
sendandclose := func(resp *http.Response) {
|
||||||
ctx.SendChain(message.Image(u1))
|
enc := base64.NewEncoder(base64.StdEncoding, buf)
|
||||||
|
_, err = io.Copy(enc, resp.Body)
|
||||||
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
_ = enc.Close()
|
||||||
|
_ = resp.Body.Close()
|
||||||
|
ctx.SendChain(message.Image(binary.BytesToString(buf.Bytes())))
|
||||||
}
|
}
|
||||||
resp2, err := http2.Head(u2)
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
resp2.Body.Close()
|
sendandclose(resp)
|
||||||
if resp2.StatusCode == http.StatusOK {
|
|
||||||
ctx.SendChain(message.Image(u2))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
buf.Reset()
|
||||||
|
buf.WriteString("base64://")
|
||||||
|
resp, err = http2.Head(u2)
|
||||||
|
if err == nil {
|
||||||
|
sendandclose(resp)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user