refactor: 重构消息发送模型
This commit is contained in:
15
model/action.go
Normal file
15
model/action.go
Normal 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,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user