/
Channel.swift
714 lines (643 loc) · 28.2 KB
/
Channel.swift
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
import Foundation
/// https://discord.com/developers/docs/resources/channel#channel-object-channel-structure
/// The same as what the Discord API docs call "partial channel".
/// Also the same as a "thread object".
public struct DiscordChannel: Sendable, Codable {
/// https://discord.com/developers/docs/resources/channel#channel-object-channel-types
@UnstableEnum<Int>
public enum Kind: Sendable, Codable {
case guildText // 0
case dm // 1
case guildVoice // 2
case groupDm // 3
case guildCategory // 4
case guildAnnouncement // 5
case announcementThread // 10
case publicThread // 11
case privateThread // 12
case guildStageVoice // 13
case guildDirectory // 14
case guildForum // 15
case __undocumented(Int)
}
/// https://discord.com/developers/docs/resources/channel#overwrite-object
public struct Overwrite: Sendable, Codable {
/// https://discord.com/developers/docs/resources/channel#overwrite-object
@UnstableEnum<Int>
public enum Kind: Sendable, Codable {
case role // 0
case member // 1
case __undocumented(Int)
}
public var id: AnySnowflake
public var type: Kind
public var allow: StringBitField<Permission>
public var deny: StringBitField<Permission>
}
/// https://discord.com/developers/docs/resources/channel#channel-object-sort-order-types
@UnstableEnum<Int>
public enum SortOrder: Sendable, Codable {
case latestActivity // 0
case creationDate // 1
case __undocumented(Int)
}
/// https://discord.com/developers/docs/resources/channel#channel-object-forum-layout-types
@UnstableEnum<Int>
public enum ForumLayout: Sendable, Codable {
case notSet // 0
case listView // 1
case galleryView // 2
case __undocumented(Int)
}
/// https://discord.com/developers/docs/resources/channel#channel-object-channel-flags
@UnstableEnum<UInt>
public enum Flag: Sendable {
case pinned // 1
case requireTag // 4
case __undocumented(UInt)
}
/// https://discord.com/developers/docs/resources/channel#channel-object-video-quality-modes
@UnstableEnum<Int>
public enum VideoQualityMode: Sendable, Codable {
case auto // 1
case full // 2
case __undocumented(Int)
}
/// Not exactly documented, but they do mention these times in a few different places.
/// Times are in minutes.
/// https://discord.com/developers/docs/resources/channel#channel-object-channel-structure
@UnstableEnum<Int>
public enum AutoArchiveDuration: Sendable, Codable {
case oneHour // 60
case oneDay // 1_440
case threeDays // 4_320
case sevenDays // 10_080
case __undocumented(Int)
}
/// https://discord.com/developers/docs/resources/channel#default-reaction-object-default-reaction-structure
public struct DefaultReaction: Sendable, Codable {
public var emoji_id: EmojiSnowflake?
public var emoji_name: String?
public init(emoji_id: EmojiSnowflake? = nil) {
self.emoji_id = emoji_id
self.emoji_name = nil
}
public init(emoji_name: String? = nil) {
self.emoji_id = nil
self.emoji_name = emoji_name
}
}
/// https://discord.com/developers/docs/resources/channel#forum-tag-object-forum-tag-structure
public struct ForumTag: Sendable, Codable {
public var id: ForumTagSnowflake
public var name: String
public var moderated: Bool
public var emoji_id: EmojiSnowflake?
public var emoji_name: String?
}
public var id: ChannelSnowflake
/// Type is optional because there are some endpoints that return
/// partial channel objects, and very few of them exclude the `type`.
public var type: Kind?
public var guild_id: GuildSnowflake?
public var position: Int?
public var permission_overwrites: [Overwrite]?
public var name: String?
public var topic: String?
public var nsfw: Bool?
public var last_message_id: MessageSnowflake?
public var bitrate: Int?
public var user_limit: Int?
public var rate_limit_per_user: Int?
public var recipients: [DiscordUser]?
public var icon: String?
public var owner_id: UserSnowflake?
public var application_id: ApplicationSnowflake?
public var manage: Bool?
public var parent_id: AnySnowflake?
public var last_pin_timestamp: DiscordTimestamp?
public var rtc_region: String?
public var video_quality_mode: VideoQualityMode?
public var message_count: Int?
public var total_message_sent: Int?
public var member_count: Int?
public var thread_metadata: ThreadMetadata?
public var default_auto_archive_duration: AutoArchiveDuration?
public var default_thread_rate_limit_per_user: Int?
public var default_reaction_emoji: DefaultReaction?
public var default_sort_order: Int?
public var default_forum_layout: ForumLayout?
public var permissions: StringBitField<Permission>?
public var flags: IntBitField<Flag>?
public var available_tags: [ForumTag]?
public var template: String?
public var member_ids_preview: [String]?
public var version: Int?
/// Thread-only:
public var member: ThreadMember?
public var newly_created: Bool?
/// Only populated by thread-related Gateway events.
public var threadMembers: [Gateway.ThreadMembersUpdate.ThreadMember]?
}
extension DiscordChannel {
/// https://discord.com/developers/docs/resources/channel#message-object
public struct Message: Sendable, Codable {
/// https://discord.com/developers/docs/resources/channel#message-reference-object-message-reference-structure
public struct MessageReference: Sendable, Codable {
public var message_id: MessageSnowflake?
public var channel_id: ChannelSnowflake?
public var guild_id: GuildSnowflake?
public var fail_if_not_exists: Bool?
public init(message_id: MessageSnowflake? = nil, channel_id: ChannelSnowflake? = nil, guild_id: GuildSnowflake? = nil, fail_if_not_exists: Bool? = nil) {
self.message_id = message_id
self.channel_id = channel_id
self.guild_id = guild_id
self.fail_if_not_exists = fail_if_not_exists
}
}
/// https://discord.com/developers/docs/resources/channel#message-object-message-types
@UnstableEnum<Int>
public enum Kind: Sendable, Codable {
case `default` // 0
case recipientAdd // 1
case recipientRemove // 2
case call // 3
case channelNameChange // 4
case channelIconChange // 5
case channelPinnedMessage // 6
case guildMemberJoin // 7
case userPremiumGuildSubscription // 8
case userPremiumGuildSubscriptionTier1 // 9
case userPremiumGuildSubscriptionTier2 // 10
case userPremiumGuildSubscriptionTier3 // 11
case channelFollowAdd // 12
case guildDiscoveryDisqualified // 14
case guildDiscoveryRequalified // 15
case guildDiscoveryGracePeriodInitialWarning // 16
case guildDiscoveryGracePeriodFinalWarning // 17
case threadCreated // 18
case reply // 19
case chatInputCommand // 20
case threadStarterMessage // 21
case guildInviteReminder // 22
case contextMenuCommand // 23
case autoModerationAction // 24
case roleSubscriptionPurchase // 25
case interactionPremiumUpsell // 26
case stageStart // 27
case stageEnd // 28
case stageSpeaker // 29
case stageTopic // 31
case guildApplicationPremiumSubscription // 32
case __undocumented(Int)
}
/// https://discord.com/developers/docs/resources/channel#message-object-message-flags
@UnstableEnum<UInt>
public enum Flag: Sendable {
case crossposted // 0
case isCrosspost // 1
case suppressEmbeds // 2
case sourceMessageDeleted // 3
case urgent // 4
case hasThread // 5
case ephemeral // 6
case loading // 7
case failedToMentionSomeRolesInThread // 8
case suppressNotifications // 12
case isVoiceMessage // 13
case __undocumented(UInt)
}
/// https://discord.com/developers/docs/resources/channel#channel-mention-object
public struct ChannelMention: Sendable, Codable {
public var id: ChannelSnowflake
public var guild_id: GuildSnowflake
public var type: DiscordChannel.Kind
public var name: String
}
/// https://discord.com/developers/docs/resources/channel#attachment-object
public struct Attachment: Sendable, Codable {
/// https://discord.com/developers/docs/resources/channel#attachment-object-attachment-flags
@UnstableEnum<UInt>
public enum Flag: Sendable {
case isRemix // 2
case __undocumented(UInt)
}
public var id: AttachmentSnowflake
public var filename: String
public var description: String?
public var content_type: String?
public var size: Int
public var url: String
public var proxy_url: String
public var height: Int?
public var width: Int?
public var ephemeral: Bool?
public var duration_secs: Double?
public var waveform: String?
public var flags: IntBitField<Flag>?
}
/// https://discord.com/developers/docs/resources/channel#reaction-object
public struct Reaction: Sendable, Codable {
/// https://discord.com/developers/docs/resources/channel#reaction-object-reaction-count-details-structure
public struct CountDetails: Sendable, Codable {
public var burst: Int
public var normal: Int
public init(burst: Int, normal: Int) {
self.burst = burst
self.normal = normal
}
}
public var count: Int
public var count_details: CountDetails
public var me: Bool
public var me_burst: Bool
public var emoji: Emoji
public var burst_colors: [DiscordColor]
enum CodingKeys: String, CodingKey {
case count
case count_details
case me
case me_burst
case emoji
case burst_colors
}
@available(*, deprecated, renamed: "init(count:count_details:me:me_burst:emoji:burst_colors:)")
public init(count: Int, me: Bool, emoji: Emoji) {
self.count = count
self.count_details = .init(burst: 0, normal: 0)
self.me = me
self.me_burst = false
self.emoji = emoji
self.burst_colors = []
}
public init(count: Int, count_details: CountDetails, me: Bool, me_burst: Bool, emoji: Emoji, burst_colors: [DiscordColor]) {
self.count = count
self.count_details = count_details
self.me = me
self.me_burst = me_burst
self.emoji = emoji
self.burst_colors = burst_colors
}
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.count = try container.decode(Int.self, forKey: .count)
self.count_details = try container.decode(CountDetails.self, forKey: .count_details)
self.me = try container.decode(Bool.self, forKey: .me)
self.me_burst = try container.decode(Bool.self, forKey: .me_burst)
self.emoji = try container.decode(Emoji.self, forKey: .emoji)
self.burst_colors = try container.decode(
[String].self,
forKey: .burst_colors
).compactMap {
DiscordColor(hex: $0)
}
}
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.count, forKey: .count)
try container.encode(self.count_details, forKey: .count_details)
try container.encode(self.me, forKey: .me)
try container.encode(self.me_burst, forKey: .me_burst)
try container.encode(self.emoji, forKey: .emoji)
try container.encode(
self.burst_colors.map { $0.asHex() },
forKey: .burst_colors
)
}
}
/// https://discord.com/developers/docs/resources/channel#message-object-message-activity-structure
public struct Activity: Sendable, Codable {
/// https://discord.com/developers/docs/resources/channel#message-object-message-activity-types
@UnstableEnum<Int>
public enum Kind: Sendable, Codable {
case join // 1
case spectate // 2
case listen // 3
case joinRequest // 5
case __undocumented(Int)
}
public var type: Kind
/// Not a Snowflake. Example: `spotify:715622804258684938`.
public var party_id: String?
}
public var id: MessageSnowflake
public var channel_id: ChannelSnowflake
public var guild_id: GuildSnowflake?
public var author: DiscordUser?
public var member: Guild.PartialMember?
public var content: String
public var timestamp: DiscordTimestamp
public var edited_timestamp: DiscordTimestamp?
public var tts: Bool
public var mention_everyone: Bool
public var mentions: [MentionUser]
public var mention_roles: [RoleSnowflake]
public var mention_channels: [ChannelMention]?
public var attachments: [Attachment]
public var embeds: [Embed]
public var reactions: [Reaction]?
public var nonce: StringOrInt?
public var pinned: Bool
public var webhook_id: WebhookSnowflake?
public var type: Kind
public var activity: Activity?
public var application: PartialApplication?
public var application_id: ApplicationSnowflake?
public var message_reference: MessageReference?
public var flags: IntBitField<Flag>?
public var referenced_message: DereferenceBox<Message>?
public var interaction: MessageInteraction?
public var thread: DiscordChannel?
public var components: [Interaction.ActionRow]?
public var sticker_items: [StickerItem]?
public var stickers: [Sticker]?
public var position: Int?
public var role_subscription_data: RoleSubscriptionData?
public var resolved: Interaction.ApplicationCommand.ResolvedData?
}
}
extension DiscordChannel {
/// Partial ``DiscordChannel.Message`` object.
public struct PartialMessage: Sendable, Codable {
public var id: MessageSnowflake
public var channel_id: ChannelSnowflake
public var author: DiscordUser?
public var content: String?
public var timestamp: DiscordTimestamp?
public var edited_timestamp: DiscordTimestamp?
public var tts: Bool?
public var mention_everyone: Bool?
public var mentions: [MentionUser]?
public var mention_roles: [RoleSnowflake]?
public var mention_channels: [DiscordChannel.Message.ChannelMention]?
public var attachments: [DiscordChannel.Message.Attachment]?
public var embeds: [Embed]?
public var reactions: [DiscordChannel.Message.Reaction]?
public var nonce: StringOrInt?
public var pinned: Bool?
public var webhook_id: WebhookSnowflake?
public var type: DiscordChannel.Message.Kind?
public var activity: DiscordChannel.Message.Activity?
public var application: PartialApplication?
public var application_id: ApplicationSnowflake?
public var message_reference: DiscordChannel.Message.MessageReference?
public var flags: IntBitField<DiscordChannel.Message.Flag>?
public var referenced_message: DereferenceBox<PartialMessage>?
public var interaction: MessageInteraction?
public var thread: DiscordChannel?
public var components: [Interaction.ActionRow]?
public var sticker_items: [StickerItem]?
public var stickers: [Sticker]?
public var position: Int?
public var role_subscription_data: RoleSubscriptionData?
/// Extra fields:
public var member: Guild.PartialMember?
public var guild_id: GuildSnowflake?
public var resolved: Interaction.ApplicationCommand.ResolvedData?
}
}
/// https://discord.com/developers/docs/resources/channel#thread-metadata-object-thread-metadata-structure
public struct ThreadMetadata: Sendable, Codable {
public var archived: Bool
public var auto_archive_duration: DiscordChannel.AutoArchiveDuration
public var archive_timestamp: DiscordTimestamp
public var locked: Bool
public var invitable: Bool?
public var create_timestamp: DiscordTimestamp?
}
/// https://discord.com/developers/docs/resources/channel#thread-member-object-thread-member-structure
public struct ThreadMember: Sendable, Codable {
public var id: ChannelSnowflake?
public var user_id: UserSnowflake?
public var join_timestamp: DiscordTimestamp
/// FIXME:
/// The field is documented but doesn't say what exactly it is.
/// Discord says: "any user-thread settings, currently only used for notifications".
/// I think currently it's set to `1` or `0` depending on if you have notifications
/// enabled for the thread?
public var flags: Int
public init(threadMemberUpdate: Gateway.ThreadMemberUpdate) {
self.id = threadMemberUpdate.id
self.user_id = threadMemberUpdate.user_id
self.join_timestamp = threadMemberUpdate.join_timestamp
self.flags = threadMemberUpdate.flags
}
}
/// For a limited amount of endpoints which return the `member` object too.
/// https://discord.com/developers/docs/resources/channel#thread-member-object-thread-member-structure
public struct ThreadMemberWithMember: Sendable, Codable {
public var id: ChannelSnowflake?
public var user_id: UserSnowflake?
public var join_timestamp: DiscordTimestamp
/// FIXME:
/// The field is documented but doesn't say what exactly it is.
/// Discord says: "any user-thread settings, currently only used for notifications".
/// I think currently it's set to `1` or `0` depending on if you have notifications
/// enabled for the thread?
public var flags: Int
public var member: Guild.Member
}
/// Thread-related subset of `DiscordChannel.Kind`
/// https://discord.com/developers/docs/resources/channel#channel-object-channel-types
@UnstableEnum<Int>
public enum ThreadKind: Sendable, Codable {
case announcementThread // 10
case publicThread // 11
case privateThread // 12
case __undocumented(Int)
}
extension DiscordChannel {
/// https://discord.com/developers/docs/resources/channel#allowed-mentions-object
public struct AllowedMentions: Sendable, Codable {
/// https://discord.com/developers/docs/resources/channel#allowed-mentions-object-allowed-mention-types
@UnstableEnum<String>
public enum Kind: Sendable, Codable {
case roles
case users
case everyone
case __undocumented(String)
}
public var parse: [Kind]
public var roles: [RoleSnowflake]
public var users: [UserSnowflake]
public var replied_user: Bool
}
}
/// https://discord.com/developers/docs/resources/channel#embed-object
public struct Embed: Sendable, Codable, ValidatablePayload {
/// https://discord.com/developers/docs/resources/channel#embed-object-embed-types
@UnstableEnum<String>
public enum Kind: Sendable, Codable {
case rich // "rich"
case image // "image"
case video // "video"
case gifv // "gifv"
case article // "article"
case link // "link"
case autoModerationMessage // "auto_moderation_message"
case __undocumented(String)
}
public enum DynamicURL: Sendable, Codable, ExpressibleByStringLiteral {
public typealias StringLiteralType = String
case exact(String)
case attachment(name: String)
public var asString: String {
switch self {
case let .exact(exact):
return exact
case let .attachment(name):
return "attachment://\(name)"
}
}
public init(stringLiteral string: String) {
if string.hasPrefix("attachment://") {
self = .attachment(name: String(string.dropFirst(13)))
} else {
self = .exact(string)
}
}
public init(from string: String) {
if string.hasPrefix("attachment://") {
self = .attachment(name: String(string.dropFirst(13)))
} else {
self = .exact(string)
}
}
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let string = try container.decode(String.self)
self = .init(from: string)
}
public func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(self.asString)
}
}
/// https://discord.com/developers/docs/resources/channel#embed-object-embed-footer-structure
public struct Footer: Sendable, Codable {
public var text: String
public var icon_url: DynamicURL?
public var proxy_icon_url: String?
public init(text: String, icon_url: DynamicURL? = nil, proxy_icon_url: String? = nil) {
self.text = text
self.icon_url = icon_url
self.proxy_icon_url = proxy_icon_url
}
}
/// https://discord.com/developers/docs/resources/channel#embed-object-embed-image-structure
public struct Media: Sendable, Codable {
public var url: DynamicURL
public var proxy_url: String?
public var height: Int?
public var width: Int?
public init(url: DynamicURL, proxy_url: String? = nil, height: Int? = nil, width: Int? = nil) {
self.url = url
self.proxy_url = proxy_url
self.height = height
self.width = width
}
}
/// https://discord.com/developers/docs/resources/channel#embed-object-embed-provider-structure
public struct Provider: Sendable, Codable {
public var name: String?
public var url: String?
public init(name: String? = nil, url: String? = nil) {
self.name = name
self.url = url
}
}
/// https://discord.com/developers/docs/resources/channel#embed-object-embed-author-structure
public struct Author: Sendable, Codable {
public var name: String
public var url: String?
public var icon_url: DynamicURL?
public var proxy_icon_url: String?
public init(name: String, url: String? = nil, icon_url: DynamicURL? = nil, proxy_icon_url: String? = nil) {
self.name = name
self.url = url
self.icon_url = icon_url
self.proxy_icon_url = proxy_icon_url
}
}
/// https://discord.com/developers/docs/resources/channel#embed-object-embed-field-structure
public struct Field: Sendable, Codable {
public var name: String
public var value: String
public var inline: Bool?
public init(name: String, value: String, inline: Bool? = nil) {
self.name = name
self.value = value
self.inline = inline
}
}
public var title: String?
public var type: Kind?
public var description: String?
public var url: String?
public var timestamp: DiscordTimestamp?
public var color: DiscordColor?
public var footer: Footer?
public var image: Media?
public var thumbnail: Media?
public var video: Media?
public var provider: Provider?
public var author: Author?
public var fields: [Field]?
/// The length that matters towards the Discord limit (currently 6000 across all embeds).
public var contentLength: Int {
let fields = fields?.reduce(into: 0) {
$0 += $1.name.unicodeScalars.count + $1.value.unicodeScalars.count
} ?? 0
return (title?.unicodeScalars.count ?? 0) +
(description?.unicodeScalars.count ?? 0) +
fields +
(footer?.text.unicodeScalars.count ?? 0) +
(author?.name.unicodeScalars.count ?? 0)
}
public init(title: String? = nil, type: Embed.Kind? = nil, description: String? = nil, url: String? = nil, timestamp: Date? = nil, color: DiscordColor? = nil, footer: Embed.Footer? = nil, image: Embed.Media? = nil, thumbnail: Embed.Media? = nil, video: Embed.Media? = nil, provider: Embed.Provider? = nil, author: Embed.Author? = nil, fields: [Embed.Field]? = nil) {
self.title = title
self.type = type
self.description = description
self.url = url
self.timestamp = timestamp.map { DiscordTimestamp(date: $0) }
self.color = color
self.footer = footer
self.image = image
self.thumbnail = thumbnail
self.video = video
self.provider = provider
self.author = author
self.fields = fields
}
public func validate() -> [ValidationFailure] {
validateElementCountDoesNotExceed(fields, max: 25, name: "fields")
validateCharacterCountDoesNotExceed(title, max: 256, name: "title")
validateCharacterCountDoesNotExceed(description, max: 4_096, name: "description")
validateCharacterCountDoesNotExceed(footer?.text, max: 2_048, name: "footer.text")
validateCharacterCountDoesNotExceed(author?.name, max: 256, name: "author.name")
for field in fields ?? [] {
validateCharacterCountDoesNotExceed(field.name, max: 256, name: "field.name")
validateCharacterCountDoesNotExceed(field.value, max: 1_024, name: "field.value")
}
}
}
/// https://discord.com/developers/docs/resources/channel#role-subscription-data-object-role-subscription-data-object-structure
public struct RoleSubscriptionData: Sendable, Codable {
// FIXME: use `Snowflake<Type>` instead
public var role_subscription_listing_id: AnySnowflake
public var tier_name: String
public var total_months_subscribed: Int
public var is_renewal: Bool
}
// MARK: + DiscordChannel.Message.Kind
extension DiscordChannel.Message.Kind {
public var isDeletable: Bool {
switch self {
case .`default`, .channelPinnedMessage, .guildMemberJoin, .userPremiumGuildSubscription, .userPremiumGuildSubscriptionTier1, .userPremiumGuildSubscriptionTier2, .userPremiumGuildSubscriptionTier3, .channelFollowAdd, .threadCreated, .reply, .chatInputCommand, .guildInviteReminder, .contextMenuCommand, .autoModerationAction, .roleSubscriptionPurchase, .interactionPremiumUpsell, .stageStart, .stageEnd, .stageSpeaker, .stageTopic:
return true
case .recipientAdd, .recipientRemove, .call, .channelNameChange, .channelIconChange, .guildDiscoveryDisqualified, .guildDiscoveryRequalified, .guildDiscoveryGracePeriodInitialWarning, .guildDiscoveryGracePeriodFinalWarning, .threadStarterMessage, .guildApplicationPremiumSubscription:
return false
case .__undocumented: return false
}
}
}