Feature nihongo (#339)

*  添加日语语法学习

* 🎨 添加err
This commit is contained in:
himawari 2022-07-24 23:28:30 +08:00 committed by GitHub
parent c30c9192f4
commit 3da37f0a3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 114 additions and 21 deletions

View File

@ -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] ?? [缩写]
</details>
<details>
<summary>日语语法学习</summary>
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/nihongo"`
- [x] 日语语法 [xxx] (使用tag随机)
</details>
<details>
<summary>小说</summary>
@ -932,6 +940,10 @@ print("run[CQ:image,file="+j["img"]+"]")
- [x] 团队猜单词
- [x] 团队六阶猜单词
- [x] 团队七阶猜单词
</details>
<details>
<summary>翻译</summary>
@ -1004,24 +1016,6 @@ print("run[CQ:image,file="+j["img"]+"]")
- 注:由于需要科学,默认注释。
</details>
<details>
<summary>b站推送</summary>
`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)
</details>
### *低优先级*

View File

@ -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" // 浅草寺求签

View File

@ -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" +

30
plugin/nihongo/model.go Normal file
View File

@ -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
}

66
plugin/nihongo/nihongo.go Normal file
View File

@ -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:可能被风控了"))
}
})
}

View File

@ -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 }),