mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-06 15:20:22 +00:00
@@ -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
30
plugin/nihongo/model.go
Normal 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
66
plugin/nihongo/nihongo.go
Normal 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:可能被风控了"))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -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 }),
|
||||
|
||||
Reference in New Issue
Block a user