🎨 优化aipaint撤回,nihongo搜索 (#470)

This commit is contained in:
himawari 2022-10-23 16:50:47 +08:00 committed by GitHub
parent cbb4408668
commit 2fc47a38fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 13 deletions

View File

@ -356,11 +356,11 @@ print("run[CQ:image,file="+j["img"]+"]")
- [x] [ 以图绘图 | 以图生图 | 以图画图 ] xxx [图片]|@xxx|[qq号] - [x] [ 以图绘图 | 以图生图 | 以图画图 ] xxx [图片]|@xxx|[qq号]
- [ ] 设置ai绘图配置 [server] [token] - [x] 设置ai绘图配置 [server] [token]
1: 设置ai绘图配置 http://91.216.169.75:5010 abc 例: 设置ai绘图配置 http://91.216.169.75:5010 abc
例2: 设置ai绘图配置 http://91.217.139.190:5010 abc 参考服务器 http://91.217.139.190:5010, http://91.216.169.75:5010, http://185.80.202.180:5010
通过 http://91.217.139.190:5010/token 获取token 通过 http://91.217.139.190:5010/token 获取token
@ -963,6 +963,8 @@ print("run[CQ:image,file="+j["img"]+"]")
- [x] 日语语法 [xxx] (使用tag随机) - [x] 日语语法 [xxx] (使用tag随机)
- [x] 搜索日语语法 [xxx]
</details> </details>
<details> <details>
<summary>小说</summary> <summary>小说</summary>

View File

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

View File

@ -25,6 +25,11 @@ func (g *grammar) string() string {
var db = &sql.Sqlite{} var db = &sql.Sqlite{}
func getRandomGrammarByTag(tag string) (g grammar) { func getRandomGrammarByTag(tag string) (g grammar) {
_ = db.Find("grammar", &g, "where tag LIKE '%"+tag+"%' ORDER BY RANDOM() limit 1") _ = db.Find("grammar", &g, "WHERE tag LIKE '%"+tag+"%' ORDER BY RANDOM() limit 1")
return
}
func getRandomGrammarByKeyword(keyword string) (g grammar) {
_ = db.Find("grammar", &g, "WHERE (name LIKE '%"+keyword+"%' or pronunciation LIKE '%"+keyword+"%') ORDER BY RANDOM() limit 1")
return return
} }

View File

@ -17,7 +17,8 @@ import (
func init() { func init() {
engine := control.Register("nihongo", &ctrl.Options[*zero.Ctx]{ engine := control.Register("nihongo", &ctrl.Options[*zero.Ctx]{
DisableOnDefault: false, DisableOnDefault: false,
Help: "日语学习\n- 日语语法[xxx](使用tag随机)", Help: "日语学习\n- 日语语法[xxx](使用tag随机)\n" +
"搜索日语语法[xxx]",
PublicDataFolder: "Nihongo", PublicDataFolder: "Nihongo",
}) })
@ -47,7 +48,7 @@ func init() {
return true return true
}) })
engine.OnRegex(`^日语语法\s?([0-9A-Za-zぁ-んァ-ヶ]{1,6})$`, getdb).SetBlock(true). engine.OnRegex(`^日语语法\s?([0-9A-Za-zぁ-んァ-ヶ]{1,6})$`, getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
g := getRandomGrammarByTag(ctx.State["regex_matched"].([]string)[1]) g := getRandomGrammarByTag(ctx.State["regex_matched"].([]string)[1])
if g.ID == 0 { if g.ID == 0 {
@ -63,4 +64,20 @@ func init() {
ctx.SendChain(message.Text("ERROR: 可能被风控了")) ctx.SendChain(message.Text("ERROR: 可能被风控了"))
} }
}) })
engine.OnRegex(`^搜索日语语法\s?([0-9A-Za-zぁ-んァ-ヶ~]{1,25})$`, getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
g := getRandomGrammarByKeyword(ctx.State["regex_matched"].([]string)[1])
if g.ID == 0 {
ctx.SendChain(message.Text("未能找到", ctx.State["regex_matched"].([]string)[1], "相关标签的语法"))
return
}
data, err := text.RenderToBase64(g.string(), text.FontFile, 400, 20)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
if id := ctx.SendChain(message.Image("base64://" + binary.BytesToString(data))); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
}
})
} }

View File

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