refactor: 重构消息发送模型

This commit is contained in:
lixiangwuxian
2024-10-28 02:58:08 +08:00
parent fe863a9ac8
commit 7e28953a56
10 changed files with 196 additions and 16 deletions

15
model/action.go Normal file
View File

@@ -0,0 +1,15 @@
package model
type Action struct {
Action string `json:"action"`
Params map[string]interface{} `json:"params"`
}
func GenDrawbackPkg(msgId int32) Action {
return Action{
Action: "delete_msg",
Params: map[string]interface{}{
"message_id": msgId,
},
}
}

View File

@@ -48,7 +48,26 @@ type ReplyMessage struct {
// 回复消息数据结构体
type ReplyData struct {
ID string `json:"id"`
ID int `json:"id"`
}
func ParseReplyData(data string) (*ReplyMessage, error) {
// 使用正则表达式提取ID
re := regexp.MustCompile(`\[CQ:reply,id=(\d+)\]`)
matches := re.FindStringSubmatch(data)
if len(matches) < 2 {
return nil, fmt.Errorf("数据格式不正确")
}
id, _ := strconv.Atoi(matches[1])
// 返回解析后的结构体
return &ReplyMessage{
Type: "reply",
Data: ReplyData{
ID: id,
},
}, nil
}
type ImageMessage struct {