diff --git a/README.md b/README.md index 14b66946..0b87f58f 100644 --- a/README.md +++ b/README.md @@ -231,6 +231,8 @@ zerobot -h -t token -u url [-d|w] [-g 监听地址:端口] qq1 qq2 qq3 ... - [x] 讲个段子 - **笑话** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_funny"` - [x] 讲个笑话[@xxx]|讲个笑话[qq号] +- **抽象话** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_chouxianghua"` + - [x] 抽象翻译[xxx] - **TODO...** ## 使用方法 diff --git a/data/ChouXiangHua/cxh.db b/data/ChouXiangHua/cxh.db new file mode 100644 index 00000000..6b8b75e5 Binary files /dev/null and b/data/ChouXiangHua/cxh.db differ diff --git a/main.go b/main.go index 55ca7fcc..aa5ca9b3 100644 --- a/main.go +++ b/main.go @@ -28,22 +28,23 @@ import ( // 娱乐类 // _ "github.com/FloatTech/ZeroBot-Plugin/plugin_wtf" // 鬼东西 - _ "github.com/FloatTech/ZeroBot-Plugin-Gif" // 制图 - _ "github.com/FloatTech/ZeroBot-Plugin/plugin_ai_false" // 服务器监控 - _ "github.com/FloatTech/ZeroBot-Plugin/plugin_book_review" // 哀伤雪刃吧推书记录 - _ "github.com/FloatTech/ZeroBot-Plugin/plugin_choose" // 选择困难症帮手 - _ "github.com/FloatTech/ZeroBot-Plugin/plugin_coser" // 三次元小姐姐 - _ "github.com/FloatTech/ZeroBot-Plugin/plugin_fortune" // 运势 - _ "github.com/FloatTech/ZeroBot-Plugin/plugin_funny" // 笑话 - _ "github.com/FloatTech/ZeroBot-Plugin/plugin_hs" // 炉石 - _ "github.com/FloatTech/ZeroBot-Plugin/plugin_minecraft" // MCSManager - _ "github.com/FloatTech/ZeroBot-Plugin/plugin_moyu" // 摸鱼 - _ "github.com/FloatTech/ZeroBot-Plugin/plugin_music" // 点歌 - _ "github.com/FloatTech/ZeroBot-Plugin/plugin_novel" // 铅笔小说网搜索 - _ "github.com/FloatTech/ZeroBot-Plugin/plugin_omikuji" // 浅草寺求签 - _ "github.com/FloatTech/ZeroBot-Plugin/plugin_reborn" // 投胎 - _ "github.com/FloatTech/ZeroBot-Plugin/plugin_shadiao" // 沙雕app - _ "github.com/FloatTech/ZeroBot-Plugin/plugin_shindan" // 测定 + _ "github.com/FloatTech/ZeroBot-Plugin-Gif" // 制图 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_ai_false" // 服务器监控 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_book_review" // 哀伤雪刃吧推书记录 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_choose" // 选择困难症帮手 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_chouxianghua" // 说抽象话 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_coser" // 三次元小姐姐 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_fortune" // 运势 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_funny" // 笑话 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_hs" // 炉石 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_minecraft" // MCSManager + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_moyu" // 摸鱼 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_music" // 点歌 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_novel" // 铅笔小说网搜索 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_omikuji" // 浅草寺求签 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_reborn" // 投胎 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_shadiao" // 沙雕app + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_shindan" // 测定 // b站相关 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_bilibili" // 查询b站用户信息 diff --git a/plugin_chouxianghua/chouxianghua.go b/plugin_chouxianghua/chouxianghua.go new file mode 100644 index 00000000..b5ea74bc --- /dev/null +++ b/plugin_chouxianghua/chouxianghua.go @@ -0,0 +1,41 @@ +package chouxianghua + +import ( + "github.com/FloatTech/ZeroBot-Plugin/control" + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/message" +) + +const ( + prio = 10 +) + +var ( + engine = control.Register("chouxianghua", &control.Options{ + DisableOnDefault: false, + Help: "抽象话\n- 抽象翻译\n", + }) +) + +func init() { + engine.OnRegex("^抽象翻译([\u4E00-\u9FA5A-Za-z0-9]{1,25})$").SetBlock(true).SetPriority(prio). + Handle(func(ctx *zero.Ctx) { + cxresult := chouXiang(ctx.State["regex_matched"].([]string)[1]) + ctx.SendChain(message.Text(cxresult)) + }) +} + +func chouXiang(s string) (cxresult string) { + h := []rune(s) + for i := 0; i < len(h); i++ { + if i < len(h)-1 && (getEmojiByPronunciation(getPronunciationByWord(string(h[i])).Pronunciation+getPronunciationByWord(string(h[i+1])).Pronunciation).Emoji != "") { + cxresult += getEmojiByPronunciation(getPronunciationByWord(string(h[i])).Pronunciation + getPronunciationByWord(string(h[i+1])).Pronunciation).Emoji + i++ + } else if getEmojiByPronunciation(getPronunciationByWord(string(h[i])).Pronunciation).Emoji != "" { + cxresult += getEmojiByPronunciation(getPronunciationByWord(string(h[i])).Pronunciation).Emoji + } else { + cxresult += string(h[i]) + } + } + return +} diff --git a/plugin_chouxianghua/data.go b/plugin_chouxianghua/data.go new file mode 100644 index 00000000..e75741b6 --- /dev/null +++ b/plugin_chouxianghua/data.go @@ -0,0 +1,35 @@ +package chouxianghua + +import ( + "github.com/FloatTech/ZeroBot-Plugin/utils/file" + "github.com/FloatTech/ZeroBot-Plugin/utils/process" + "github.com/FloatTech/ZeroBot-Plugin/utils/sql" + log "github.com/sirupsen/logrus" + "os" +) + +const ( + dbpath = "data/ChouXiangHua/" + dbfile = dbpath + "cxh.db" +) + +var db = &sql.Sqlite{DBPath: dbfile} + +// 加载数据库 +func init() { + go func() { + process.SleepAbout1sTo2s() + // os.RemoveAll(dbpath) + _ = os.MkdirAll(dbpath, 0755) + _, _ = file.GetLazyData(dbfile, false, true) + err := db.Create("pinyin", &Pinyin{}) + if err != nil { + panic(err) + } + n, err := db.Count("pinyin") + if err != nil { + panic(err) + } + log.Printf("[chouxianghua]读取%d条拼音", n) + }() +} diff --git a/plugin_chouxianghua/model.go b/plugin_chouxianghua/model.go new file mode 100644 index 00000000..4ef682ea --- /dev/null +++ b/plugin_chouxianghua/model.go @@ -0,0 +1,20 @@ +package chouxianghua + +type Pinyin struct { + Word string `db:"word"` + Pronunciation string `db:"pronunciation"` +} +type Emoji struct { + Pronunciation string `db:"pronunciation"` + Emoji string `db:"emoji"` +} + +func getPronunciationByWord(word string) (p Pinyin) { + db.Find("pinyin", &p, "where word = '"+word+"'") + return +} + +func getEmojiByPronunciation(pronunciation string) (e Emoji) { + db.Find("emoji", &e, "where pronunciation = '"+pronunciation+"'") + return +} diff --git a/plugin_shadiao/zuan.go b/plugin_shadiao/zuan.go index 28ee3f5e..a706f461 100644 --- a/plugin_shadiao/zuan.go +++ b/plugin_shadiao/zuan.go @@ -1,7 +1,7 @@ package shadiao +/* func init() { - /* engine.OnFullMatch("骂我").SetBlock(true).SetPriority(prio).Handle(func(ctx *zero.Ctx) { if !limit.Load(ctx.Event.GroupID).Acquire() { return @@ -25,5 +25,5 @@ func init() { } ctx.SendChain(message.At(math.Str2Int64(ctx.State["regex_matched"].([]string)[1])), message.Text(helper.BytesToString(data))) }) - */ } +*/