mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-06 15:20:22 +00:00
移除ChatGPT & 默认注释 thesaurus
This commit is contained in:
@@ -36,7 +36,7 @@ const (
|
||||
defaultttsindexkey = -2905
|
||||
)
|
||||
|
||||
var replyModes = [...]string{"青云客", "小爱", "ChatGPT"}
|
||||
var replyModes = [...]string{"青云客", "小爱"}
|
||||
|
||||
func setReplyMode(ctx *zero.Ctx, name string) error {
|
||||
gid := ctx.Event.GroupID
|
||||
@@ -62,8 +62,6 @@ func setReplyMode(ctx *zero.Ctx, name string) error {
|
||||
return m.SetData(gid, (m.GetData(index)&^0xff)|(index&0xff))
|
||||
}
|
||||
|
||||
var chats *aireply.ChatGPT
|
||||
|
||||
func getReplyMode(ctx *zero.Ctx) aireply.AIReply {
|
||||
gid := ctx.Event.GroupID
|
||||
if gid == 0 {
|
||||
@@ -71,16 +69,10 @@ func getReplyMode(ctx *zero.Ctx) aireply.AIReply {
|
||||
}
|
||||
m, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
|
||||
if ok {
|
||||
switch m.GetData(gid) & 0xff {
|
||||
case 0:
|
||||
return aireply.NewQYK(aireply.QYKURL, aireply.QYKBotName)
|
||||
case 1:
|
||||
if m.GetData(gid)&0xff == 1 {
|
||||
return aireply.NewXiaoAi(aireply.XiaoAiURL, aireply.XiaoAiBotName)
|
||||
case 2:
|
||||
if chats != nil {
|
||||
return chats
|
||||
}
|
||||
}
|
||||
return aireply.NewQYK(aireply.QYKURL, aireply.QYKBotName)
|
||||
}
|
||||
return aireply.NewQYK(aireply.QYKURL, aireply.QYKBotName)
|
||||
}
|
||||
|
||||
@@ -2,14 +2,10 @@
|
||||
package aireply
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/FloatTech/AnimeAPI/aireply"
|
||||
"github.com/FloatTech/AnimeAPI/chatgpt"
|
||||
"github.com/FloatTech/AnimeAPI/tts/genshin"
|
||||
"github.com/FloatTech/floatbox/binary"
|
||||
ctrl "github.com/FloatTech/zbpctrl"
|
||||
"github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
@@ -35,7 +31,7 @@ func init() { // 插件主体
|
||||
enr := control.Register("aireply", &ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "人工智能回复",
|
||||
Help: "- @Bot 任意文本(任意一句话回复)\n- 设置回复模式[青云客|小爱|ChatGPT]\n- 设置 ChatGPT SessionToken xxx\n- 设置 ChatGPT UA xxx\n- 设置 ChatGPT CF xxx\n- 重置ChatGPT连接",
|
||||
Help: "- @Bot 任意文本(任意一句话回复)\n- 设置回复模式[青云客|小爱]",
|
||||
PrivateDataFolder: "aireply",
|
||||
})
|
||||
|
||||
@@ -63,102 +59,6 @@ func init() { // 插件主体
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("成功"))
|
||||
})
|
||||
|
||||
chatgptfile := enr.DataFolder() + "chatgpt.txt"
|
||||
uafile := enr.DataFolder() + "ua.txt"
|
||||
cffile := enr.DataFolder() + "cf.txt"
|
||||
cfg := &chatgpt.Config{
|
||||
RefreshInterval: time.Hour,
|
||||
Timeout: time.Minute,
|
||||
}
|
||||
data, err := os.ReadFile(chatgptfile)
|
||||
if err == nil {
|
||||
cfg.SessionToken = binary.BytesToString(data)
|
||||
data, err = os.ReadFile(uafile)
|
||||
if err == nil {
|
||||
cfg.UA = binary.BytesToString(data)
|
||||
data, err = os.ReadFile(cffile)
|
||||
if err == nil {
|
||||
cfg.CFClearance = binary.BytesToString(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
chats = aireply.NewChatGPT(cfg)
|
||||
go func() {
|
||||
for range time.NewTicker(time.Hour).C {
|
||||
if chats == nil || cfg.SessionToken == "" {
|
||||
continue
|
||||
}
|
||||
err := os.WriteFile(chatgptfile, binary.StringToBytes(cfg.SessionToken), 0644)
|
||||
if err != nil {
|
||||
logrus.Warnln("[aireply] 保存 chatgpt session token 到", chatgptfile, "失败:", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
enr.OnRegex(`^设置\s*ChatGPT\s*SessionToken\s*(.*)$`, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||
token := ctx.State["regex_matched"].([]string)[1]
|
||||
f, err := os.Create(chatgptfile)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
_, err = f.WriteString(token)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
cfg.SessionToken = token
|
||||
ctx.SendChain(message.Text("设置成功"))
|
||||
})
|
||||
|
||||
enr.OnRegex(`^设置\s*ChatGPT\s*UA\s*(.*)$`, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||
ua := ctx.State["regex_matched"].([]string)[1]
|
||||
f, err := os.Create(uafile)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
_, err = f.WriteString(ua)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
cfg.UA = ua
|
||||
ctx.SendChain(message.Text("设置成功"))
|
||||
})
|
||||
|
||||
enr.OnRegex(`^设置\s*ChatGPT\s*CF\s*(.*)$`, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||
cf := ctx.State["regex_matched"].([]string)[1]
|
||||
f, err := os.Create(cffile)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
_, err = f.WriteString(cf)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
cfg.CFClearance = cf
|
||||
ctx.SendChain(message.Text("设置成功"))
|
||||
})
|
||||
|
||||
enr.OnFullMatch("重置ChatGPT连接").SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||
if chats == nil {
|
||||
ctx.SendChain(message.Text("ERROR: chats 为空"))
|
||||
return
|
||||
}
|
||||
err := chats.Reset(ctx.Event.UserID)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Text("成功"))
|
||||
})
|
||||
|
||||
ent.OnMessage(zero.OnlyToMe).SetBlock(true).Limit(ctxext.LimitByUser).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
msg := ctx.ExtractPlainText()
|
||||
|
||||
Reference in New Issue
Block a user