ZeroBot-Plugin/plugin_shadiao/yduanzi.go
github-actions[bot] 4147f1056a 🎨 改进代码样式
2021-12-24 04:33:46 +00:00

29 lines
757 B
Go

package shadiao
import (
"strings"
"github.com/tidwall/gjson"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
"github.com/wdvxdr1123/ZeroBot/utils/helper"
"github.com/FloatTech/ZeroBot-Plugin/utils/web"
)
func init() {
engine.OnFullMatch("讲个段子").SetBlock(true).SetPriority(prio).Handle(func(ctx *zero.Ctx) {
if !limit.Load(ctx.Event.GroupID).Acquire() {
return
}
data, err := web.ReqWith(yduanziURL, "POST", yduanziReferer, ua)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
text := gjson.Get(helper.BytesToString(data), "duanzi").String()
text = strings.Replace(text, "<br>", "\n", -1)
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(text))
})
}