make lint happy

This commit is contained in:
fumiama
2021-12-25 13:01:05 +08:00
parent 59fe8a021f
commit eebfa23509
11 changed files with 90 additions and 77 deletions

View File

@@ -7,36 +7,36 @@ import (
"github.com/FloatTech/ZeroBot-Plugin/control"
)
const (
prio = 10
)
var (
engine = control.Register("chouxianghua", &control.Options{
DisableOnDefault: false,
Help: "抽象话\n- 抽象翻译\n",
})
)
const prio = 10
func init() {
engine.OnRegex("^抽象翻译([\u4E00-\u9FA5A-Za-z0-9]{1,25})$").SetBlock(true).SetPriority(prio).
control.Register("chouxianghua", &control.Options{
DisableOnDefault: false,
Help: "抽象话\n- 抽象翻译xxx\n",
}).OnRegex("^抽象翻译([\u4E00-\u9FA5A-Za-z0-9]+)$").SetBlock(true).SetPriority(prio).
Handle(func(ctx *zero.Ctx) {
cxresult := chouXiang(ctx.State["regex_matched"].([]string)[1])
ctx.SendChain(message.Text(cxresult))
r := cx(ctx.State["regex_matched"].([]string)[1])
ctx.SendChain(message.Text(r))
})
}
func chouXiang(s string) (cxresult string) {
func cx(s string) (r 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])
if i < len(h)-1 {
e := getEmojiByPronun(getPronunByDWord(h[i], h[i+1]))
if e != "" {
r += e
i++
continue
}
}
e := getEmojiByPronun(getPinyinByWord(string(h[i])))
if e != "" {
r += e
continue
}
r += string(h[i])
}
return
}

View File

@@ -24,7 +24,7 @@ func init() {
// os.RemoveAll(dbpath)
_ = os.MkdirAll(dbpath, 0755)
_, _ = file.GetLazyData(dbfile, false, true)
err := db.Create("pinyin", &Pinyin{})
err := db.Create("pinyin", &pinyin{})
if err != nil {
panic(err)
}

View File

@@ -1,20 +1,26 @@
package chouxianghua
type Pinyin struct {
Word string `db:"word"`
Pronunciation string `db:"pronunciation"`
type pinyin struct {
Word string `db:"word"`
Pronun string `db:"pronunciation"`
}
type Emoji struct {
Pronunciation string `db:"pronunciation"`
Emoji string `db:"emoji"`
type emoji struct {
Pronun string `db:"pronunciation"`
Emoji string `db:"emoji"`
}
func getPronunciationByWord(word string) (p Pinyin) {
func getPinyinByWord(word string) string {
var p pinyin
db.Find("pinyin", &p, "where word = '"+word+"'")
return
return p.Pronun
}
func getEmojiByPronunciation(pronunciation string) (e Emoji) {
db.Find("emoji", &e, "where pronunciation = '"+pronunciation+"'")
return
func getPronunByDWord(w0, w1 rune) string {
return getPinyinByWord(string(w0)) + getPinyinByWord(string(w1))
}
func getEmojiByPronun(pronun string) string {
var e emoji
db.Find("emoji", &e, "where pronunciation = '"+pronun+"'")
return e.Emoji
}