添加对群系统消息的处理
This commit is contained in:
parent
0fbf517c3b
commit
ef31047cc5
17
message.go
17
message.go
@ -66,9 +66,18 @@ func (m *Message) Sender() (*User, error) {
|
|||||||
|
|
||||||
// SenderInGroup 获取消息在群里面的发送者
|
// SenderInGroup 获取消息在群里面的发送者
|
||||||
func (m *Message) SenderInGroup() (*User, error) {
|
func (m *Message) SenderInGroup() (*User, error) {
|
||||||
if !m.IsSendByGroup() {
|
if !m.IsComeFromGroup() {
|
||||||
return nil, errors.New("message is not from group")
|
return nil, errors.New("message is not from group")
|
||||||
}
|
}
|
||||||
|
// 拍一拍系列的系统消息
|
||||||
|
// https://github.com/eatmoreapple/openwechat/issues/66
|
||||||
|
if m.IsSystem() {
|
||||||
|
// 判断是否有自己发送
|
||||||
|
if m.FromUserName == m.Bot.self.User.UserName {
|
||||||
|
return m.Bot.self.User, nil
|
||||||
|
}
|
||||||
|
return nil, errors.New("can not found sender from system message")
|
||||||
|
}
|
||||||
group, err := m.Sender()
|
group, err := m.Sender()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -632,3 +641,9 @@ func (a *AppMessageData) IsArticle() bool {
|
|||||||
func (a AppMessageData) IsFile() bool {
|
func (a AppMessageData) IsFile() bool {
|
||||||
return a.AppMsg.Type == AppMsgTypeAttach
|
return a.AppMsg.Type == AppMsgTypeAttach
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsComeFromGroup 判断消息是否来自群组
|
||||||
|
// 可能是自己或者别的群员发送
|
||||||
|
func (m *Message) IsComeFromGroup() bool {
|
||||||
|
return m.IsSendByGroup() || strings.HasPrefix(m.ToUserName, "@@")
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user