From 30301f1abaa551ed9714d26b61dafa826ff1f099 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: Sat, 22 Apr 2023 14:40:35 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=99=E8=AF=B7=E6=B1=82=E6=94=B9POST?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/thesaurus/chat.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/plugin/thesaurus/chat.go b/plugin/thesaurus/chat.go index e9baf455..0bdfb92a 100644 --- a/plugin/thesaurus/chat.go +++ b/plugin/thesaurus/chat.go @@ -6,7 +6,6 @@ import ( "encoding/json" "math/rand" "net/http" - "net/url" "os" "strconv" "strings" @@ -180,15 +179,20 @@ func init() { SetBlock(false). Handle(randreply(sm.K)) engine.OnMessage(canmatch(tALPACA), func(ctx *zero.Ctx) bool { - return !zero.HasPicture(ctx) && alpacapiurl != "" && alpacatoken != "" + return alpacapiurl != "" && alpacatoken != "" }).SetBlock(false).Handle(func(ctx *zero.Ctx) { msg := ctx.ExtractPlainText() if msg != "" { - data, err := web.RequestDataWithHeaders(http.DefaultClient, alpacapiurl+"/reply?msg="+url.QueryEscape(msg), "GET", + data, err := web.RequestDataWithHeaders(http.DefaultClient, alpacapiurl+"/reply", "POST", func(r *http.Request) error { r.Header.Set("Authorization", alpacatoken) return nil - }, nil) + }, bytes.NewReader(binary.NewWriterF(func(writer *binary.Writer) { + _ = json.NewEncoder(writer).Encode(&alpacamsg{ + Name: ctx.CardOrNickName(ctx.Event.UserID), + Message: msg, + }) + }))) if err != nil { logrus.Warnln("[chat] 🦙 err:", err) return @@ -235,6 +239,11 @@ type simai struct { K map[string][]string `yaml:"可爱"` } +type alpacamsg struct { + Name string + Message string +} + const ( tKIMO = iota tDERE