game-db-robot/handler/kmarkdown.go

51 lines
1.1 KiB
Go
Raw Normal View History

2023-04-17 08:27:26 +08:00
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)
}
}