Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

回复群中的回复消息时,会多出一个@xxx #329

Open
icey-yu opened this issue Mar 24, 2023 · 0 comments
Open

回复群中的回复消息时,会多出一个@xxx #329

icey-yu opened this issue Mar 24, 2023 · 0 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@icey-yu
Copy link

icey-yu commented Mar 24, 2023

Mirai版本:v0.0.0-20230315231550-b461f356a30a
运行环境:win64
使用协议:AndroidPad
重现步骤:使用message.NewReply(groupMessage)方法回复一个群里的回复消息
代码:

sendingMessage := message.NewSendingMessage()
reply := message.NewReply(groupMessage)  // 从事件中获取而来
msgStr := message.NewText("测试")
sendingMessage.Elements = append(sendingMessage.Elements, msgStr, reply)
bot.SendGroupMessage(groupCode, sendingMessage)  // bot为机器人client对象

结果:
A5$0F)DUMILNLGOYQY(XOIT

其他说明:
原因是群聊的回复消息是At+Text+Reply组成的,是否在框架的NewReply中将其处理掉比较好?
image

以下是我目前用的解决该问题的代码:

func removeReplyAt(messages []message.IMessageElement) []message.IMessageElement {
	for index, msg := range messages {
		if msg.Type() == message.Reply {
			if index < 2 { // 由qq群聊发送的reply消息,reply是第三个元素。
				return messages
			}
			if messages[index-1].Type() == message.Text && messages[index-2].Type() == message.At {
				// 当reply的前两个元素分别人At和内容为" "的text元素时,进行移除
				textMsg := messages[index-1].(*message.TextElement)
				if textMsg.Content == " " {
					if index == 2 {
						return append(messages[2:])
					}
					return append(messages[:index-3], messages[index:]...)
				}
			}
		}
	}
	return messages
}
@fumiama fumiama added bug Something isn't working help wanted Extra attention is needed labels May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants