game-db-robot/handler/kmarkdown.go

51 lines
1.1 KiB
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 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)
}
}