解决冲突
This commit is contained in:
parent
76679696f9
commit
a1e5433af6
1 changed files with 34 additions and 55 deletions
|
|
@ -56,7 +56,6 @@ const (
|
||||||
var emojiRegexp = regexp.MustCompile(`<[^<]*?ext="([^"]+)"[^<]*?faceType=(\d+)[^<]*?>|<[^<]*?faceType=(\d+)[^<]*?ext="([^"]+)"[^<]*?>`)
|
var emojiRegexp = regexp.MustCompile(`<[^<]*?ext="([^"]+)"[^<]*?faceType=(\d+)[^<]*?>|<[^<]*?faceType=(\d+)[^<]*?ext="([^"]+)"[^<]*?>`)
|
||||||
var extRegexp = regexp.MustCompile(`ext="([^"]+)"`)
|
var extRegexp = regexp.MustCompile(`ext="([^"]+)"`)
|
||||||
|
|
||||||
|
|
||||||
type qqAPI interface {
|
type qqAPI interface {
|
||||||
WS(ctx context.Context, params map[string]string, body string) (*dto.WebsocketAP, error)
|
WS(ctx context.Context, params map[string]string, body string) (*dto.WebsocketAP, error)
|
||||||
PostGroupMessage(
|
PostGroupMessage(
|
||||||
|
|
@ -71,7 +70,7 @@ type qqAPI interface {
|
||||||
type QQChannel struct {
|
type QQChannel struct {
|
||||||
*channels.BaseChannel
|
*channels.BaseChannel
|
||||||
config config.QQConfig
|
config config.QQConfig
|
||||||
api qqAPI
|
api qqAPI
|
||||||
tokenSource oauth2.TokenSource
|
tokenSource oauth2.TokenSource
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
|
|
@ -355,7 +354,7 @@ func (c *QQChannel) SendMedia(ctx context.Context, msg bus.OutboundMediaMessage)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *QQChannel) uploadMedia( ctx context.Context,
|
func (c *QQChannel) uploadMedia(ctx context.Context,
|
||||||
chatKind kindType, chatID string, part bus.MediaPart) ([]byte, error) {
|
chatKind kindType, chatID string, part bus.MediaPart) ([]byte, error) {
|
||||||
|
|
||||||
payload, err := c.buildMediaUpload(part)
|
payload, err := c.buildMediaUpload(part)
|
||||||
|
|
@ -500,8 +499,6 @@ func (c *QQChannel) outboundMediaType(part bus.MediaPart, localPath string) stri
|
||||||
return "audio"
|
return "audio"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Fix the sendUploadedMedia function syntax error
|
// Fix the sendUploadedMedia function syntax error
|
||||||
func (c *QQChannel) sendUploadedMedia(ctx context.Context, chatKind kindType, chatID string, part bus.MediaPart,
|
func (c *QQChannel) sendUploadedMedia(ctx context.Context, chatKind kindType, chatID string, part bus.MediaPart,
|
||||||
fileInfo []byte) error {
|
fileInfo []byte) error {
|
||||||
|
|
@ -515,7 +512,6 @@ func (c *QQChannel) sendUploadedMedia(ctx context.Context, chatKind kindType, ch
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.MsgID, msg.MsgSeq = c.getReplyExtInfo(ctx, chatID)
|
msg.MsgID, msg.MsgSeq = c.getReplyExtInfo(ctx, chatID)
|
||||||
|
|
||||||
if chatKind == kindGroup {
|
if chatKind == kindGroup {
|
||||||
if msg.Content != "" {
|
if msg.Content != "" {
|
||||||
msg.Content = sanitizeURLs(msg.Content)
|
msg.Content = sanitizeURLs(msg.Content)
|
||||||
|
|
@ -606,33 +602,30 @@ func (c *QQChannel) handleC2CMessage() event.C2CMessageEventHandler {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.InfoCF("qq", "Received C2C message", map[string]any{
|
logger.InfoCF("qq", "Received C2C message", map[string]any{
|
||||||
"sender": senderID,
|
"sender": senderID,
|
||||||
"length": len(content),
|
"length": len(content),
|
||||||
"media_count": len(mediaPaths),
|
"media_count": len(mediaPaths),
|
||||||
"sender": senderID,
|
|
||||||
"length": len(content),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Store chat routing context.
|
// Store chat routing context.
|
||||||
c.saveChatKind(senderID, kindDirect)
|
c.saveChatKind(senderID, kindDirect)
|
||||||
c.lastMsgID.Store(senderID, data.ID)
|
c.lastMsgID.Store(senderID, data.ID)
|
||||||
|
|
||||||
metadata := map[string]string{
|
metadata := map[string]string{
|
||||||
"account_id": senderID,
|
"account_id": senderID,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.HandleMessage(c.ctx,
|
|
||||||
bus.Peer{Kind: string(kindDirect), ID: senderID},
|
|
||||||
data.ID,
|
|
||||||
senderID,
|
|
||||||
senderID,
|
|
||||||
content,
|
|
||||||
mediaPaths,
|
|
||||||
metadata,
|
|
||||||
sender,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
c.HandleMessage(c.ctx,
|
||||||
|
bus.Peer{Kind: string(kindDirect), ID: senderID},
|
||||||
|
data.ID,
|
||||||
|
senderID,
|
||||||
|
senderID,
|
||||||
|
content,
|
||||||
|
mediaPaths,
|
||||||
|
metadata,
|
||||||
|
sender,
|
||||||
|
)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -658,19 +651,9 @@ func (c *QQChannel) handleGroupATMessage() event.GroupATMessageEventHandler {
|
||||||
Platform: "qq",
|
Platform: "qq",
|
||||||
PlatformID: data.Author.ID,
|
PlatformID: data.Author.ID,
|
||||||
CanonicalID: identity.BuildCanonicalID("qq", data.Author.ID),
|
CanonicalID: identity.BuildCanonicalID("qq", data.Author.ID),
|
||||||
|
Username: data.Author.Username,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.IsAllowedSender(sender) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
content := strings.TrimSpace(data.Content)
|
|
||||||
mediaPaths, attachmentNotes := c.extractInboundAttachments(data.GroupID, data.ID, data.Attachments)
|
|
||||||
for _, note := range attachmentNotes {
|
|
||||||
content = appendContent(content, note)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if !c.IsAllowedSender(sender) {
|
if !c.IsAllowedSender(sender) {
|
||||||
logger.Infof("qq", "Received group message from unauthorized sender", map[string]any{
|
logger.Infof("qq", "Received group message from unauthorized sender", map[string]any{
|
||||||
"sender": sender,
|
"sender": sender,
|
||||||
|
|
@ -680,7 +663,7 @@ func (c *QQChannel) handleGroupATMessage() event.GroupATMessageEventHandler {
|
||||||
|
|
||||||
scope := channels.BuildMediaScope("qq", data.GroupID, data.ID)
|
scope := channels.BuildMediaScope("qq", data.GroupID, data.ID)
|
||||||
|
|
||||||
content, mediaPaths = c.decodeMessage(context.Background(), event, (*dto.Message)(data), scope)
|
content, mediaPaths := c.decodeMessage(context.Background(), event, (*dto.Message)(data), scope)
|
||||||
if content == "" {
|
if content == "" {
|
||||||
logger.DebugC("qq", "Received empty group message, ignoring")
|
logger.DebugC("qq", "Received empty group message, ignoring")
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -712,23 +695,23 @@ func (c *QQChannel) handleGroupATMessage() event.GroupATMessageEventHandler {
|
||||||
"group_id": data.GroupID,
|
"group_id": data.GroupID,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.HandleMessage(c.ctx,
|
c.HandleMessage(c.ctx,
|
||||||
bus.Peer{Kind: string(kindGroup), ID: data.GroupID},
|
bus.Peer{Kind: string(kindGroup), ID: data.GroupID},
|
||||||
data.ID,
|
data.ID,
|
||||||
senderID,
|
senderID,
|
||||||
data.GroupID,
|
data.GroupID,
|
||||||
content,
|
content,
|
||||||
mediaPaths,
|
mediaPaths,
|
||||||
metadata,
|
metadata,
|
||||||
sender,
|
sender,
|
||||||
)
|
)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *QQChannel) extractInboundAttachments( chatID, messageID string,
|
func (c *QQChannel) extractInboundAttachments(chatID, messageID string,
|
||||||
attachments []*dto.MessageAttachment ) ([]string, []string) {
|
attachments []*dto.MessageAttachment) ([]string, []string) {
|
||||||
|
|
||||||
if len(attachments) == 0 {
|
if len(attachments) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
@ -1167,8 +1150,6 @@ func (c *QQChannel) processAttachments(ctx context.Context, attachments []Messag
|
||||||
return mediaPaths, content
|
return mediaPaths, content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// getAttachmentType determines the type of attachment (image, audio, video, file)
|
// getAttachmentType determines the type of attachment (image, audio, video, file)
|
||||||
func (c *QQChannel) getAttachmentType(attachment MessageAttachment) string {
|
func (c *QQChannel) getAttachmentType(attachment MessageAttachment) string {
|
||||||
if strings.HasPrefix(attachment.ContentType, "image") {
|
if strings.HasPrefix(attachment.ContentType, "image") {
|
||||||
|
|
@ -1237,8 +1218,6 @@ func sanitizeURLs(text string) string {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func getVoiceInfo(event *dto.WSPayload) (string, string) {
|
func getVoiceInfo(event *dto.WSPayload) (string, string) {
|
||||||
_raw, err := json.Marshal(event.Data)
|
_raw, err := json.Marshal(event.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue