From 0315718ab7b1d77d5443590c2a6b86abdf3c0fc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Thu, 20 Apr 2023 01:14:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/thesaurus/chat.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/plugin/thesaurus/chat.go b/plugin/thesaurus/chat.go index 9331f163..be336b42 100644 --- a/plugin/thesaurus/chat.go +++ b/plugin/thesaurus/chat.go @@ -8,7 +8,9 @@ import ( "net/http" "net/url" "os" + "strconv" "strings" + "time" "github.com/FloatTech/floatbox/binary" "github.com/FloatTech/floatbox/ctxext" @@ -192,6 +194,7 @@ func init() { return } type reply struct { + ID int Msg string } m := reply{} @@ -200,8 +203,25 @@ func init() { logrus.Warnln("[chat] 🦙 unmarshal err:", err) return } - if len(m.Msg) > 0 { - ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text(m.Msg))) + for i := 0; i < 60; i++ { + time.Sleep(time.Second * 4) + data, err := web.RequestDataWithHeaders(http.DefaultClient, alpacapiurl+"/get?id="+strconv.Itoa(m.ID), "GET", + func(r *http.Request) error { + r.Header.Set("Authorization", alpacatoken) + return nil + }, nil) + if err != nil { + continue + } + err = json.Unmarshal(data, &m) + if err != nil { + logrus.Warnln("[chat] 🦙 unmarshal err:", err) + return + } + if len(m.Msg) > 0 { + ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text(m.Msg))) + } + return } } })