🦙请求改POST

This commit is contained in:
源文雨 2023-04-22 14:40:35 +08:00
parent df1d71b9b2
commit 30301f1aba

View File

@ -6,7 +6,6 @@ import (
"encoding/json" "encoding/json"
"math/rand" "math/rand"
"net/http" "net/http"
"net/url"
"os" "os"
"strconv" "strconv"
"strings" "strings"
@ -180,15 +179,20 @@ func init() {
SetBlock(false). SetBlock(false).
Handle(randreply(sm.K)) Handle(randreply(sm.K))
engine.OnMessage(canmatch(tALPACA), func(ctx *zero.Ctx) bool { 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) { }).SetBlock(false).Handle(func(ctx *zero.Ctx) {
msg := ctx.ExtractPlainText() msg := ctx.ExtractPlainText()
if msg != "" { 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 { func(r *http.Request) error {
r.Header.Set("Authorization", alpacatoken) r.Header.Set("Authorization", alpacatoken)
return nil 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 { if err != nil {
logrus.Warnln("[chat] 🦙 err:", err) logrus.Warnln("[chat] 🦙 err:", err)
return return
@ -235,6 +239,11 @@ type simai struct {
K map[string][]string `yaml:"可爱"` K map[string][]string `yaml:"可爱"`
} }
type alpacamsg struct {
Name string
Message string
}
const ( const (
tKIMO = iota tKIMO = iota
tDERE tDERE