51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package handler
|
||
|
||
import (
|
||
"fmt"
|
||
"github.com/lonelyevil/kook"
|
||
"regexp"
|
||
)
|
||
|
||
// KMarkdownHandler
|
||
// @description:
|
||
func KMarkdownHandler(ctx *kook.KmarkdownMessageContext) {
|
||
if ctx.Common.Type != kook.MessageTypeKMarkdown || ctx.Extra.Author.Bot {
|
||
return
|
||
}
|
||
|
||
pattern := `\(met\)[^()]*\(met\) `
|
||
re := regexp.MustCompile(pattern)
|
||
content := re.ReplaceAllString(ctx.Common.Content, "")
|
||
fmt.Printf("收到新消息: %s(%s) -> %s\n", ctx.Extra.Author.Username, ctx.Extra.Author.Nickname, content)
|
||
|
||
// 判断是否为at机器人,不是的话就不处理
|
||
isAt := false
|
||
for _, part := range ctx.Extra.Kmarkdown.MentionPart {
|
||
if part.ID == "2259002513" {
|
||
isAt = true
|
||
break
|
||
}
|
||
}
|
||
if !isAt {
|
||
return
|
||
}
|
||
|
||
reply := "机器人功能开发中~"
|
||
if content == "ping" {
|
||
reply = "pong"
|
||
}
|
||
|
||
resp, err := ctx.Session.MessageCreate(&kook.MessageCreate{
|
||
MessageCreateBase: kook.MessageCreateBase{
|
||
TargetID: ctx.Common.TargetID,
|
||
Content: reply,
|
||
Quote: ctx.Common.MsgID,
|
||
Type: kook.MessageTypeKMarkdown,
|
||
},
|
||
})
|
||
if err != nil {
|
||
fmt.Printf("消息回复失败: %v", err)
|
||
fmt.Printf("接口返回信息: %+v", resp)
|
||
}
|
||
}
|