Skip to content

Commit 3da37f0

Browse files
authored
Feature nihongo (#339)
* ✨ 添加日语语法学习 * 🎨 添加err
1 parent c30c919 commit 3da37f0

File tree

6 files changed

+114
-21
lines changed

6 files changed

+114
-21
lines changed

README.md

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ print("run[CQ:image,file="+j["img"]+"]")
706706

707707
- [x] 设置音色40 (0~127)
708708

709-
- [x] 注: 该插件需要安装timidity,linux安装脚本可参考 https://gitcode.net/anto_july/midi/-/raw/master/timidity.sh , windows安装脚本可参考 https://gitcode.net/anto_july/midi/-/raw/master/timidity.bat , windows需要管理员模式运行
709+
- [x] 注: 该插件需要安装timidity, linux安装脚本可参考 https://gitcode.net/anto_july/midi/-/raw/master/timidity.sh, windows安装脚本可参考 https://gitcode.net/anto_july/midi/-/raw/master/timidity.bat?inline=false, windows需要管理员模式运行
710710

711711
- [x] 符号说明: C5是中央C,后面不写数字,默认接5,Cb6<1,b代表降调,#代表升调,6比5高八度,<1代表音长×2,<3代表音长×8,<-1代表音长×0.5,<-3代表音长×0.125,R是休止符
712712

@@ -796,6 +796,14 @@ print("run[CQ:image,file="+j["img"]+"]")
796796

797797
- [x] ?? [缩写]
798798

799+
</details>
800+
<details>
801+
<summary>日语语法学习</summary>
802+
803+
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/nihongo"`
804+
805+
- [x] 日语语法 [xxx] (使用tag随机)
806+
799807
</details>
800808
<details>
801809
<summary>小说</summary>
@@ -932,6 +940,10 @@ print("run[CQ:image,file="+j["img"]+"]")
932940

933941
- [x] 团队猜单词
934942

943+
- [x] 团队六阶猜单词
944+
945+
- [x] 团队七阶猜单词
946+
935947
</details>
936948
<details>
937949
<summary>翻译</summary>
@@ -1004,24 +1016,6 @@ print("run[CQ:image,file="+j["img"]+"]")
10041016

10051017
- 注:由于需要科学,默认注释。
10061018

1007-
</details>
1008-
<details>
1009-
<summary>b站推送</summary>
1010-
1011-
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/bilibili_push"`
1012-
1013-
- [x] 添加b站订阅[uid]
1014-
1015-
- [x] 取消b站订阅[uid]
1016-
1017-
- [x] 取消b站动态订阅[uid]
1018-
1019-
- [x] 取消b站直播订阅[uid]
1020-
1021-
- [x] b站推送列表
1022-
1023-
- 注:由于需要安装Chrome,默认注释,具体看[这里](https://www.yuque.com/xiangrikuidezhongzi/zerobot/qrwxth)
1024-
10251019
</details>
10261020

10271021
### *低优先级*

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ import (
9393
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nativesetu" // 本地涩图
9494
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nativewife" // 本地老婆
9595
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nbnhhsh" // 拼音首字母缩写释义工具
96+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nihongo" // 日语语法学习
9697
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/novel" // 铅笔小说网搜索
9798
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nsfw" // nsfw图片识别
9899
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/omikuji" // 浅草寺求签

plugin/midicreate/midicreate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
func init() {
3131
engine := control.Register("midicreate", &ctrl.Options[*zero.Ctx]{
3232
DisableOnDefault: false,
33-
Help: "midi音乐制作,该插件需要安装timidity,linux安装脚本可参考https://gitcode.net/anto_july/midi/-/raw/master/timidity.sh,windows安装脚本可参考https://gitcode.net/anto_july/midi/-/raw/master/timidity.bat,windows需要管理员模式运行\n" +
33+
Help: "midi音乐制作, 该插件需要安装timidity, linux安装脚本可参考https://gitcode.net/anto_july/midi/-/raw/master/timidity.sh, windows安装脚本可参考https://gitcode.net/anto_july/midi/-/raw/master/timidity.bat?inline=false, windows需要管理员模式运行\n" +
3434
"- midi制作 CCGGAAGR FFEEDDCR GGFFEEDR GGFFEEDR CCGGAAGR FFEEDDCR\n" +
3535
"- 个人听音练习\n" +
3636
"- 团队听音练习\n" +

plugin/nihongo/model.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package nihongo
2+
3+
import (
4+
"fmt"
5+
6+
sql "github.com/FloatTech/sqlite"
7+
)
8+
9+
type grammar struct {
10+
ID int `db:"id"`
11+
Tag string `db:"tag"`
12+
Name string `db:"name"`
13+
Pronunciation string `db:"pronunciation"`
14+
Usage string `db:"usage"`
15+
Meaning string `db:"meaning"`
16+
Explanation string `db:"explanation"`
17+
Example string `db:"example"`
18+
GrammarURL string `db:"grammar_url"`
19+
}
20+
21+
func (g *grammar) string() string {
22+
return fmt.Sprintf("ID:\n%d\n\n标签:\n%s\n\n语法名:\n%s\n\n发音:\n%s\n\n用法:\n%s\n\n意思:\n%s\n\n解说:\n%s\n\n示例:\n%s", g.ID, g.Tag, g.Name, g.Pronunciation, g.Usage, g.Meaning, g.Explanation, g.Example)
23+
}
24+
25+
var db = &sql.Sqlite{}
26+
27+
func getRandomGrammarByTag(tag string) (g grammar) {
28+
_ = db.Find("grammar", &g, "where tag LIKE '%"+tag+"%' ORDER BY RANDOM() limit 1")
29+
return
30+
}

plugin/nihongo/nihongo.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Package nihongo 日语学习
2+
package nihongo
3+
4+
import (
5+
"time"
6+
7+
ctrl "github.com/FloatTech/zbpctrl"
8+
"github.com/FloatTech/zbputils/binary"
9+
"github.com/FloatTech/zbputils/control"
10+
"github.com/FloatTech/zbputils/ctxext"
11+
"github.com/FloatTech/zbputils/img/text"
12+
log "github.com/sirupsen/logrus"
13+
zero "github.com/wdvxdr1123/ZeroBot"
14+
"github.com/wdvxdr1123/ZeroBot/message"
15+
)
16+
17+
func init() {
18+
engine := control.Register("nihongo", &ctrl.Options[*zero.Ctx]{
19+
DisableOnDefault: false,
20+
Help: "日语学习\n- 日语语法[xxx](使用tag随机)",
21+
PublicDataFolder: "Nihongo",
22+
})
23+
24+
getdb := ctxext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
25+
db.DBPath = engine.DataFolder() + "nihongo.db"
26+
_, err := engine.GetLazyData("nihongo.db", true)
27+
if err != nil {
28+
ctx.SendChain(message.Text("ERROR:", err))
29+
return false
30+
}
31+
err = db.Open(time.Hour * 24)
32+
if err != nil {
33+
ctx.SendChain(message.Text("ERROR:", err))
34+
return false
35+
}
36+
err = db.Create("grammar", &grammar{})
37+
if err != nil {
38+
ctx.SendChain(message.Text("ERROR:", err))
39+
return false
40+
}
41+
n, err := db.Count("grammar")
42+
if err != nil {
43+
ctx.SendChain(message.Text("ERROR:", err))
44+
return false
45+
}
46+
log.Infof("[nihongo]读取%d条语法", n)
47+
return true
48+
})
49+
50+
engine.OnRegex(`^日语语法\s?([0-9A-Za-z]{1,6})$`, getdb).SetBlock(true).
51+
Handle(func(ctx *zero.Ctx) {
52+
g := getRandomGrammarByTag(ctx.State["regex_matched"].([]string)[1])
53+
if g.ID == 0 {
54+
ctx.SendChain(message.Text("未能找到", ctx.State["regex_matched"].([]string)[1], "相关标签的语法"))
55+
return
56+
}
57+
data, err := text.RenderToBase64(g.string(), text.FontFile, 400, 20)
58+
if err != nil {
59+
ctx.SendChain(message.Text("ERROR:", err))
60+
return
61+
}
62+
if id := ctx.SendChain(message.Image("base64://" + binary.BytesToString(data))); id.ID() == 0 {
63+
ctx.SendChain(message.Text("ERROR:可能被风控了"))
64+
}
65+
})
66+
}

plugin/wordle/wordle.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ func init() {
6464
DisableOnDefault: false,
6565
Help: "猜单词\n" +
6666
"- 个人猜单词\n" +
67-
"- 团队猜单词",
67+
"- 团队猜单词\n" +
68+
"- 团队六阶猜单词\n" +
69+
"- 团队七阶猜单词",
6870
PublicDataFolder: "Wordle",
6971
}).ApplySingle(single.New(
7072
single.WithKeyFn(func(ctx *zero.Ctx) int64 { return ctx.Event.GroupID }),

0 commit comments

Comments
 (0)