forked from andersfylling/disgord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
struct_emoji.go
104 lines (87 loc) · 2.27 KB
/
struct_emoji.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package disgord
import "sync"
// Emoji
type Emoji struct {
ID Snowflake `json:"id"`
Name string `json:"name"`
Roles []Snowflake `json:"roles,omitempty"`
User *User `json:"user,omitempty"` // the user who created the emoji
RequireColons bool `json:"require_colons,omitempty"`
Managed bool `json:"managed,omitempty"`
Animated bool `json:"animated,omitempty"`
// image string // base 64 string, with prefix and everything
mu sync.RWMutex
}
type PartialEmoji = Emoji
// SetBase64Image use this before creating the emoji for the first time
//func (e *Emoji) SetBase64Image(img string) {
// e.image = img
//}
// Mention mentions an emoji. Adds the animation prefix, if animated
func (e *Emoji) Mention() string {
prefix := ""
if e.Animated {
prefix = "a:"
}
return "<" + prefix + e.Name + ":" + e.ID.String() + ">"
}
func (e *Emoji) DeepCopy() (copy interface{}) {
copy = &Emoji{}
e.CopyOverTo(copy)
return
}
func (e *Emoji) CopyOverTo(other interface{}) (err error) {
var emoji *Emoji
var ok bool
if emoji, ok = other.(*Emoji); !ok {
err = NewErrorUnsupportedType("given type is not *Emoji")
return
}
e.mu.RLock()
emoji.mu.Lock()
emoji.ID = e.ID
emoji.Name = e.Name
emoji.Roles = e.Roles
emoji.RequireColons = e.RequireColons
emoji.Managed = e.Managed
emoji.Animated = e.Animated
emoji.mu = sync.RWMutex{}
if e.User != nil {
emoji.User = e.User.DeepCopy().(*User)
}
e.mu.RUnlock()
emoji.mu.Unlock()
return
}
// Missing GuildID...
//func (e *Emoji) saveToDiscord(session Session) (err error) {
// session.Emoji
//}
//func (e *Emoji) deleteFromDiscord(session Session) (err error) {
// session.DeleteGuildEmoji(guildID, emojiID)
//}
//func (e *Emoji) createGuildEmoji(session Session) (err error) {
// params := &CreateGuildEmojiParams{
// Name: e.Name,
// Image: e.image,
// Roles: e.Roles,
// }
//
// var creation *Emoji
// creation, err = session.CreateGuildEmoji(, params)
// if err != nil {
// return
// }
//
// creation.CopyOverTo(e)
// return
//}
//func (e *Emoji) modifyGuildEmoji(session Session) (err error) {
// params := &ModifyGuildEmojiParams{
// Name: e.Name,
// Roles: e.Roles,
// }
//}
// func (e *Emoji) Clear() {
// // obviously don't delete the user ...
// }