From 3da37f0a3ebfc6cb83b416694ad59da6282db50f Mon Sep 17 00:00:00 2001
From: himawari <54976075+guohuiyuan@users.noreply.github.com>
Date: Sun, 24 Jul 2022 23:28:30 +0800
Subject: [PATCH] Feature nihongo (#339)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* ✨ 添加日语语法学习
* 🎨 添加err
---
README.md | 32 +++++++---------
main.go | 1 +
plugin/midicreate/midicreate.go | 2 +-
plugin/nihongo/model.go | 30 +++++++++++++++
plugin/nihongo/nihongo.go | 66 +++++++++++++++++++++++++++++++++
plugin/wordle/wordle.go | 4 +-
6 files changed, 114 insertions(+), 21 deletions(-)
create mode 100644 plugin/nihongo/model.go
create mode 100644 plugin/nihongo/nihongo.go
diff --git a/README.md b/README.md
index 21be122b..099abc93 100644
--- a/README.md
+++ b/README.md
@@ -706,7 +706,7 @@ print("run[CQ:image,file="+j["img"]+"]")
- [x] 设置音色40 (0~127)
- - [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需要管理员模式运行
+ - [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需要管理员模式运行
- [x] 符号说明: C5是中央C,后面不写数字,默认接5,Cb6<1,b代表降调,#代表升调,6比5高八度,<1代表音长×2,<3代表音长×8,<-1代表音长×0.5,<-3代表音长×0.125,R是休止符
@@ -796,6 +796,14 @@ print("run[CQ:image,file="+j["img"]+"]")
- [x] ?? [缩写]
+
+
+ 日语语法学习
+
+ `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/nihongo"`
+
+ - [x] 日语语法 [xxx] (使用tag随机)
+
小说
@@ -932,6 +940,10 @@ print("run[CQ:image,file="+j["img"]+"]")
- [x] 团队猜单词
+ - [x] 团队六阶猜单词
+
+ - [x] 团队七阶猜单词
+
翻译
@@ -1004,24 +1016,6 @@ print("run[CQ:image,file="+j["img"]+"]")
- 注:由于需要科学,默认注释。
-
-
- b站推送
-
- `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/bilibili_push"`
-
- - [x] 添加b站订阅[uid]
-
- - [x] 取消b站订阅[uid]
-
- - [x] 取消b站动态订阅[uid]
-
- - [x] 取消b站直播订阅[uid]
-
- - [x] b站推送列表
-
- - 注:由于需要安装Chrome,默认注释,具体看[这里](https://www.yuque.com/xiangrikuidezhongzi/zerobot/qrwxth)
-
### *低优先级*
diff --git a/main.go b/main.go
index 645bef24..d557b719 100644
--- a/main.go
+++ b/main.go
@@ -93,6 +93,7 @@ import (
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nativesetu" // 本地涩图
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nativewife" // 本地老婆
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nbnhhsh" // 拼音首字母缩写释义工具
+ _ "github.com/FloatTech/ZeroBot-Plugin/plugin/nihongo" // 日语语法学习
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/novel" // 铅笔小说网搜索
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nsfw" // nsfw图片识别
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/omikuji" // 浅草寺求签
diff --git a/plugin/midicreate/midicreate.go b/plugin/midicreate/midicreate.go
index 16a1c9ab..79d58788 100644
--- a/plugin/midicreate/midicreate.go
+++ b/plugin/midicreate/midicreate.go
@@ -30,7 +30,7 @@ import (
func init() {
engine := control.Register("midicreate", &ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
- 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" +
+ 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" +
"- midi制作 CCGGAAGR FFEEDDCR GGFFEEDR GGFFEEDR CCGGAAGR FFEEDDCR\n" +
"- 个人听音练习\n" +
"- 团队听音练习\n" +
diff --git a/plugin/nihongo/model.go b/plugin/nihongo/model.go
new file mode 100644
index 00000000..5c254edb
--- /dev/null
+++ b/plugin/nihongo/model.go
@@ -0,0 +1,30 @@
+package nihongo
+
+import (
+ "fmt"
+
+ sql "github.com/FloatTech/sqlite"
+)
+
+type grammar struct {
+ ID int `db:"id"`
+ Tag string `db:"tag"`
+ Name string `db:"name"`
+ Pronunciation string `db:"pronunciation"`
+ Usage string `db:"usage"`
+ Meaning string `db:"meaning"`
+ Explanation string `db:"explanation"`
+ Example string `db:"example"`
+ GrammarURL string `db:"grammar_url"`
+}
+
+func (g *grammar) string() string {
+ 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)
+}
+
+var db = &sql.Sqlite{}
+
+func getRandomGrammarByTag(tag string) (g grammar) {
+ _ = db.Find("grammar", &g, "where tag LIKE '%"+tag+"%' ORDER BY RANDOM() limit 1")
+ return
+}
diff --git a/plugin/nihongo/nihongo.go b/plugin/nihongo/nihongo.go
new file mode 100644
index 00000000..186c1ec9
--- /dev/null
+++ b/plugin/nihongo/nihongo.go
@@ -0,0 +1,66 @@
+// Package nihongo 日语学习
+package nihongo
+
+import (
+ "time"
+
+ ctrl "github.com/FloatTech/zbpctrl"
+ "github.com/FloatTech/zbputils/binary"
+ "github.com/FloatTech/zbputils/control"
+ "github.com/FloatTech/zbputils/ctxext"
+ "github.com/FloatTech/zbputils/img/text"
+ log "github.com/sirupsen/logrus"
+ zero "github.com/wdvxdr1123/ZeroBot"
+ "github.com/wdvxdr1123/ZeroBot/message"
+)
+
+func init() {
+ engine := control.Register("nihongo", &ctrl.Options[*zero.Ctx]{
+ DisableOnDefault: false,
+ Help: "日语学习\n- 日语语法[xxx](使用tag随机)",
+ PublicDataFolder: "Nihongo",
+ })
+
+ getdb := ctxext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
+ db.DBPath = engine.DataFolder() + "nihongo.db"
+ _, err := engine.GetLazyData("nihongo.db", true)
+ if err != nil {
+ ctx.SendChain(message.Text("ERROR:", err))
+ return false
+ }
+ err = db.Open(time.Hour * 24)
+ if err != nil {
+ ctx.SendChain(message.Text("ERROR:", err))
+ return false
+ }
+ err = db.Create("grammar", &grammar{})
+ if err != nil {
+ ctx.SendChain(message.Text("ERROR:", err))
+ return false
+ }
+ n, err := db.Count("grammar")
+ if err != nil {
+ ctx.SendChain(message.Text("ERROR:", err))
+ return false
+ }
+ log.Infof("[nihongo]读取%d条语法", n)
+ return true
+ })
+
+ engine.OnRegex(`^日语语法\s?([0-9A-Za-z]{1,6})$`, getdb).SetBlock(true).
+ Handle(func(ctx *zero.Ctx) {
+ g := getRandomGrammarByTag(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:可能被风控了"))
+ }
+ })
+}
diff --git a/plugin/wordle/wordle.go b/plugin/wordle/wordle.go
index 5325fb94..3f2dc943 100644
--- a/plugin/wordle/wordle.go
+++ b/plugin/wordle/wordle.go
@@ -64,7 +64,9 @@ func init() {
DisableOnDefault: false,
Help: "猜单词\n" +
"- 个人猜单词\n" +
- "- 团队猜单词",
+ "- 团队猜单词\n" +
+ "- 团队六阶猜单词\n" +
+ "- 团队七阶猜单词",
PublicDataFolder: "Wordle",
}).ApplySingle(single.New(
single.WithKeyFn(func(ctx *zero.Ctx) int64 { return ctx.Event.GroupID }),