mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-01-02 00:09:07 +08:00
43 lines
931 B
Go
43 lines
931 B
Go
package chouxianghua
|
||
|
||
import (
|
||
zero "github.com/wdvxdr1123/ZeroBot"
|
||
"github.com/wdvxdr1123/ZeroBot/message"
|
||
|
||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||
)
|
||
|
||
const prio = 10
|
||
|
||
func init() {
|
||
control.Register("chouxianghua", &control.Options{
|
||
DisableOnDefault: false,
|
||
Help: "抽象话\n- 抽象翻译xxx\n",
|
||
}).OnRegex("^抽象翻译((\\s|[\\r\\n]|[\u4E00-\u9FA5A-Za-z0-9“”,;、。《》=?\\x22])+)$").SetBlock(true).SetPriority(prio).
|
||
Handle(func(ctx *zero.Ctx) {
|
||
r := cx(ctx.State["regex_matched"].([]string)[1])
|
||
ctx.SendChain(message.Text(r))
|
||
})
|
||
}
|
||
|
||
func cx(s string) (r string) {
|
||
h := []rune(s)
|
||
for i := 0; i < len(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
|
||
}
|