fix: 修复权限系统qq提取问题,新增权限问题
This commit is contained in:
@@ -19,6 +19,27 @@ type AtData struct {
|
||||
QQ string `json:"qq"`
|
||||
}
|
||||
|
||||
func (msg *AtMessage) ToCQString() string {
|
||||
return fmt.Sprintf(`\[CQ:at,qq=%s\]`, msg.Data.QQ)
|
||||
}
|
||||
|
||||
func ParseAtMessage(data string) (*AtMessage, error) {
|
||||
// 使用正则表达式提取QQ号
|
||||
re := regexp.MustCompile(`\[CQ:at,qq=(\d+)\]`)
|
||||
matches := re.FindStringSubmatch(data)
|
||||
if len(matches) < 2 {
|
||||
return nil, fmt.Errorf("数据格式不正确")
|
||||
}
|
||||
|
||||
// 返回解析后的结构体
|
||||
return &AtMessage{
|
||||
Type: "at",
|
||||
Data: AtData{
|
||||
QQ: matches[1],
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// 回复消息结构体
|
||||
type ReplyMessage struct {
|
||||
Type string `json:"type"`
|
||||
@@ -30,7 +51,12 @@ type ReplyData struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
type CQImageMessage struct {
|
||||
type ImageMessage struct {
|
||||
Type string `json:"type"`
|
||||
Data ImageMessageData `json:"data"`
|
||||
}
|
||||
|
||||
type ImageMessageData struct {
|
||||
File string
|
||||
SubType string
|
||||
FileID string
|
||||
@@ -39,20 +65,20 @@ type CQImageMessage struct {
|
||||
FileUnique string
|
||||
}
|
||||
|
||||
func (msg *CQImageMessage) ToCQString() (string, error) {
|
||||
func (msg *ImageMessage) ToCQString() (string, error) {
|
||||
// URL 转义
|
||||
escapedURL := url.QueryEscape(msg.URL)
|
||||
escapedURL := url.QueryEscape(msg.Data.URL)
|
||||
|
||||
// 构造 CQ:image 字符串
|
||||
cqString := fmt.Sprintf("[CQ:image,file=%s,sub_type=%s,file_id=%s,url=%s,file_size=%d,file_unique=%s]",
|
||||
msg.File, msg.SubType, msg.FileID, escapedURL, msg.FileSize, msg.FileUnique)
|
||||
msg.Data.File, msg.Data.SubType, msg.Data.FileID, escapedURL, msg.Data.FileSize, msg.Data.FileUnique)
|
||||
|
||||
return cqString, nil
|
||||
}
|
||||
|
||||
func ParseCQImageMessage(data string) (*CQImageMessage, error) {
|
||||
func ParseCQImageMessage(data string) (*ImageMessage, error) {
|
||||
// 使用正则表达式提取各个字段
|
||||
re := regexp.MustCompile(`CQ:image,file=(.*?),sub_type=(.*?),file_id=(.*?),url=(.*?),file_size=(\d+),file_unique=(.*?)\]`)
|
||||
re := regexp.MustCompile(`\[CQ:image,file=(.*?),sub_type=(.*?),file_id=(.*?),url=(.*?),file_size=(\d+),file_unique=(.*?)\]`)
|
||||
matches := re.FindStringSubmatch(data)
|
||||
if len(matches) < 7 {
|
||||
return nil, fmt.Errorf("数据格式不正确")
|
||||
@@ -76,12 +102,23 @@ func ParseCQImageMessage(data string) (*CQImageMessage, error) {
|
||||
}
|
||||
|
||||
// 返回解析后的结构体
|
||||
return &CQImageMessage{
|
||||
File: matches[1],
|
||||
SubType: matches[2],
|
||||
FileID: matches[3],
|
||||
URL: decodedURL,
|
||||
FileSize: fileSize,
|
||||
FileUnique: matches[6],
|
||||
// return &ImageMessageData{
|
||||
// File: matches[1],
|
||||
// SubType: matches[2],
|
||||
// FileID: matches[3],
|
||||
// URL: decodedURL,
|
||||
// FileSize: fileSize,
|
||||
// FileUnique: matches[6],
|
||||
// }, nil
|
||||
return &ImageMessage{
|
||||
Type: "image",
|
||||
Data: ImageMessageData{
|
||||
File: matches[1],
|
||||
SubType: matches[2],
|
||||
FileID: matches[3],
|
||||
URL: decodedURL,
|
||||
FileSize: fileSize,
|
||||
FileUnique: matches[6],
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user