修复图片、视频、文件消息不能撤回的bug 🐛
This commit is contained in:
parent
6484a80b37
commit
b5832e624d
26
message.go
26
message.go
@ -135,43 +135,37 @@ func (m *Message) IsSendByGroup() bool {
|
|||||||
return strings.HasPrefix(m.FromUserName, "@@")
|
return strings.HasPrefix(m.FromUserName, "@@")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reply 回复消息
|
// ReplyText 回复文本消息
|
||||||
func (m *Message) Reply(msgType MessageType, content, mediaId string) (*SentMessage, error) {
|
func (m *Message) ReplyText(content string) (*SentMessage, error) {
|
||||||
msg := NewSendMessage(msgType, content, m.Bot.self.User.UserName, m.FromUserName, mediaId)
|
msg := NewSendMessage(MsgTypeText, content, m.Bot.self.User.UserName, m.FromUserName, "")
|
||||||
info := m.Bot.Storage.LoginInfo
|
info := m.Bot.Storage.LoginInfo
|
||||||
request := m.Bot.Storage.Request
|
request := m.Bot.Storage.Request
|
||||||
sentMessage, err := m.Bot.Caller.WebWxSendMsg(msg, info, request)
|
sentMessage, err := m.Bot.Caller.WebWxSendMsg(msg, info, request)
|
||||||
if err != nil {
|
return m.Bot.self.sendMessageWrapper(sentMessage, err)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
sentMessage.Self = m.Bot.self
|
|
||||||
return sentMessage, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReplyText 回复文本消息
|
|
||||||
func (m *Message) ReplyText(content string) (*SentMessage, error) {
|
|
||||||
return m.Reply(MsgTypeText, content, "")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReplyImage 回复图片消息
|
// ReplyImage 回复图片消息
|
||||||
func (m *Message) ReplyImage(file *os.File) (*SentMessage, error) {
|
func (m *Message) ReplyImage(file *os.File) (*SentMessage, error) {
|
||||||
info := m.Bot.Storage.LoginInfo
|
info := m.Bot.Storage.LoginInfo
|
||||||
request := m.Bot.Storage.Request
|
request := m.Bot.Storage.Request
|
||||||
return m.Bot.Caller.WebWxSendImageMsg(file, request, info, m.Bot.self.UserName, m.FromUserName)
|
sentMessage, err := m.Bot.Caller.WebWxSendImageMsg(file, request, info, m.Bot.self.UserName, m.FromUserName)
|
||||||
|
return m.Bot.self.sendMessageWrapper(sentMessage, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReplyVideo 回复视频消息
|
// ReplyVideo 回复视频消息
|
||||||
func (m *Message) ReplyVideo(file *os.File) (*SentMessage, error) {
|
func (m *Message) ReplyVideo(file *os.File) (*SentMessage, error) {
|
||||||
info := m.Bot.Storage.LoginInfo
|
info := m.Bot.Storage.LoginInfo
|
||||||
request := m.Bot.Storage.Request
|
request := m.Bot.Storage.Request
|
||||||
return m.Bot.Caller.WebWxSendVideoMsg(file, request, info, m.Bot.self.UserName, m.FromUserName)
|
sentMessage, err := m.Bot.Caller.WebWxSendVideoMsg(file, request, info, m.Bot.self.UserName, m.FromUserName)
|
||||||
|
return m.Bot.self.sendMessageWrapper(sentMessage, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReplyFile 回复文件消息
|
// ReplyFile 回复文件消息
|
||||||
func (m *Message) ReplyFile(file *os.File) (*SentMessage, error) {
|
func (m *Message) ReplyFile(file *os.File) (*SentMessage, error) {
|
||||||
info := m.Bot.Storage.LoginInfo
|
info := m.Bot.Storage.LoginInfo
|
||||||
request := m.Bot.Storage.Request
|
request := m.Bot.Storage.Request
|
||||||
return m.Bot.Caller.WebWxSendFile(file, request, info, m.Bot.self.UserName, m.FromUserName)
|
sentMessage, err := m.Bot.Caller.WebWxSendFile(file, request, info, m.Bot.self.UserName, m.FromUserName)
|
||||||
|
return m.Bot.self.sendMessageWrapper(sentMessage, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Message) IsText() bool {
|
func (m *Message) IsText() bool {
|
||||||
|
54
relations.go
54
relations.go
@ -18,11 +18,6 @@ func (f *Friend) SetRemarkName(name string) error {
|
|||||||
return f.Self.SetRemarkNameToFriend(f, name)
|
return f.Self.SetRemarkNameToFriend(f, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendMsg 发送自定义消息
|
|
||||||
func (f *Friend) SendMsg(msg *SendMessage) (*SentMessage, error) {
|
|
||||||
return f.Self.SendMessageToFriend(f, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendText 发送文本消息
|
// SendText 发送文本消息
|
||||||
func (f *Friend) SendText(content string) (*SentMessage, error) {
|
func (f *Friend) SendText(content string) (*SentMessage, error) {
|
||||||
return f.Self.SendTextToFriend(f, content)
|
return f.Self.SendTextToFriend(f, content)
|
||||||
@ -111,28 +106,6 @@ func (f Friends) Search(limit int, condFuncList ...func(friend *Friend) bool) (r
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendMsg 向slice的好友依次发送消息
|
|
||||||
func (f Friends) SendMsg(msg *SendMessage, delay ...time.Duration) error {
|
|
||||||
total := getTotalDuration(delay...)
|
|
||||||
var (
|
|
||||||
sentMessage *SentMessage
|
|
||||||
err error
|
|
||||||
self *Self
|
|
||||||
)
|
|
||||||
for _, friend := range f {
|
|
||||||
self = friend.Self
|
|
||||||
time.Sleep(total)
|
|
||||||
if sentMessage != nil {
|
|
||||||
err = self.ForwardMessageToFriends(sentMessage, f...)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if sentMessage, err = friend.SendMsg(msg); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendText 向slice的好友依次发送文本消息
|
// SendText 向slice的好友依次发送文本消息
|
||||||
func (f Friends) SendText(text string, delay ...time.Duration) error {
|
func (f Friends) SendText(text string, delay ...time.Duration) error {
|
||||||
total := getTotalDuration(delay...)
|
total := getTotalDuration(delay...)
|
||||||
@ -206,11 +179,6 @@ func (g Group) String() string {
|
|||||||
return fmt.Sprintf("<Group:%s>", g.NickName)
|
return fmt.Sprintf("<Group:%s>", g.NickName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendMsg 发行消息给当前的群组
|
|
||||||
func (g *Group) SendMsg(msg *SendMessage) (*SentMessage, error) {
|
|
||||||
return g.Self.SendMessageToGroup(g, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendText 发行文本消息给当前的群组
|
// SendText 发行文本消息给当前的群组
|
||||||
func (g *Group) SendText(content string) (*SentMessage, error) {
|
func (g *Group) SendText(content string) (*SentMessage, error) {
|
||||||
return g.Self.SendTextToGroup(g, content)
|
return g.Self.SendTextToGroup(g, content)
|
||||||
@ -280,28 +248,6 @@ func (g Groups) Last() *Group {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendMsg 向群组依次发送消息, 支持发送延迟
|
|
||||||
func (g Groups) SendMsg(msg *SendMessage, delay ...time.Duration) error {
|
|
||||||
total := getTotalDuration(delay...)
|
|
||||||
var (
|
|
||||||
sentMessage *SentMessage
|
|
||||||
err error
|
|
||||||
self *Self
|
|
||||||
)
|
|
||||||
for _, group := range g {
|
|
||||||
self = group.Self
|
|
||||||
time.Sleep(total)
|
|
||||||
if sentMessage != nil {
|
|
||||||
err = self.ForwardMessageToGroups(sentMessage, g...)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if sentMessage, err = group.SendMsg(msg); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendText 向群组依次发送文本消息, 支持发送延迟
|
// SendText 向群组依次发送文本消息, 支持发送延迟
|
||||||
func (g Groups) SendText(text string, delay ...time.Duration) error {
|
func (g Groups) SendText(text string, delay ...time.Duration) error {
|
||||||
total := getTotalDuration(delay...)
|
total := getTotalDuration(delay...)
|
||||||
|
98
user.go
98
user.go
@ -248,50 +248,55 @@ func (s *Self) UpdateMembersDetail() error {
|
|||||||
return members.detail(s)
|
return members.detail(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 抽象发送消息接口
|
func (s *Self) sendTextToUser(user *User, text string) (*SentMessage, error) {
|
||||||
func (s *Self) sendMessageToUser(user *User, msg *SendMessage) (*SentMessage, error) {
|
msg := NewTextSendMessage(text, s.UserName, user.UserName)
|
||||||
msg.FromUserName = s.UserName
|
msg.FromUserName = s.UserName
|
||||||
msg.ToUserName = user.UserName
|
msg.ToUserName = user.UserName
|
||||||
info := s.Bot.Storage.LoginInfo
|
info := s.Bot.Storage.LoginInfo
|
||||||
request := s.Bot.Storage.Request
|
request := s.Bot.Storage.Request
|
||||||
successSendMessage, err := s.Bot.Caller.WebWxSendMsg(msg, info, request)
|
sentMessage, err := s.Bot.Caller.WebWxSendMsg(msg, info, request)
|
||||||
if err != nil {
|
return s.sendMessageWrapper(sentMessage, err)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
successSendMessage.Self = s
|
|
||||||
return successSendMessage, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendMessageToFriend 发送消息给好友
|
func (s *Self) sendImageToUser(user *User, file *os.File) (*SentMessage, error) {
|
||||||
func (s *Self) SendMessageToFriend(friend *Friend, msg *SendMessage) (*SentMessage, error) {
|
req := s.Bot.Storage.Request
|
||||||
return s.sendMessageToUser(friend.User, msg)
|
info := s.Bot.Storage.LoginInfo
|
||||||
|
sentMessage, err := s.Bot.Caller.WebWxSendImageMsg(file, req, info, s.UserName, user.UserName)
|
||||||
|
return s.sendMessageWrapper(sentMessage, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Self) sendVideoToUser(user *User, file *os.File) (*SentMessage, error) {
|
||||||
|
req := s.Bot.Storage.Request
|
||||||
|
info := s.Bot.Storage.LoginInfo
|
||||||
|
sentMessage, err := s.Bot.Caller.WebWxSendVideoMsg(file, req, info, s.UserName, user.UserName)
|
||||||
|
return s.sendMessageWrapper(sentMessage, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Self) sendFileToUser(user *User, file *os.File) (*SentMessage, error) {
|
||||||
|
req := s.Bot.Storage.Request
|
||||||
|
info := s.Bot.Storage.LoginInfo
|
||||||
|
sentMessage, err := s.Bot.Caller.WebWxSendFile(file, req, info, s.UserName, user.UserName)
|
||||||
|
return s.sendMessageWrapper(sentMessage, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendTextToFriend 发送文本消息给好友
|
// SendTextToFriend 发送文本消息给好友
|
||||||
func (s *Self) SendTextToFriend(friend *Friend, text string) (*SentMessage, error) {
|
func (s *Self) SendTextToFriend(friend *Friend, text string) (*SentMessage, error) {
|
||||||
msg := NewTextSendMessage(text, s.UserName, friend.UserName)
|
return s.sendTextToUser(friend.User, text)
|
||||||
return s.SendMessageToFriend(friend, msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendImageToFriend 发送图片消息给好友
|
// SendImageToFriend 发送图片消息给好友
|
||||||
func (s *Self) SendImageToFriend(friend *Friend, file *os.File) (*SentMessage, error) {
|
func (s *Self) SendImageToFriend(friend *Friend, file *os.File) (*SentMessage, error) {
|
||||||
req := s.Bot.Storage.Request
|
return s.sendImageToUser(friend.User, file)
|
||||||
info := s.Bot.Storage.LoginInfo
|
|
||||||
return s.Bot.Caller.WebWxSendImageMsg(file, req, info, s.UserName, friend.UserName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendVideoToFriend 发送视频给好友
|
// SendVideoToFriend 发送视频给好友
|
||||||
func (s *Self) SendVideoToFriend(friend *Friend, file *os.File) (*SentMessage, error) {
|
func (s *Self) SendVideoToFriend(friend *Friend, file *os.File) (*SentMessage, error) {
|
||||||
req := s.Bot.Storage.Request
|
return s.sendVideoToUser(friend.User, file)
|
||||||
info := s.Bot.Storage.LoginInfo
|
|
||||||
return s.Bot.Caller.WebWxSendVideoMsg(file, req, info, s.UserName, friend.UserName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendFileToFriend 发送文件给好友
|
// SendFileToFriend 发送文件给好友
|
||||||
func (s *Self) SendFileToFriend(friend *Friend, file *os.File) (*SentMessage, error) {
|
func (s *Self) SendFileToFriend(friend *Friend, file *os.File) (*SentMessage, error) {
|
||||||
req := s.Bot.Storage.Request
|
return s.sendFileToUser(friend.User, file)
|
||||||
info := s.Bot.Storage.LoginInfo
|
|
||||||
return s.Bot.Caller.WebWxSendFile(file, req, info, s.UserName, friend.UserName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetRemarkNameToFriend 设置好友备注
|
// SetRemarkNameToFriend 设置好友备注
|
||||||
@ -392,36 +397,24 @@ func (s *Self) RenameGroup(group *Group, newName string) error {
|
|||||||
return s.Bot.Caller.WebWxRenameChatRoom(req, info, newName, group)
|
return s.Bot.Caller.WebWxRenameChatRoom(req, info, newName, group)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendMessageToGroup 发送消息给群组
|
|
||||||
func (s *Self) SendMessageToGroup(group *Group, msg *SendMessage) (*SentMessage, error) {
|
|
||||||
return s.sendMessageToUser(group.User, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendTextToGroup 发送文本消息给群组
|
// SendTextToGroup 发送文本消息给群组
|
||||||
func (s *Self) SendTextToGroup(group *Group, text string) (*SentMessage, error) {
|
func (s *Self) SendTextToGroup(group *Group, text string) (*SentMessage, error) {
|
||||||
msg := NewTextSendMessage(text, s.UserName, group.UserName)
|
return s.sendTextToUser(group.User, text)
|
||||||
return s.SendMessageToGroup(group, msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendImageToGroup 发送图片消息给群组
|
// SendImageToGroup 发送图片消息给群组
|
||||||
func (s *Self) SendImageToGroup(group *Group, file *os.File) (*SentMessage, error) {
|
func (s *Self) SendImageToGroup(group *Group, file *os.File) (*SentMessage, error) {
|
||||||
req := s.Bot.Storage.Request
|
return s.sendImageToUser(group.User, file)
|
||||||
info := s.Bot.Storage.LoginInfo
|
|
||||||
return s.Bot.Caller.WebWxSendImageMsg(file, req, info, s.UserName, group.UserName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendVideoToGroup 发送视频给群组
|
// SendVideoToGroup 发送视频给群组
|
||||||
func (s *Self) SendVideoToGroup(group *Group, file *os.File) (*SentMessage, error) {
|
func (s *Self) SendVideoToGroup(group *Group, file *os.File) (*SentMessage, error) {
|
||||||
req := s.Bot.Storage.Request
|
return s.sendVideoToUser(group.User, file)
|
||||||
info := s.Bot.Storage.LoginInfo
|
|
||||||
return s.Bot.Caller.WebWxSendVideoMsg(file, req, info, s.UserName, group.UserName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendFileToGroup 发送文件给群组
|
// SendFileToGroup 发送文件给群组
|
||||||
func (s *Self) SendFileToGroup(group *Group, file *os.File) (*SentMessage, error) {
|
func (s *Self) SendFileToGroup(group *Group, file *os.File) (*SentMessage, error) {
|
||||||
req := s.Bot.Storage.Request
|
return s.sendFileToUser(group.User, file)
|
||||||
info := s.Bot.Storage.LoginInfo
|
|
||||||
return s.Bot.Caller.WebWxSendFile(file, req, info, s.UserName, group.UserName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RevokeMessage 撤回消息
|
// RevokeMessage 撤回消息
|
||||||
@ -668,27 +661,30 @@ func NewFriendHelper(self *Self) *Friend {
|
|||||||
return &Friend{&User{UserName: "filehelper", Self: self}}
|
return &Friend{&User{UserName: "filehelper", Self: self}}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendMessageToMp 发送消息给公众号
|
|
||||||
func (s *Self) SendMessageToMp(mp *Mp, msg *SendMessage) (*SentMessage, error) {
|
|
||||||
return s.sendMessageToUser(mp.User, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendTextToMp 发送文本消息给公众号
|
// SendTextToMp 发送文本消息给公众号
|
||||||
func (s *Self) SendTextToMp(mp *Mp, text string) (*SentMessage, error) {
|
func (s *Self) SendTextToMp(mp *Mp, text string) (*SentMessage, error) {
|
||||||
msg := NewTextSendMessage(text, s.UserName, mp.UserName)
|
return s.sendTextToUser(mp.User, text)
|
||||||
return s.SendMessageToMp(mp, msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendImageToMp 发送图片消息给公众号
|
// SendImageToMp 发送图片消息给公众号
|
||||||
func (s *Self) SendImageToMp(mp *Mp, file *os.File) (*SentMessage, error) {
|
func (s *Self) SendImageToMp(mp *Mp, file *os.File) (*SentMessage, error) {
|
||||||
req := s.Bot.Storage.Request
|
return s.sendImageToUser(mp.User, file)
|
||||||
info := s.Bot.Storage.LoginInfo
|
|
||||||
return s.Bot.Caller.WebWxSendImageMsg(file, req, info, s.UserName, mp.UserName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendFileToMp 发送文件给公众号
|
// SendFileToMp 发送文件给公众号
|
||||||
func (s *Self) SendFileToMp(mp *Mp, file *os.File) (*SentMessage, error) {
|
func (s *Self) SendFileToMp(mp *Mp, file *os.File) (*SentMessage, error) {
|
||||||
req := s.Bot.Storage.Request
|
return s.sendFileToUser(mp.User, file)
|
||||||
info := s.Bot.Storage.LoginInfo
|
}
|
||||||
return s.Bot.Caller.WebWxSendFile(file, req, info, s.UserName, mp.UserName)
|
|
||||||
|
// SendVideoToMp 发送视频消息给公众号
|
||||||
|
func (s *Self) SendVideoToMp(mp *Mp, file *os.File) (*SentMessage, error) {
|
||||||
|
return s.sendVideoToUser(mp.User, file)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Self) sendMessageWrapper(message *SentMessage, err error) (*SentMessage, error) {
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
message.Self = s
|
||||||
|
return message, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user