refactor: 重构 GetLoginAccountInfo 函数,移除 actionManager 依赖,并更新相关调用;修改 sendAlertMessage 函数为发送合并转发

This commit is contained in:
lixiangwuxian
2025-04-12 01:13:22 +08:00
parent 8af78f8422
commit 46a82e1fef
6 changed files with 45 additions and 78 deletions

View File

@@ -9,7 +9,7 @@ import (
// CQMessage 接口定义了所有 CQ 消息必须实现的方法
type CQMessage interface {
ToCQString() string
ParseMessage(data string) error
// ParseMessage(data string) error
}
// RawMessage 用于初始解析 JSON 的通用结构

View File

@@ -78,23 +78,9 @@ func (msg *NodeMessage) ToCQString() string {
return fmt.Sprintf("[CQ:node,user_id=%s,nickname=%s]", msg.Data.UserID, msg.Data.Nickname)
}
func (msg *NodeMessage) ParseMessage(data string) error {
// 解析已有消息节点
idRe := regexp.MustCompile(`\[CQ:node,id=(.*?)\]`)
matches := idRe.FindStringSubmatch(data)
if len(matches) == 2 {
msg.Data.ID = matches[1]
return nil
}
// 解析自定义消息节点
customRe := regexp.MustCompile(`\[CQ:node,user_id=(.*?),nickname=(.*?)\]`)
matches = customRe.FindStringSubmatch(data)
if len(matches) == 3 {
msg.Data.UserID = matches[1]
msg.Data.Nickname = matches[2]
return nil
}
return fmt.Errorf("转发消息节点格式不正确")
func (msg *NodeMessage) ParseMessage(userId string, nickname string, content []any) *NodeMessage {
msg.Data.UserID = userId
msg.Data.Nickname = nickname
msg.Data.Content = content
return msg
}

View File

@@ -32,7 +32,7 @@ func (msg *TextMessage) ToCQString() string {
return msg.Data.Text
}
func (msg *TextMessage) ParseMessage(data string) error {
func (msg *TextMessage) ParseMessage(data string) *TextMessage {
msg.Data.Text = data
return nil
return msg
}