ZeroBot-Plugin/plugin_chouxianghua/chouxianghua.go
himawari 96802efa45
增加绝绝子和藏头诗 (#93)
* feat:添加绝绝子和藏头诗

* fix:去除日志

* fix:修一下help,replace,命名
2021-12-26 15:17:11 +08:00

43 lines
931 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}