mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-20 14:30:10 +08:00
优化
This commit is contained in:
parent
1c0270fda0
commit
971c179227
@ -5,6 +5,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -106,7 +107,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
ctx.SendChain(message.Text("成功!"))
|
ctx.SendChain(message.Text("成功!"))
|
||||||
})
|
})
|
||||||
engine.OnRegex(`^设置🦙API地址\s*(http.*)\s*$`).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
engine.OnRegex(`^设置🦙API地址\s*(http.*)\s*$`, zero.SuperUserPermission, zero.OnlyPrivate).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||||
alpacapiurl = ctx.State["regex_matched"].([]string)[1]
|
alpacapiurl = ctx.State["regex_matched"].([]string)[1]
|
||||||
err := os.WriteFile(alpacapifile, binary.StringToBytes(alpacapiurl), 0644)
|
err := os.WriteFile(alpacapifile, binary.StringToBytes(alpacapiurl), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -115,7 +116,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
ctx.SendChain(message.Text("成功!"))
|
ctx.SendChain(message.Text("成功!"))
|
||||||
})
|
})
|
||||||
engine.OnRegex(`^设置🦙token\s*([0-9a-f]{112})\s*$`).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
engine.OnRegex(`^设置🦙token\s*([0-9a-f]{112})\s*$`, zero.SuperUserPermission, zero.OnlyPrivate).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||||
alpacatoken = ctx.State["regex_matched"].([]string)[1]
|
alpacatoken = ctx.State["regex_matched"].([]string)[1]
|
||||||
err := os.WriteFile(alpacatokenfile, binary.StringToBytes(alpacatoken), 0644)
|
err := os.WriteFile(alpacatokenfile, binary.StringToBytes(alpacatoken), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -181,16 +182,26 @@ func init() {
|
|||||||
}).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.GetData(alpacapiurl + "/reply?msg=" + url.QueryEscape(msg))
|
data, err := web.RequestDataWithHeaders(http.DefaultClient, alpacapiurl+"/reply?msg="+url.QueryEscape(msg), "GET",
|
||||||
if err == nil {
|
func(r *http.Request) error {
|
||||||
type reply struct {
|
r.Header.Set("Authorization", alpacatoken)
|
||||||
Msg string
|
return nil
|
||||||
}
|
}, nil)
|
||||||
m := reply{}
|
if err != nil {
|
||||||
err := json.Unmarshal(data, &m)
|
logrus.Warnln("[chat] 🦙 err:", err)
|
||||||
if err == nil && len(m.Msg) > 0 {
|
return
|
||||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text(m.Msg)))
|
}
|
||||||
}
|
type reply struct {
|
||||||
|
Msg string
|
||||||
|
}
|
||||||
|
m := reply{}
|
||||||
|
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)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user