-
Notifications
You must be signed in to change notification settings - Fork 87
/
contact_self.go
73 lines (65 loc) · 1.88 KB
/
contact_self.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package user
import (
"errors"
"github.com/wechaty/go-wechaty/wechaty-puppet/filebox"
_interface "github.com/wechaty/go-wechaty/wechaty/interface"
)
type ContactSelf struct {
*Contact
}
// NewContactSelf ...
func NewContactSelf(id string, accessory _interface.IAccessory) *ContactSelf {
return &ContactSelf{&Contact{
IAccessory: accessory,
Id: id,
}}
}
// SetAvatar SET the avatar for a bot
func (c *ContactSelf) SetAvatar(box *filebox.FileBox) error {
if c.Id != c.GetPuppet().SelfID() {
return errors.New("set avatar only available for user self")
}
return c.GetPuppet().SetContactAvatar(c.Id, box)
}
// QRCode get bot qrcode
func (c *ContactSelf) QRCode() (string, error) {
puppetId := c.GetPuppet().SelfID()
if puppetId == "" {
return "", errors.New("can not get qrcode, user might be either not logged in or already logged out")
}
if c.Id != puppetId {
return "", errors.New("only can get qrcode for the login userself")
}
code, err := c.GetPuppet().ContactSelfQRCode()
if err != nil {
return "", err
}
return code, nil
}
// SetName change bot name
func (c *ContactSelf) SetName(name string) error {
puppetId := c.GetPuppet().SelfID()
if puppetId == "" {
return errors.New("can not set name for user self, user might be either not logged in or already logged out")
}
if c.Id != puppetId {
return errors.New("only can set name for user self")
}
err := c.GetPuppet().SetContactSelfName(name)
if err != nil {
return err
}
_ = c.Sync()
return nil
}
// Signature change bot signature
func (c *ContactSelf) Signature(signature string) error {
puppetId := c.GetPuppet().SelfID()
if puppetId == "" {
return errors.New("can not set signature for user self, user might be either not logged in or already logged out")
}
if c.Id != puppetId {
return errors.New("only can change signature for user self")
}
return c.GetPuppet().SetContactSelfSignature(signature)
}