Skip to content

Commit 0315718

Browse files
committed
优化
1 parent 971c179 commit 0315718

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

plugin/thesaurus/chat.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import (
88
"net/http"
99
"net/url"
1010
"os"
11+
"strconv"
1112
"strings"
13+
"time"
1214

1315
"github.com/FloatTech/floatbox/binary"
1416
"github.com/FloatTech/floatbox/ctxext"
@@ -192,6 +194,7 @@ func init() {
192194
return
193195
}
194196
type reply struct {
197+
ID int
195198
Msg string
196199
}
197200
m := reply{}
@@ -200,8 +203,25 @@ func init() {
200203
logrus.Warnln("[chat] 🦙 unmarshal err:", err)
201204
return
202205
}
203-
if len(m.Msg) > 0 {
204-
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text(m.Msg)))
206+
for i := 0; i < 60; i++ {
207+
time.Sleep(time.Second * 4)
208+
data, err := web.RequestDataWithHeaders(http.DefaultClient, alpacapiurl+"/get?id="+strconv.Itoa(m.ID), "GET",
209+
func(r *http.Request) error {
210+
r.Header.Set("Authorization", alpacatoken)
211+
return nil
212+
}, nil)
213+
if err != nil {
214+
continue
215+
}
216+
err = json.Unmarshal(data, &m)
217+
if err != nil {
218+
logrus.Warnln("[chat] 🦙 unmarshal err:", err)
219+
return
220+
}
221+
if len(m.Msg) > 0 {
222+
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text(m.Msg)))
223+
}
224+
return
205225
}
206226
}
207227
})

0 commit comments

Comments
 (0)