更新注释
This commit is contained in:
parent
45d57c123a
commit
2abb9cc99a
@ -350,6 +350,7 @@ func (c *Client) WebWxVerifyUser(storage WechatStorage, info RecommendInfo, veri
|
||||
return c.Do(req)
|
||||
}
|
||||
|
||||
// 获取图片消息的图片响应
|
||||
func (c *Client) WebWxGetMsgImg(msg *Message, info LoginInfo) (*http.Response, error) {
|
||||
path, _ := url.Parse(webWxGetMsgImgUrl)
|
||||
params := url.Values{}
|
||||
@ -360,6 +361,7 @@ func (c *Client) WebWxGetMsgImg(msg *Message, info LoginInfo) (*http.Response, e
|
||||
return c.Get(path.String())
|
||||
}
|
||||
|
||||
// 获取语音消息的语音响应
|
||||
func (c *Client) WebWxGetVoice(msg *Message, info LoginInfo) (*http.Response, error) {
|
||||
path, _ := url.Parse(webWxGetVoiceUrl)
|
||||
params := url.Values{}
|
||||
@ -369,6 +371,7 @@ func (c *Client) WebWxGetVoice(msg *Message, info LoginInfo) (*http.Response, er
|
||||
return c.Get(path.String())
|
||||
}
|
||||
|
||||
// 获取视频消息的视频响应
|
||||
func (c *Client) WebWxGetVideo(msg *Message, info LoginInfo) (*http.Response, error) {
|
||||
path, _ := url.Parse(webWxGetVideoUrl)
|
||||
params := url.Values{}
|
||||
@ -378,6 +381,7 @@ func (c *Client) WebWxGetVideo(msg *Message, info LoginInfo) (*http.Response, er
|
||||
return c.Get(path.String())
|
||||
}
|
||||
|
||||
// 获取文件消息的文件响应
|
||||
func (c *Client) WebWxGetMedia(msg *Message, info LoginInfo) (*http.Response, error) {
|
||||
path, _ := url.Parse(webWxGetMediaUrl)
|
||||
params := url.Values{}
|
||||
@ -391,6 +395,7 @@ func (c *Client) WebWxGetMedia(msg *Message, info LoginInfo) (*http.Response, er
|
||||
return c.Get(path.String())
|
||||
}
|
||||
|
||||
// 用户退出
|
||||
func (c *Client) Logout(info LoginInfo) (*http.Response, error) {
|
||||
path, _ := url.Parse(webWxLogoutUrl)
|
||||
params := url.Values{}
|
||||
|
@ -88,6 +88,7 @@ func (m *Message) SenderInGroup() (*User, error) {
|
||||
return users.First(), nil
|
||||
}
|
||||
|
||||
// 获取消息的接收者
|
||||
func (m *Message) Receiver() (*User, error) {
|
||||
if m.IsSendByGroup() {
|
||||
if sender, err := m.Sender(); err != nil {
|
||||
@ -187,10 +188,12 @@ func (m *Message) IsNotify() bool {
|
||||
return m.MsgType == 51 && m.StatusNotifyCode != 0
|
||||
}
|
||||
|
||||
// 判断消息是否为文件类型的消息
|
||||
func (m *Message) HasFile() bool {
|
||||
return m.IsPicture() || m.IsVoice() || m.IsVideo() || m.IsMedia()
|
||||
}
|
||||
|
||||
// 获取文件消息的文件
|
||||
func (m *Message) GetFile() (*http.Response, error) {
|
||||
if !m.HasFile() {
|
||||
return nil, errors.New("invalid message type")
|
||||
@ -210,7 +213,8 @@ func (m *Message) GetFile() (*http.Response, error) {
|
||||
return nil, errors.New("unsupported type")
|
||||
}
|
||||
|
||||
// 用在多个messageHandler之间传递信息
|
||||
// 往消息上下文中设置值
|
||||
// goroutine safe
|
||||
func (m *Message) Set(key string, value interface{}) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
@ -220,6 +224,8 @@ func (m *Message) Set(key string, value interface{}) {
|
||||
m.item[key] = value
|
||||
}
|
||||
|
||||
// 从消息上下文中获取值
|
||||
// goroutine safe
|
||||
func (m *Message) Get(key string) (value interface{}, exist bool) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
@ -227,6 +233,7 @@ func (m *Message) Get(key string) (value interface{}, exist bool) {
|
||||
return
|
||||
}
|
||||
|
||||
// 消息初始化,根据不同的消息作出不同的处理
|
||||
func (m *Message) init(bot *Bot) {
|
||||
m.Bot = bot
|
||||
if m.IsSendByGroup() {
|
||||
|
13
relations.go
13
relations.go
@ -13,28 +13,34 @@ func (f Friend) String() string {
|
||||
return fmt.Sprintf("<Friend:%s>", f.NickName)
|
||||
}
|
||||
|
||||
// 重命名当前好友
|
||||
func (f *Friend) RemarkName(name string) error {
|
||||
return f.remakeName(name)
|
||||
}
|
||||
|
||||
// 发送自定义消息
|
||||
func (f *Friend) SendMsg(msg *SendMessage) error {
|
||||
return f.sendMsg(msg)
|
||||
}
|
||||
|
||||
// 发送文本消息
|
||||
func (f *Friend) SendText(content string) error {
|
||||
return f.sendText(content)
|
||||
}
|
||||
|
||||
// 发送图片消息
|
||||
func (f *Friend) SendImage(file *os.File) error {
|
||||
return f.sendImage(file)
|
||||
}
|
||||
|
||||
type Friends []*Friend
|
||||
|
||||
// 获取好友的数量
|
||||
func (f Friends) Count() int {
|
||||
return len(f)
|
||||
}
|
||||
|
||||
// 获取第一个好友
|
||||
func (f Friends) First() *Friend {
|
||||
if f.Count() > 0 {
|
||||
return f[0]
|
||||
@ -42,6 +48,7 @@ func (f Friends) First() *Friend {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 获取最后一个好友
|
||||
func (f Friends) Last() *Friend {
|
||||
if f.Count() > 0 {
|
||||
return f[f.Count()-1]
|
||||
@ -49,18 +56,22 @@ func (f Friends) Last() *Friend {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 根据用户名查找好友
|
||||
func (f Friends) SearchByUserName(limit int, username string) (results Friends) {
|
||||
return f.Search(limit, func(friend *Friend) bool { return friend.User.UserName == username })
|
||||
}
|
||||
|
||||
// 根据昵称查找好友
|
||||
func (f Friends) SearchByNickName(limit int, nickName string) (results Friends) {
|
||||
return f.Search(limit, func(friend *Friend) bool { return friend.User.NickName == nickName })
|
||||
}
|
||||
|
||||
// 根据备注查找好友
|
||||
func (f Friends) SearchByRemarkName(limit int, remarkName string) (results Friends) {
|
||||
return f.Search(limit, func(friend *Friend) bool { return friend.User.RemarkName == remarkName })
|
||||
}
|
||||
|
||||
// 根据自定义条件查找好友
|
||||
func (f Friends) Search(limit int, condFuncList ...func(friend *Friend) bool) (results Friends) {
|
||||
if condFuncList == nil {
|
||||
return f
|
||||
@ -85,6 +96,7 @@ func (f Friends) Search(limit int, condFuncList ...func(friend *Friend) bool) (r
|
||||
return
|
||||
}
|
||||
|
||||
// 向slice的好友依次发送消息
|
||||
func (f Friends) SendMsg(msg *SendMessage) error {
|
||||
for _, friend := range f {
|
||||
if err := friend.SendMsg(msg); err != nil {
|
||||
@ -94,6 +106,7 @@ func (f Friends) SendMsg(msg *SendMessage) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 向slice的好友依次发送文本消息
|
||||
func (f Friends) SendText(text string) error {
|
||||
for _, friend := range f {
|
||||
if err := friend.SendText(text); err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user