This repository has been archived by the owner on Jan 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
channel.cr
234 lines (207 loc) · 4.78 KB
/
channel.cr
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
require "./converters"
module Discord
enum MessageType : UInt8
Default = 0
RecipientAdd = 1
RecipientRemove = 2
Call = 3
ChannelNameChange = 4
ChannelIconChange = 5
ChannelPinnedMessage = 6
GuildMemberJoin = 7
end
struct Message
JSON.mapping(
type: {type: MessageType, converter: MessageTypeConverter},
content: String,
id: Snowflake,
channel_id: Snowflake,
author: User,
timestamp: {type: Time, converter: TimestampConverter},
tts: Bool,
mention_everyone: Bool,
mentions: Array(User),
mention_roles: Array(Snowflake),
attachments: Array(Attachment),
embeds: Array(Embed),
pinned: Bool?,
reactions: Array(Reaction)?,
activity: Activity?
)
end
enum ActivityType : UInt8
Join = 1
Spectate = 2
Listen = 3
JoinRequest = 5
end
struct Activity
JSON.mapping(
type: ActivityType,
party_id: String?
)
end
enum ChannelType : UInt8
GuildText = 0
DM = 1
Voice = 2
GroupDM = 3
end
struct Channel
# :nodoc:
def initialize(private_channel : PrivateChannel)
@id = private_channel.id
@type = private_channel.type
@recipients = private_channel.recipients
@last_message_id = private_channel.last_message_id
end
JSON.mapping(
id: Snowflake,
type: {type: ChannelType, converter: ChannelTypeConverter},
guild_id: Snowflake?,
name: String?,
permission_overwrites: Array(Overwrite)?,
topic: String?,
last_message_id: Snowflake?,
bitrate: UInt32?,
user_limit: UInt32?,
recipients: Array(User)?,
nsfw: Bool?,
icon: Bool?,
owner_id: Snowflake?,
application_id: Snowflake?,
position: Int32?,
parent_id: Snowflake?
)
end
struct PrivateChannel
JSON.mapping(
id: Snowflake,
type: {type: ChannelType, converter: ChannelTypeConverter},
recipients: Array(User),
last_message_id: Snowflake?
)
end
struct Overwrite
JSON.mapping(
id: Snowflake,
type: String,
allow: Permissions,
deny: Permissions
)
end
struct Reaction
JSON.mapping(
emoji: ReactionEmoji,
count: UInt32,
me: Bool
)
end
struct ReactionEmoji
JSON.mapping(
id: Snowflake?,
name: String
)
end
struct Embed
def initialize(@title : String? = nil, @type : String = "rich",
@description : String? = nil, @url : String? = nil,
@timestamp : Time? = nil, @colour : UInt32? = nil,
@footer : EmbedFooter? = nil, @image : EmbedImage? = nil,
@thumbnail : EmbedThumbnail? = nil, @author : EmbedAuthor? = nil,
@fields : Array(EmbedField)? = nil)
end
JSON.mapping(
title: String?,
type: String,
description: String?,
url: String?,
timestamp: {type: Time?, converter: TimestampConverter},
colour: {type: UInt32?, key: "color"},
footer: EmbedFooter?,
image: EmbedImage?,
thumbnail: EmbedThumbnail?,
video: EmbedVideo?,
provider: EmbedProvider?,
author: EmbedAuthor?,
fields: Array(EmbedField)?
)
{% unless flag?(:correct_english) %}
def color
colour
end
{% end %}
end
struct EmbedThumbnail
def initialize(@url : String)
end
JSON.mapping(
url: String,
proxy_url: String?,
height: UInt32?,
width: UInt32?
)
end
struct EmbedVideo
JSON.mapping(
url: String,
height: UInt32,
width: UInt32
)
end
struct EmbedImage
def initialize(@url : String)
end
JSON.mapping(
url: String,
proxy_url: String?,
height: UInt32?,
width: UInt32?
)
end
struct EmbedProvider
JSON.mapping(
name: String,
url: String?
)
end
struct EmbedAuthor
def initialize(@name : String? = nil, @url : String? = nil, @icon_url : String? = nil)
end
JSON.mapping(
name: String?,
url: String?,
icon_url: String?,
proxy_icon_url: String?
)
end
struct EmbedFooter
def initialize(@text : String? = nil, @icon_url : String? = nil)
end
JSON.mapping(
text: String?,
icon_url: String?,
proxy_icon_url: String?
)
end
struct EmbedField
def initialize(@name : String, @value : String, @inline : Bool = false)
end
JSON.mapping(
name: String,
value: String,
inline: Bool
)
end
struct Attachment
JSON.mapping(
id: Snowflake,
filename: String,
size: UInt32,
url: String,
proxy_url: String,
height: UInt32?,
width: UInt32?
)
end
end