forked from Mrs4s/MiraiGo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
elements.go
141 lines (129 loc) · 2.52 KB
/
elements.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package topic
import (
"strconv"
)
type (
TextElement struct {
Content string
}
EmojiElement struct {
Index int32
Id string
Name string
}
AtElement struct {
Id string
TinyId uint64
Nickname string
}
ChannelQuoteElement struct {
GuildId uint64
ChannelId uint64
DisplayText string
}
UrlQuoteElement struct {
Url string
DisplayText string
}
)
func selectContent(b bool, c1, c2 content) content {
if b {
return c1
}
return c2
}
func (e *TextElement) pack(patternId string, isPatternData bool) content {
return selectContent(isPatternData,
content{
"type": 1,
"style": "n",
"text": e.Content,
"children": make([]int, 0),
},
content{
"type": 1,
"text_content": content{
"text": e.Content,
},
})
}
func (e *EmojiElement) pack(patternId string, isPatternData bool) content {
return selectContent(isPatternData,
content{
"type": 2,
"id": patternId,
"emojiType": "1",
"emojiId": e.Id,
},
content{
"type": 4,
"pattern_id": patternId,
"emoji_content": content{
"type": "1",
"id": e.Id,
},
})
}
func (e *AtElement) pack(patternId string, isPatternData bool) content {
return selectContent(isPatternData,
content{
"type": 3,
"id": patternId,
"user": content{
"id": strconv.FormatUint(e.TinyId, 10),
"nick": e.Nickname,
},
},
content{
"type": 2,
"pattern_id": patternId,
"at_content": content{
"type": 1,
"user": content{
"id": e.Id,
"nick": e.Nickname,
},
},
})
}
func (e *ChannelQuoteElement) pack(patternId string, isPatternData bool) content {
return selectContent(isPatternData,
content{
"type": 4,
"id": patternId,
"guild_info": content{
"channel_id": strconv.FormatUint(e.ChannelId, 10),
"name": e.DisplayText,
},
},
content{
"type": 5,
"pattern_id": patternId,
"channel_content": content{
"channel_info": content{
"name": e.DisplayText,
"sign": content{
"guild_id": strconv.FormatUint(e.GuildId, 10),
"channel_id": strconv.FormatUint(e.ChannelId, 10),
},
},
},
})
}
func (e *UrlQuoteElement) pack(patternId string, isPatternData bool) content {
return selectContent(isPatternData,
content{
"type": 5,
"desc": e.DisplayText,
"href": e.Url,
"id": patternId,
},
content{
"type": 3,
"pattern_id": patternId,
"url_content": content{
"url": e.Url,
"displayText": e.DisplayText,
},
})
}