Skip to content

Commit 2fc47a3

Browse files
authored
🎨 优化aipaint撤回,nihongo搜索 (#470)
1 parent cbb4408 commit 2fc47a3

File tree

5 files changed

+45
-13
lines changed

5 files changed

+45
-13
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,11 @@ print("run[CQ:image,file="+j["img"]+"]")
356356

357357
- [x] [ 以图绘图 | 以图生图 | 以图画图 ] xxx [图片]|@xxx|[qq号]
358358

359-
- [ ] 设置ai绘图配置 [server] [token]
359+
- [x] 设置ai绘图配置 [server] [token]
360360

361-
例1: 设置ai绘图配置 http://91.216.169.75:5010 abc
361+
: 设置ai绘图配置 http://91.216.169.75:5010 abc
362362

363-
例2: 设置ai绘图配置 http://91.217.139.190:5010 abc
363+
参考服务器 http://91.217.139.190:5010, http://91.216.169.75:5010, http://185.80.202.180:5010
364364

365365
通过 http://91.217.139.190:5010/token 获取token
366366

@@ -962,6 +962,8 @@ print("run[CQ:image,file="+j["img"]+"]")
962962
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/nihongo"`
963963

964964
- [x] 日语语法 [xxx] (使用tag随机)
965+
966+
- [x] 搜索日语语法 [xxx]
965967

966968
</details>
967969
<details>

plugin/aipaint/aipaint.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"regexp"
1313
"strconv"
1414
"strings"
15+
"time"
1516

1617
"github.com/FloatTech/floatbox/binary"
1718
"github.com/FloatTech/floatbox/file"
@@ -54,8 +55,8 @@ func init() { // 插件主体
5455
"- [ ai绘图 | 生成色图 | 生成涩图 | ai画图 ] xxx\n" +
5556
"- [ 以图绘图 | 以图生图 | 以图画图 ] xxx [图片]|@xxx|[qq号]\n" +
5657
"- 设置ai绘图配置 [server] [token]\n" +
57-
"例1: 设置ai绘图配置 http://91.216.169.75:5010 abc\n" +
58-
"例2: 设置ai绘图配置 http://91.217.139.190:5010 abc\n" +
58+
": 设置ai绘图配置 http://91.217.139.190:5010 abc\n" +
59+
"参考服务器 http://91.217.139.190:5010, http://91.216.169.75:5010, http://185.80.202.180:5010" +
5960
"通过 http://91.217.139.190:5010/token 获取token",
6061
PrivateDataFolder: "aipaint",
6162
})
@@ -161,7 +162,13 @@ func sendAiImg(ctx *zero.Ctx, data []byte) {
161162
encodeStr := base64.StdEncoding.EncodeToString(data)
162163
m := message.Message{ctxext.FakeSenderForwardNode(ctx, message.Image("base64://"+encodeStr))}
163164
m = append(m, ctxext.FakeSenderForwardNode(ctx, message.Text(r.String())))
164-
if id := ctx.Send(m).ID(); id == 0 {
165+
if mid := ctx.Send(m); mid.ID() == 0 {
165166
ctx.SendChain(message.Text("ERROR: 可能被风控或下载图片用时过长,请耐心等待"))
167+
} else {
168+
go func(i message.MessageID) {
169+
time.Sleep(90 * time.Second)
170+
ctx.DeleteMessage(i)
171+
}(mid)
166172
}
173+
167174
}

plugin/nihongo/model.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ func (g *grammar) string() string {
2525
var db = &sql.Sqlite{}
2626

2727
func getRandomGrammarByTag(tag string) (g grammar) {
28-
_ = db.Find("grammar", &g, "where tag LIKE '%"+tag+"%' ORDER BY RANDOM() limit 1")
28+
_ = db.Find("grammar", &g, "WHERE tag LIKE '%"+tag+"%' ORDER BY RANDOM() limit 1")
29+
return
30+
}
31+
32+
func getRandomGrammarByKeyword(keyword string) (g grammar) {
33+
_ = db.Find("grammar", &g, "WHERE (name LIKE '%"+keyword+"%' or pronunciation LIKE '%"+keyword+"%') ORDER BY RANDOM() limit 1")
2934
return
3035
}

plugin/nihongo/nihongo.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import (
1717
func init() {
1818
engine := control.Register("nihongo", &ctrl.Options[*zero.Ctx]{
1919
DisableOnDefault: false,
20-
Help: "日语学习\n- 日语语法[xxx](使用tag随机)",
20+
Help: "日语学习\n- 日语语法[xxx](使用tag随机)\n" +
21+
"搜索日语语法[xxx]",
2122
PublicDataFolder: "Nihongo",
2223
})
2324

@@ -47,7 +48,7 @@ func init() {
4748
return true
4849
})
4950

50-
engine.OnRegex(`^日语语法\s?([0-9A-Za-zぁ-んァ-ヶ]{1,6})$`, getdb).SetBlock(true).
51+
engine.OnRegex(`^日语语法\s?([0-9A-Za-zぁ-んァ-ヶ]{1,6})$`, getdb).SetBlock(true).
5152
Handle(func(ctx *zero.Ctx) {
5253
g := getRandomGrammarByTag(ctx.State["regex_matched"].([]string)[1])
5354
if g.ID == 0 {
@@ -63,4 +64,20 @@ func init() {
6364
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
6465
}
6566
})
67+
engine.OnRegex(`^搜索日语语法\s?([0-9A-Za-zぁ-んァ-ヶ~]{1,25})$`, getdb).SetBlock(true).
68+
Handle(func(ctx *zero.Ctx) {
69+
g := getRandomGrammarByKeyword(ctx.State["regex_matched"].([]string)[1])
70+
if g.ID == 0 {
71+
ctx.SendChain(message.Text("未能找到", ctx.State["regex_matched"].([]string)[1], "相关标签的语法"))
72+
return
73+
}
74+
data, err := text.RenderToBase64(g.string(), text.FontFile, 400, 20)
75+
if err != nil {
76+
ctx.SendChain(message.Text("ERROR: ", err))
77+
return
78+
}
79+
if id := ctx.SendChain(message.Image("base64://" + binary.BytesToString(data))); id.ID() == 0 {
80+
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
81+
}
82+
})
6683
}

plugin/shadiao/shadiao.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ import (
1212
)
1313

1414
const (
15-
chpURL = "https://api.shadiao.app/chp"
16-
duURL = "https://api.shadiao.app/du"
17-
pyqURL = "https://api.shadiao.app/pyq"
15+
shadiaoURL = "https://api.shadiao.pro"
16+
chpURL = shadiaoURL + "/chp"
17+
duURL = shadiaoURL + "/du"
18+
pyqURL = shadiaoURL + "/pyq"
1819
yduanziURL = "http://www.yduanzi.com/duanzi/getduanzi"
1920
chayiURL = "https://api.lovelive.tools/api/SweetNothings/Web/0"
2021
ganhaiURL = "https://api.lovelive.tools/api/SweetNothings/Web/1"
2122
ergofabulousURL = "https://ergofabulous.org/luther/?"
2223
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"
23-
sdReferer = "https://api.shadiao.app/"
24+
sdReferer = shadiaoURL
2425
yduanziReferer = "http://www.yduanzi.com/?utm_source=shadiao.app"
2526
loveliveReferer = "https://lovelive.tools/"
2627
)

0 commit comments

Comments
 (0)