Skip to content

Commit 0cb7d0d

Browse files
authored
Merge pull request #1 from FloatTech/master
👍
2 parents 6faa2b6 + df8a320 commit 0cb7d0d

File tree

17 files changed

+165
-167
lines changed

17 files changed

+165
-167
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ zerobot [-h] [-n nickname] [-t token] [-u url] [-p prefix] [-d|w] [-c|s config.j
6868
"command_prefix": "/",
6969
"super_users": [],
7070
"ring_len": 4096,
71-
"latency": 1000000000,
71+
"latency": 233000000,
7272
"max_process_time": 240000000000
7373
},
7474
"ws": [

go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ go 1.19
55
require (
66
github.com/Baidu-AIP/golang-sdk v1.1.1
77
github.com/Coloured-glaze/gg v1.3.4
8-
github.com/FloatTech/AnimeAPI v1.5.2-0.20221105044443-0c9004b2f051
9-
github.com/FloatTech/floatbox v0.0.0-20221029160423-446812ec82d9
10-
github.com/FloatTech/sqlite v0.5.0
8+
github.com/FloatTech/AnimeAPI v1.5.2-0.20221110071402-5672d8466e21
9+
github.com/FloatTech/floatbox v0.0.0-20221110070748-e0d0b3af3e57
10+
github.com/FloatTech/sqlite v0.5.1
1111
github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b
12-
github.com/FloatTech/zbpctrl v1.5.2
13-
github.com/FloatTech/zbputils v1.5.1-0.20221101032142-05b2a4825567
12+
github.com/FloatTech/zbpctrl v1.5.3-0.20221110070900-b2888434e9fc
13+
github.com/FloatTech/zbputils v1.5.1-0.20221110071200-0a9ea4b7e9c4
1414
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c
1515
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc
1616
github.com/antchfx/htmlquery v1.2.5
1717
github.com/corona10/goimagehash v1.1.0
1818
github.com/fumiama/ahsai v0.1.0
1919
github.com/fumiama/cron v1.3.0
2020
github.com/fumiama/go-base16384 v1.6.1
21-
github.com/fumiama/go-registry v0.2.1
21+
github.com/fumiama/go-registry v0.2.2
2222
github.com/fumiama/gotracemoe v0.0.3
2323
github.com/fumiama/sqlite3 v1.14.6
2424
github.com/fumiama/unibase2n v0.0.0-20221003115227-e7db987de949

go.sum

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
44
github.com/Coloured-glaze/gg v1.3.4 h1:l31zIF/HaVwkzjrj+A56RGQoSKyKuR1IWtIrqXGFStI=
55
github.com/Coloured-glaze/gg v1.3.4/go.mod h1:Ih5NLNNDHOy3RJbB0EPqGTreIzq/H02TGThIagh8HJg=
66
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
7-
github.com/FloatTech/AnimeAPI v1.5.2-0.20221105044443-0c9004b2f051 h1:NEW8HzBNybMXAV0NrDpMF31n/e9BFGvNiGkDPGSkouc=
8-
github.com/FloatTech/AnimeAPI v1.5.2-0.20221105044443-0c9004b2f051/go.mod h1:Z+Q4kIPNo/OX4RWw6WGQOQcaNsbkv/wPmPDw8p4aQIY=
9-
github.com/FloatTech/floatbox v0.0.0-20221029160423-446812ec82d9 h1:HYJ7lwaqaOKmbYooPUMWxMhXRTp+JItoyeqa320ARD4=
10-
github.com/FloatTech/floatbox v0.0.0-20221029160423-446812ec82d9/go.mod h1:w+ND28mRaJvxUJ6pRXS6i4cLzutpXsWyroutCzBdL78=
11-
github.com/FloatTech/sqlite v0.5.0 h1:U7J5Omc534PqmH6csfu+ypCo3DS8L91l5lTsxUu3b/U=
12-
github.com/FloatTech/sqlite v0.5.0/go.mod h1:i33d92OtR8jcp5fBUvQtospf27+MkfUxnGwnZ95E/dA=
7+
github.com/FloatTech/AnimeAPI v1.5.2-0.20221110071402-5672d8466e21 h1:Ao45y4vcH2n5Qx1DPyDPc2Wmt7Lol4/MwY1ZknBhGw4=
8+
github.com/FloatTech/AnimeAPI v1.5.2-0.20221110071402-5672d8466e21/go.mod h1:D3VwaTmT25UM+x/0AULJtJw4Mzyhob5YOa90J5QAX/w=
9+
github.com/FloatTech/floatbox v0.0.0-20221110070748-e0d0b3af3e57 h1:1H1QSxBPqq7o4S5/xtl0cI/GOqaiajoBg+156cuK1e4=
10+
github.com/FloatTech/floatbox v0.0.0-20221110070748-e0d0b3af3e57/go.mod h1:72tI2fKLhrNpuj4AlE2HSjJOAtEnUEKOx/+dEYSc4FE=
11+
github.com/FloatTech/sqlite v0.5.1 h1:IjTdnqMVIVIoIEFXhvh/KKBfYxFvG0tk7Rghz65/DAU=
12+
github.com/FloatTech/sqlite v0.5.1/go.mod h1:i33d92OtR8jcp5fBUvQtospf27+MkfUxnGwnZ95E/dA=
1313
github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b h1:tvciXWq2nuvTbFeJGLDNIdRX3BI546D3O7k7vrVueZw=
1414
github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
15-
github.com/FloatTech/zbpctrl v1.5.2 h1:5ap0t2KgROpfTVHqMd9vHKXLeLmRFGI3ZrTPASgFP6s=
16-
github.com/FloatTech/zbpctrl v1.5.2/go.mod h1:BVPivMDJCBImPSdwgizb6sqb7rcDaRE65ZjfgthoC7g=
17-
github.com/FloatTech/zbputils v1.5.1-0.20221101032142-05b2a4825567 h1:bQHNAaTTl/NItJmEzjOCHmUKvRi+OnUB3tvfDGImplo=
18-
github.com/FloatTech/zbputils v1.5.1-0.20221101032142-05b2a4825567/go.mod h1:KDPJDu4KHeB4Gdyt8sqR5+QnIsIDW6XXsFfT1kD7okw=
15+
github.com/FloatTech/zbpctrl v1.5.3-0.20221110070900-b2888434e9fc h1:jNHQsG7kKKkRwey4u9XpQIIBfNXX3SLBCeiTyjhBRQc=
16+
github.com/FloatTech/zbpctrl v1.5.3-0.20221110070900-b2888434e9fc/go.mod h1:zfrIWujK6ORPhOuUUzeKGNOLGI/XXz+78FRHRF9zEFo=
17+
github.com/FloatTech/zbputils v1.5.1-0.20221110071200-0a9ea4b7e9c4 h1:pCUhvQ6LfQFXpHGen+aTeLGyZhBYfeMKXFO7IQKzFMk=
18+
github.com/FloatTech/zbputils v1.5.1-0.20221110071200-0a9ea4b7e9c4/go.mod h1:fUIPd81Bj5wRcjoybxwgwKsMU8+f5QJepsjXWup0vKM=
1919
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
2020
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c h1:cNPOdTNiVwxLpROLjXCgbIPvdkE+BwvxDvgmdYmWx6Q=
2121
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c/go.mod h1:KqZzu7slNKROh3TSYEH/IUMG6f4M+1qubZ5e52QypsE=
@@ -52,8 +52,8 @@ github.com/fumiama/cron v1.3.0 h1:ZWlwuexF+HQHl3cYytEE5HNwD99q+3vNZF1GrEiXCFo=
5252
github.com/fumiama/cron v1.3.0/go.mod h1:bz5Izvgi/xEUI8tlBN8BI2jr9Moo8N4or0KV8xXuPDY=
5353
github.com/fumiama/go-base16384 v1.6.1 h1:4yb4JgmBJDnQtq3XGXXdLrVwEnRpjhMUt4eAcsNeA30=
5454
github.com/fumiama/go-base16384 v1.6.1/go.mod h1:OEn+947GV5gsbTAnyuUW/SrfxJYUdYupSIQXOuGOcXM=
55-
github.com/fumiama/go-registry v0.2.1 h1:PCu4d1OIYkLmoSufyxov3QXRul4lXrAfXfK1pVS2wrQ=
56-
github.com/fumiama/go-registry v0.2.1/go.mod h1:GP45kejHuDLFxcWdksrt75r5rHBqYwtfeUl3JzGWxfQ=
55+
github.com/fumiama/go-registry v0.2.2 h1:BAA/pltg/Ryq3oj4CRJBenVZM6EowOQvtHbv/rPp2LY=
56+
github.com/fumiama/go-registry v0.2.2/go.mod h1:GP45kejHuDLFxcWdksrt75r5rHBqYwtfeUl3JzGWxfQ=
5757
github.com/fumiama/go-simple-protobuf v0.1.0 h1:rLzJgNqB6LHNDVMl81yyNt6ZKziWtVfu+ioF0edlEVw=
5858
github.com/fumiama/go-simple-protobuf v0.1.0/go.mod h1:5yYNapXq1tQMOZg9bOIVhQlZk9pQqpuFIO4DZLbsdy4=
5959
github.com/fumiama/gofastTEA v0.0.10 h1:JJJ+brWD4kie+mmK2TkspDXKzqq0IjXm89aGYfoGhhQ=

kanban/banner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
var (
1010
// Banner ...
1111
Banner = "* OneBot + ZeroBot + Golang\n" +
12-
"* Version 1.5.2-beta2 - 2022-10-28 12:49:51 +0800 CST\n" +
12+
"* Version 1.5.2 - 2022-11-09 15:15:01 +0800 CST\n" +
1313
"* Copyright © 2020 - 2022 FloatTech. All Rights Reserved.\n" +
1414
"* Project: https://github.com/FloatTech/ZeroBot-Plugin"
1515
reg = registry.NewRegReader("reilia.fumiama.top:32664", "fumiama")

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func init() {
204204
prefix := flag.String("p", "/", "Set command prefix.")
205205
runcfg := flag.String("c", "", "Run from config file.")
206206
save := flag.String("s", "", "Save default config to file and exit.")
207-
late := flag.Uint("l", 1000, "Response latency (ms).")
207+
late := flag.Uint("l", 233, "Response latency (ms).")
208208
rsz := flag.Uint("r", 4096, "Receiving buffer ring size.")
209209
maxpt := flag.Uint("x", 4, "Max process time (min).")
210210

plugin/ai_reply/ai_tts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func newttsmode() *ttsmode {
152152
tts := &ttsmode{}
153153
tts.Lock()
154154
defer tts.Unlock()
155-
m, ok := control.Lookup(ttsServiceName)
155+
m, ok := control.Lookup("tts")
156156
tts.mode = make(map[int64]int64, 2*len(soundList))
157157
tts.mode[-2905] = 1
158158
if ok {
@@ -229,7 +229,7 @@ func (tts *ttsmode) setDefaultSoundMode(name string) error {
229229
}
230230
tts.Lock()
231231
defer tts.Unlock()
232-
m, ok := control.Lookup(ttsServiceName)
232+
m, ok := control.Lookup("tts")
233233
if !ok {
234234
return errors.New("[tts] service not found")
235235
}

plugin/ai_reply/main.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,10 @@ import (
1717
"github.com/wdvxdr1123/ZeroBot/message"
1818
)
1919

20-
const (
21-
replyServiceName = "aireply"
22-
ttsServiceName = "tts"
23-
)
24-
2520
var replyModes = [...]string{"青云客", "小爱"}
2621

2722
func init() { // 插件主体
28-
enOftts := control.Register(ttsServiceName, &ctrl.Options[*zero.Ctx]{
23+
enOftts := control.Register("tts", &ctrl.Options[*zero.Ctx]{
2924
DisableOnDefault: true,
3025
Brief: "人工智能语音回复",
3126
Help: "- @Bot 任意文本(任意一句话回复)\n" +
@@ -35,7 +30,7 @@ func init() { // 插件主体
3530
"当前适用的原神人物含有以下:\n" + list(soundList[:], 5),
3631
})
3732
tts := newttsmode()
38-
enOfreply := control.Register(replyServiceName, &ctrl.Options[*zero.Ctx]{
33+
enOfreply := control.Register("aireply", &ctrl.Options[*zero.Ctx]{
3934
DisableOnDefault: false,
4035
Brief: "人工智能回复",
4136
Help: "- @Bot 任意文本(任意一句话回复)\n- 设置回复模式[青云客|小爱]",

plugin/aipaint/aipaint.go

Lines changed: 7 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@
22
package aipaint
33

44
import (
5-
"bytes"
65
"encoding/base64"
76
"encoding/json"
87
"fmt"
9-
"image"
108
"net/url"
11-
"os"
129
"regexp"
1310
"strconv"
1411
"strings"
1512
"time"
1613

1714
"github.com/FloatTech/floatbox/binary"
1815
"github.com/FloatTech/floatbox/file"
19-
"github.com/FloatTech/floatbox/img/writer"
2016
"github.com/FloatTech/floatbox/web"
2117
ctrl "github.com/FloatTech/zbpctrl"
2218
"github.com/FloatTech/zbputils/control"
@@ -54,15 +50,14 @@ func init() { // 插件主体
5450
Brief: "ai绘图",
5551
Help: "- [ ai绘图 | 生成色图 | 生成涩图 | ai画图 ] xxx\n" +
5652
"- [ ai高级绘图 | 高级生成色图 | 高级生成涩图 | ai高级画图 ] [prompt]\n" +
57-
"- [ 以图绘图 | 以图生图 | 以图画图 ] xxx [图片]|@xxx|[qq号]\n" +
5853
"- 设置ai绘图配置 [server] [token]\n" +
5954
"- 设置ai绘图撤回时间90s\n" +
6055
"- 查看ai绘图配置\n" +
6156
"例: 设置ai绘图配置 http://91.217.139.190:5010 abc\n" +
6257
"参考服务器 http://91.217.139.190:5010, http://91.216.169.75:5010, http://185.80.202.180:5010\n" +
6358
"通过 http://91.217.139.190:5010/token 获取token\n" +
6459
"[prompt]参数如下\n" +
65-
"tags:tag词条\nntags:ntag词条\nshape:[Portrait|Landscape|Square]\nscale:[6:20]\nseed:种子\n" +
60+
"tags:tag词条\nntags:ntag词条\nshape:[Portrait|Landscape|Square]\nscale:[6:20]\nseed:种子\nstrength:[0-1] 建议0-0.7\nnoise:[0-1] 建议0-0.15" +
6661
"参数与参数内容用:连接,每个参数之间用回车分割",
6762
PrivateDataFolder: "aipaint",
6863
})
@@ -83,63 +78,6 @@ func init() { // 插件主体
8378
}
8479
sendAiImg(ctx, data, cfg.Interval)
8580
})
86-
engine.OnRegex(`^(以图绘图|以图生图|以图画图)[\s\S]*?(\[CQ:(image\,file=([0-9a-zA-Z]{32}).*|at.+?(\d{5,11}))\].*|(\d+))$`).SetBlock(true).
87-
Handle(func(ctx *zero.Ctx) {
88-
err := cfg.load()
89-
if err != nil {
90-
ctx.SendChain(message.Text("ERROR: ", err))
91-
return
92-
}
93-
c := newContext(ctx.Event.UserID)
94-
list := ctx.State["regex_matched"].([]string)
95-
err = c.prepareLogos(list[4]+list[5]+list[6], strconv.FormatInt(ctx.Event.UserID, 10))
96-
if err != nil {
97-
ctx.SendChain(message.Text("ERROR: ", err))
98-
return
99-
}
100-
args := strings.TrimSuffix(strings.TrimPrefix(list[0], list[1]), list[2])
101-
if args == "" {
102-
ctx.SendChain(message.Text("ERROR: 以图绘图必须添加tag"))
103-
return
104-
}
105-
ctx.SendChain(message.Text("少女祈祷中..."))
106-
postURL := cfg.BaseURL + fmt.Sprintf(aipaintImg2ImgURL, cfg.Token, url.QueryEscape(strings.TrimSpace(strings.ReplaceAll(args, " ", "%20"))))
107-
108-
f, err := os.Open(c.headimgsdir[0])
109-
if err != nil {
110-
ctx.SendChain(message.Text("ERROR: ", err))
111-
return
112-
}
113-
defer f.Close()
114-
115-
img, _, err := image.Decode(f)
116-
if err != nil {
117-
ctx.SendChain(message.Text("ERROR: ", err))
118-
return
119-
}
120-
imageShape := ""
121-
switch {
122-
case img.Bounds().Dx() > img.Bounds().Dy():
123-
imageShape = "Landscape"
124-
case img.Bounds().Dx() == img.Bounds().Dy():
125-
imageShape = "Square"
126-
default:
127-
imageShape = "Portrait"
128-
}
129-
130-
// 图片转base64
131-
base64Bytes, err := writer.ToBase64(img)
132-
if err != nil {
133-
ctx.SendChain(message.Text("ERROR: ", err))
134-
return
135-
}
136-
data, err := web.PostData(postURL+"&shape="+imageShape, "text/plain", bytes.NewReader(base64Bytes))
137-
if err != nil {
138-
ctx.SendChain(message.Text("ERROR: ", err))
139-
return
140-
}
141-
sendAiImg(ctx, data, cfg.Interval)
142-
})
14381
engine.OnPrefixGroup([]string{`ai高级绘图`, `高级生成色图`, `高级生成涩图`, `ai高级画图`}).SetBlock(true).
14482
Handle(func(ctx *zero.Ctx) {
14583
err := cfg.load()
@@ -183,6 +121,12 @@ func init() { // 插件主体
183121
if _, ok := tags["seed"]; ok {
184122
apiurl += "&seed=" + url.QueryEscape(strings.TrimSpace(tags["seed"]))
185123
}
124+
if _, ok := tags["strength"]; ok {
125+
apiurl += "&strength=" + url.QueryEscape(strings.TrimSpace(tags["strength"]))
126+
}
127+
if _, ok := tags["noise"]; ok {
128+
apiurl += "&noise=" + url.QueryEscape(strings.TrimSpace(tags["noise"]))
129+
}
186130
data, err := web.GetData(cfg.BaseURL + apiurl)
187131
if err != nil {
188132
ctx.SendChain(message.Text("ERROR: ", err))

plugin/aipaint/img2img.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Package aipaint ai绘图
2+
package aipaint
3+
4+
import (
5+
"bytes"
6+
"fmt"
7+
"image"
8+
"net/url"
9+
"os"
10+
"strconv"
11+
"strings"
12+
13+
"github.com/FloatTech/floatbox/file"
14+
"github.com/FloatTech/floatbox/img/writer"
15+
"github.com/FloatTech/floatbox/web"
16+
ctrl "github.com/FloatTech/zbpctrl"
17+
"github.com/FloatTech/zbputils/control"
18+
zero "github.com/wdvxdr1123/ZeroBot"
19+
"github.com/wdvxdr1123/ZeroBot/message"
20+
)
21+
22+
func init() { // 插件主体
23+
engine := control.Register("img2img", &ctrl.Options[*zero.Ctx]{
24+
DisableOnDefault: true,
25+
Brief: "以图绘图",
26+
Help: "- [ 以图绘图 | 以图生图 | 以图画图 ] xxx [图片]|@xxx|[qq号]\n" +
27+
"- 官方以图绘图api已失效 需要自建api 其他配置参数同ai绘图",
28+
PrivateDataFolder: "img2img",
29+
})
30+
datapath = file.BOTPATH + "/" + engine.DataFolder()
31+
engine.OnRegex(`^(以图绘图|以图生图|以图画图)[\s\S]*?(\[CQ:(image\,file=([0-9a-zA-Z]{32}).*|at.+?(\d{5,11}))\].*|(\d+))$`).SetBlock(true).
32+
Handle(func(ctx *zero.Ctx) {
33+
err := cfg.load()
34+
if err != nil {
35+
ctx.SendChain(message.Text("ERROR: ", err))
36+
return
37+
}
38+
c := newContext(ctx.Event.UserID)
39+
list := ctx.State["regex_matched"].([]string)
40+
err = c.prepareLogos(list[4]+list[5]+list[6], strconv.FormatInt(ctx.Event.UserID, 10))
41+
if err != nil {
42+
ctx.SendChain(message.Text("ERROR: ", err))
43+
return
44+
}
45+
args := strings.TrimSuffix(strings.TrimPrefix(list[0], list[1]), list[2])
46+
if args == "" {
47+
ctx.SendChain(message.Text("ERROR: 以图绘图必须添加tag"))
48+
return
49+
}
50+
ctx.SendChain(message.Text("少女祈祷中..."))
51+
postURL := cfg.BaseURL + fmt.Sprintf(aipaintImg2ImgURL, cfg.Token, url.QueryEscape(strings.TrimSpace(strings.ReplaceAll(args, " ", "%20"))))
52+
53+
f, err := os.Open(c.headimgsdir[0])
54+
if err != nil {
55+
ctx.SendChain(message.Text("ERROR: ", err))
56+
return
57+
}
58+
defer f.Close()
59+
60+
img, _, err := image.Decode(f)
61+
if err != nil {
62+
ctx.SendChain(message.Text("ERROR: ", err))
63+
return
64+
}
65+
imageShape := ""
66+
switch {
67+
case img.Bounds().Dx() > img.Bounds().Dy():
68+
imageShape = "Landscape"
69+
case img.Bounds().Dx() == img.Bounds().Dy():
70+
imageShape = "Square"
71+
default:
72+
imageShape = "Portrait"
73+
}
74+
75+
// 图片转base64
76+
base64Bytes, err := writer.ToBase64(img)
77+
if err != nil {
78+
ctx.SendChain(message.Text("ERROR: ", err))
79+
return
80+
}
81+
data, err := web.PostData(postURL+"&shape="+imageShape, "text/plain", bytes.NewReader(base64Bytes))
82+
if err != nil {
83+
ctx.SendChain(message.Text("ERROR: ", err))
84+
return
85+
}
86+
sendAiImg(ctx, data, cfg.Interval)
87+
})
88+
}

plugin/atri/atri.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,10 @@ import (
1717
"github.com/FloatTech/zbputils/control"
1818
)
1919

20-
const (
21-
// 服务名
22-
servicename = "atri"
23-
// ATRI 表情的 codechina 镜像
24-
res = "https://gitcode.net/u011570312/zbpdata/-/raw/main/Atri/"
25-
)
20+
const res = "https://gitcode.net/u011570312/zbpdata/-/raw/main/Atri/"
2621

2722
func init() { // 插件主体
28-
engine := control.Register(servicename, &ctrl.Options[*zero.Ctx]{
23+
engine := control.Register("atri", &ctrl.Options[*zero.Ctx]{
2924
DisableOnDefault: false,
3025
Brief: "atri人格文本回复",
3126
Help: "本插件基于 ATRI ,为 Golang 移植版\n" +

0 commit comments

Comments
 (0)