1use compact_str::CompactString;
8use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Error as DeError};
9
10use crate::{
11 guild::Member,
12 id::{
13 ApplicationId, ChannelId, EmojiId, GenericId, GuildId, MessageId, RoleId, TagId, UserId,
14 WebhookId,
15 },
16 macros::{int_enum, int_flags},
17 permissions::Permissions,
18 user::User,
19 util::{ImageHash, Timestamp},
20};
21
22#[derive(Clone, Debug, PartialEq, Eq)]
50#[non_exhaustive]
51pub enum Channel {
52 Text(TextChannel),
54 Dm(DmChannel),
56 Voice(VoiceChannel),
58 GroupDm(GroupDmChannel),
60 Category(CategoryChannel),
62 Announcement(TextChannel),
65 AnnouncementThread(ThreadChannel),
67 PublicThread(ThreadChannel),
69 PrivateThread(ThreadChannel),
71 Stage(VoiceChannel),
73 Directory(DirectoryChannel),
75 Forum(ForumChannel),
77 Media(ForumChannel),
79 Unknown(UnknownChannel),
81}
82
83impl Channel {
84 #[must_use]
88 pub const fn id(&self) -> ChannelId {
89 match self {
90 Self::Text(channel) | Self::Announcement(channel) => channel.id,
91 Self::Dm(channel) => channel.id,
92 Self::Voice(channel) | Self::Stage(channel) => channel.id,
93 Self::GroupDm(channel) => channel.id,
94 Self::Category(channel) => channel.id,
95 Self::AnnouncementThread(channel)
96 | Self::PublicThread(channel)
97 | Self::PrivateThread(channel) => channel.id,
98 Self::Directory(channel) => channel.id,
99 Self::Forum(channel) | Self::Media(channel) => channel.id,
100 Self::Unknown(channel) => channel.id,
101 }
102 }
103
104 #[must_use]
108 pub const fn kind(&self) -> ChannelType {
109 match self {
110 Self::Text(_) => ChannelType::GuildText,
111 Self::Dm(_) => ChannelType::Dm,
112 Self::Voice(_) => ChannelType::GuildVoice,
113 Self::GroupDm(_) => ChannelType::GroupDm,
114 Self::Category(_) => ChannelType::GuildCategory,
115 Self::Announcement(_) => ChannelType::GuildAnnouncement,
116 Self::AnnouncementThread(_) => ChannelType::AnnouncementThread,
117 Self::PublicThread(_) => ChannelType::PublicThread,
118 Self::PrivateThread(_) => ChannelType::PrivateThread,
119 Self::Stage(_) => ChannelType::GuildStageVoice,
120 Self::Directory(_) => ChannelType::GuildDirectory,
121 Self::Forum(_) => ChannelType::GuildForum,
122 Self::Media(_) => ChannelType::GuildMedia,
123 Self::Unknown(channel) => channel.kind,
124 }
125 }
126
127 #[must_use]
132 pub const fn guild_id(&self) -> Option<GuildId> {
133 match self {
134 Self::Text(channel) | Self::Announcement(channel) => channel.guild_id,
135 Self::Voice(channel) | Self::Stage(channel) => channel.guild_id,
136 Self::Category(channel) => channel.guild_id,
137 Self::AnnouncementThread(channel)
138 | Self::PublicThread(channel)
139 | Self::PrivateThread(channel) => channel.guild_id,
140 Self::Directory(channel) => channel.guild_id,
141 Self::Forum(channel) | Self::Media(channel) => channel.guild_id,
142 Self::Unknown(channel) => channel.guild_id,
143 Self::Dm(_) | Self::GroupDm(_) => None,
144 }
145 }
146
147 #[must_use]
151 pub fn name(&self) -> Option<&str> {
152 match self {
153 Self::Text(channel) | Self::Announcement(channel) => Some(&channel.name),
154 Self::Voice(channel) | Self::Stage(channel) => Some(&channel.name),
155 Self::Category(channel) => Some(&channel.name),
156 Self::AnnouncementThread(channel)
157 | Self::PublicThread(channel)
158 | Self::PrivateThread(channel) => Some(&channel.name),
159 Self::Directory(channel) => Some(&channel.name),
160 Self::Forum(channel) | Self::Media(channel) => Some(&channel.name),
161 Self::GroupDm(channel) => channel.name.as_deref(),
162 Self::Unknown(channel) => channel.name.as_deref(),
163 Self::Dm(_) => None,
164 }
165 }
166
167 #[must_use]
171 pub const fn parent_id(&self) -> Option<ChannelId> {
172 match self {
173 Self::Text(channel) | Self::Announcement(channel) => channel.parent_id,
174 Self::Voice(channel) | Self::Stage(channel) => channel.parent_id,
175 Self::AnnouncementThread(channel)
176 | Self::PublicThread(channel)
177 | Self::PrivateThread(channel) => channel.parent_id,
178 Self::Directory(channel) => channel.parent_id,
179 Self::Forum(channel) | Self::Media(channel) => channel.parent_id,
180 Self::Unknown(channel) => channel.parent_id,
181 Self::Dm(_) | Self::GroupDm(_) | Self::Category(_) => None,
182 }
183 }
184
185 #[must_use]
189 pub const fn flags(&self) -> ChannelFlags {
190 match self {
191 Self::Text(channel) | Self::Announcement(channel) => channel.flags,
192 Self::Dm(channel) => channel.flags,
193 Self::Voice(channel) | Self::Stage(channel) => channel.flags,
194 Self::GroupDm(channel) => channel.flags,
195 Self::Category(channel) => channel.flags,
196 Self::AnnouncementThread(channel)
197 | Self::PublicThread(channel)
198 | Self::PrivateThread(channel) => channel.flags,
199 Self::Directory(channel) => channel.flags,
200 Self::Forum(channel) | Self::Media(channel) => channel.flags,
201 Self::Unknown(channel) => channel.flags,
202 }
203 }
204
205 #[must_use]
209 pub fn permission_overwrites(&self) -> &[Overwrite] {
210 match self {
211 Self::Text(channel) | Self::Announcement(channel) => &channel.permission_overwrites,
212 Self::Voice(channel) | Self::Stage(channel) => &channel.permission_overwrites,
213 Self::Category(channel) => &channel.permission_overwrites,
214 Self::Directory(channel) => &channel.permission_overwrites,
215 Self::Forum(channel) | Self::Media(channel) => &channel.permission_overwrites,
216 Self::Dm(_)
217 | Self::GroupDm(_)
218 | Self::AnnouncementThread(_)
219 | Self::PublicThread(_)
220 | Self::PrivateThread(_)
221 | Self::Unknown(_) => &[],
222 }
223 }
224
225 #[must_use]
229 pub const fn as_thread(&self) -> Option<&ThreadChannel> {
230 match self {
231 Self::AnnouncementThread(channel)
232 | Self::PublicThread(channel)
233 | Self::PrivateThread(channel) => Some(channel),
234 _ => None,
235 }
236 }
237}
238
239int_enum! {
240 pub enum ChannelType: u8 {
244 GuildText = 0,
246 Dm = 1,
248 GuildVoice = 2,
250 GroupDm = 3,
252 GuildCategory = 4,
254 GuildAnnouncement = 5,
256 AnnouncementThread = 10,
258 PublicThread = 11,
260 PrivateThread = 12,
262 GuildStageVoice = 13,
264 GuildDirectory = 14,
266 GuildForum = 15,
268 GuildMedia = 16,
270 }
271}
272
273impl ChannelType {
274 #[must_use]
278 pub const fn is_thread(self) -> bool {
279 matches!(
280 self,
281 Self::AnnouncementThread | Self::PublicThread | Self::PrivateThread
282 )
283 }
284}
285
286#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
290#[non_exhaustive]
291pub struct TextChannel {
292 pub id: ChannelId,
294 #[serde(skip_serializing_if = "Option::is_none")]
296 pub guild_id: Option<GuildId>,
297 pub name: CompactString,
299 pub position: i32,
301 pub permission_overwrites: Vec<Overwrite>,
303 pub parent_id: Option<ChannelId>,
305 pub nsfw: bool,
307 pub topic: Option<CompactString>,
309 pub last_message_id: Option<MessageId>,
311 pub rate_limit_per_user: u16,
314 #[serde(skip_serializing_if = "Option::is_none")]
316 pub last_pin_timestamp: Option<Timestamp>,
317 #[serde(skip_serializing_if = "Option::is_none")]
319 pub default_auto_archive_duration: Option<AutoArchiveDuration>,
320 #[serde(skip_serializing_if = "Option::is_none")]
322 pub default_thread_rate_limit_per_user: Option<u16>,
323 pub flags: ChannelFlags,
325}
326
327#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
333#[non_exhaustive]
334pub struct VoiceChannel {
335 pub id: ChannelId,
337 #[serde(skip_serializing_if = "Option::is_none")]
339 pub guild_id: Option<GuildId>,
340 pub name: CompactString,
342 pub position: i32,
344 pub permission_overwrites: Vec<Overwrite>,
346 pub parent_id: Option<ChannelId>,
348 pub nsfw: bool,
350 #[serde(skip_serializing_if = "Option::is_none")]
352 pub topic: Option<CompactString>,
353 pub last_message_id: Option<MessageId>,
355 pub rate_limit_per_user: u16,
357 pub bitrate: u32,
359 pub user_limit: u32,
361 pub rtc_region: Option<CompactString>,
364 pub video_quality_mode: VideoQualityMode,
366 pub flags: ChannelFlags,
368}
369
370#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
374#[non_exhaustive]
375pub struct CategoryChannel {
376 pub id: ChannelId,
378 #[serde(skip_serializing_if = "Option::is_none")]
380 pub guild_id: Option<GuildId>,
381 pub name: CompactString,
383 pub position: i32,
385 pub permission_overwrites: Vec<Overwrite>,
387 pub nsfw: bool,
389 pub flags: ChannelFlags,
391}
392
393#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
397#[non_exhaustive]
398pub struct ForumChannel {
399 pub id: ChannelId,
401 #[serde(skip_serializing_if = "Option::is_none")]
403 pub guild_id: Option<GuildId>,
404 pub name: CompactString,
406 pub position: i32,
408 pub permission_overwrites: Vec<Overwrite>,
410 pub parent_id: Option<ChannelId>,
412 pub nsfw: bool,
414 pub topic: Option<CompactString>,
416 pub last_message_id: Option<MessageId>,
418 pub rate_limit_per_user: u16,
420 #[serde(skip_serializing_if = "Option::is_none")]
422 pub default_auto_archive_duration: Option<AutoArchiveDuration>,
423 pub available_tags: Vec<ForumTag>,
425 #[serde(skip_serializing_if = "Option::is_none")]
427 pub default_thread_rate_limit_per_user: Option<u16>,
428 pub default_reaction_emoji: Option<DefaultReaction>,
430 pub default_sort_order: Option<SortOrderType>,
432 pub default_forum_layout: ForumLayoutType,
434 pub flags: ChannelFlags,
436}
437
438#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
442#[non_exhaustive]
443pub struct ThreadChannel {
444 pub id: ChannelId,
446 #[serde(skip_serializing_if = "Option::is_none")]
448 pub guild_id: Option<GuildId>,
449 pub name: CompactString,
451 pub parent_id: Option<ChannelId>,
453 #[serde(skip_serializing_if = "Option::is_none")]
455 pub owner_id: Option<UserId>,
456 pub nsfw: bool,
458 pub last_message_id: Option<MessageId>,
460 pub rate_limit_per_user: u16,
462 #[serde(skip_serializing_if = "Option::is_none")]
464 pub last_pin_timestamp: Option<Timestamp>,
465 #[serde(skip_serializing_if = "Option::is_none")]
467 pub message_count: Option<u32>,
468 #[serde(skip_serializing_if = "Option::is_none")]
470 pub member_count: Option<u32>,
471 #[serde(skip_serializing_if = "Option::is_none")]
474 pub total_message_sent: Option<u32>,
475 pub thread_metadata: ThreadMetadata,
477 #[serde(skip_serializing_if = "Option::is_none")]
479 pub member: Option<Box<ThreadMember>>,
480 #[serde(skip_serializing_if = "Vec::is_empty")]
482 pub applied_tags: Vec<TagId>,
483 pub flags: ChannelFlags,
485}
486
487#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
491#[non_exhaustive]
492pub struct DmChannel {
493 pub id: ChannelId,
495 pub last_message_id: Option<MessageId>,
497 pub recipients: Vec<User>,
499 #[serde(skip_serializing_if = "Option::is_none")]
501 pub last_pin_timestamp: Option<Timestamp>,
502 pub flags: ChannelFlags,
504}
505
506#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
510#[non_exhaustive]
511pub struct GroupDmChannel {
512 pub id: ChannelId,
514 pub name: Option<CompactString>,
516 pub icon: Option<ImageHash>,
518 pub recipients: Vec<User>,
520 pub owner_id: UserId,
522 #[serde(skip_serializing_if = "Option::is_none")]
524 pub application_id: Option<ApplicationId>,
525 pub managed: bool,
527 pub last_message_id: Option<MessageId>,
529 #[serde(skip_serializing_if = "Option::is_none")]
531 pub last_pin_timestamp: Option<Timestamp>,
532 pub flags: ChannelFlags,
534}
535
536#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
540#[non_exhaustive]
541pub struct DirectoryChannel {
542 pub id: ChannelId,
544 #[serde(skip_serializing_if = "Option::is_none")]
546 pub guild_id: Option<GuildId>,
547 pub name: CompactString,
549 pub position: i32,
551 pub permission_overwrites: Vec<Overwrite>,
553 pub parent_id: Option<ChannelId>,
555 pub flags: ChannelFlags,
557}
558
559#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
564#[non_exhaustive]
565pub struct UnknownChannel {
566 pub id: ChannelId,
568 #[serde(skip)]
570 pub kind: ChannelType,
571 #[serde(skip_serializing_if = "Option::is_none")]
573 pub guild_id: Option<GuildId>,
574 #[serde(skip_serializing_if = "Option::is_none")]
576 pub name: Option<CompactString>,
577 #[serde(skip_serializing_if = "Option::is_none")]
579 pub parent_id: Option<ChannelId>,
580 pub flags: ChannelFlags,
582}
583
584#[derive(Deserialize)]
587struct RawChannel {
588 id: ChannelId,
589 #[serde(rename = "type")]
590 kind: ChannelType,
591 #[serde(default)]
592 guild_id: Option<GuildId>,
593 #[serde(default)]
594 position: Option<i32>,
595 #[serde(default)]
596 permission_overwrites: Vec<Overwrite>,
597 #[serde(default)]
598 name: Option<CompactString>,
599 #[serde(default)]
600 topic: Option<CompactString>,
601 #[serde(default)]
602 nsfw: bool,
603 #[serde(default)]
604 last_message_id: Option<MessageId>,
605 #[serde(default)]
606 bitrate: Option<u32>,
607 #[serde(default)]
608 user_limit: Option<u32>,
609 #[serde(default)]
610 rate_limit_per_user: Option<u16>,
611 #[serde(default)]
612 recipients: Vec<User>,
613 #[serde(default)]
614 icon: Option<ImageHash>,
615 #[serde(default)]
616 owner_id: Option<UserId>,
617 #[serde(default)]
618 application_id: Option<ApplicationId>,
619 #[serde(default)]
620 managed: bool,
621 #[serde(default)]
622 parent_id: Option<ChannelId>,
623 #[serde(default)]
624 last_pin_timestamp: Option<Timestamp>,
625 #[serde(default)]
626 rtc_region: Option<CompactString>,
627 #[serde(default)]
628 video_quality_mode: Option<VideoQualityMode>,
629 #[serde(default)]
630 message_count: Option<u32>,
631 #[serde(default)]
632 member_count: Option<u32>,
633 #[serde(default)]
634 thread_metadata: Option<ThreadMetadata>,
635 #[serde(default)]
636 member: Option<Box<ThreadMember>>,
637 #[serde(default)]
638 default_auto_archive_duration: Option<AutoArchiveDuration>,
639 #[serde(default)]
640 flags: ChannelFlags,
641 #[serde(default)]
642 total_message_sent: Option<u32>,
643 #[serde(default)]
644 available_tags: Vec<ForumTag>,
645 #[serde(default)]
646 applied_tags: Vec<TagId>,
647 #[serde(default)]
648 default_reaction_emoji: Option<DefaultReaction>,
649 #[serde(default)]
650 default_thread_rate_limit_per_user: Option<u16>,
651 #[serde(default)]
652 default_sort_order: Option<SortOrderType>,
653 #[serde(default)]
654 default_forum_layout: Option<ForumLayoutType>,
655}
656
657impl RawChannel {
658 fn name<E: DeError>(&mut self) -> Result<CompactString, E> {
659 self.name.take().ok_or_else(|| E::missing_field("name"))
660 }
661
662 fn into_channel<E: DeError>(mut self) -> Result<Channel, E> {
663 Ok(match self.kind {
664 ChannelType::GuildText => Channel::Text(self.text()?),
665 ChannelType::GuildAnnouncement => Channel::Announcement(self.text()?),
666 ChannelType::GuildVoice => Channel::Voice(self.voice()?),
667 ChannelType::GuildStageVoice => Channel::Stage(self.voice()?),
668 ChannelType::GuildForum => Channel::Forum(self.forum()?),
669 ChannelType::GuildMedia => Channel::Media(self.forum()?),
670 ChannelType::AnnouncementThread => Channel::AnnouncementThread(self.thread()?),
671 ChannelType::PublicThread => Channel::PublicThread(self.thread()?),
672 ChannelType::PrivateThread => Channel::PrivateThread(self.thread()?),
673 ChannelType::GuildCategory => Channel::Category(CategoryChannel {
674 id: self.id,
675 guild_id: self.guild_id,
676 name: self.name()?,
677 position: self.position.unwrap_or_default(),
678 permission_overwrites: self.permission_overwrites,
679 nsfw: self.nsfw,
680 flags: self.flags,
681 }),
682 ChannelType::Dm => Channel::Dm(DmChannel {
683 id: self.id,
684 last_message_id: self.last_message_id,
685 recipients: self.recipients,
686 last_pin_timestamp: self.last_pin_timestamp,
687 flags: self.flags,
688 }),
689 ChannelType::GroupDm => Channel::GroupDm(GroupDmChannel {
690 id: self.id,
691 name: self.name,
692 icon: self.icon,
693 recipients: self.recipients,
694 owner_id: self.owner_id.ok_or_else(|| E::missing_field("owner_id"))?,
695 application_id: self.application_id,
696 managed: self.managed,
697 last_message_id: self.last_message_id,
698 last_pin_timestamp: self.last_pin_timestamp,
699 flags: self.flags,
700 }),
701 ChannelType::GuildDirectory => Channel::Directory(DirectoryChannel {
702 id: self.id,
703 guild_id: self.guild_id,
704 name: self.name()?,
705 position: self.position.unwrap_or_default(),
706 permission_overwrites: self.permission_overwrites,
707 parent_id: self.parent_id,
708 flags: self.flags,
709 }),
710 ChannelType::Unknown(_) => Channel::Unknown(UnknownChannel {
711 id: self.id,
712 kind: self.kind,
713 guild_id: self.guild_id,
714 name: self.name,
715 parent_id: self.parent_id,
716 flags: self.flags,
717 }),
718 })
719 }
720
721 fn text<E: DeError>(mut self) -> Result<TextChannel, E> {
722 Ok(TextChannel {
723 id: self.id,
724 guild_id: self.guild_id,
725 name: self.name()?,
726 position: self.position.unwrap_or_default(),
727 permission_overwrites: self.permission_overwrites,
728 parent_id: self.parent_id,
729 nsfw: self.nsfw,
730 topic: self.topic,
731 last_message_id: self.last_message_id,
732 rate_limit_per_user: self.rate_limit_per_user.unwrap_or_default(),
733 last_pin_timestamp: self.last_pin_timestamp,
734 default_auto_archive_duration: self.default_auto_archive_duration,
735 default_thread_rate_limit_per_user: self.default_thread_rate_limit_per_user,
736 flags: self.flags,
737 })
738 }
739
740 fn voice<E: DeError>(mut self) -> Result<VoiceChannel, E> {
741 Ok(VoiceChannel {
742 id: self.id,
743 guild_id: self.guild_id,
744 name: self.name()?,
745 position: self.position.unwrap_or_default(),
746 permission_overwrites: self.permission_overwrites,
747 parent_id: self.parent_id,
748 nsfw: self.nsfw,
749 topic: self.topic,
750 last_message_id: self.last_message_id,
751 rate_limit_per_user: self.rate_limit_per_user.unwrap_or_default(),
752 bitrate: self.bitrate.unwrap_or_default(),
753 user_limit: self.user_limit.unwrap_or_default(),
754 rtc_region: self.rtc_region,
755 video_quality_mode: self.video_quality_mode.unwrap_or_default(),
756 flags: self.flags,
757 })
758 }
759
760 fn forum<E: DeError>(mut self) -> Result<ForumChannel, E> {
761 Ok(ForumChannel {
762 id: self.id,
763 guild_id: self.guild_id,
764 name: self.name()?,
765 position: self.position.unwrap_or_default(),
766 permission_overwrites: self.permission_overwrites,
767 parent_id: self.parent_id,
768 nsfw: self.nsfw,
769 topic: self.topic,
770 last_message_id: self.last_message_id,
771 rate_limit_per_user: self.rate_limit_per_user.unwrap_or_default(),
772 default_auto_archive_duration: self.default_auto_archive_duration,
773 available_tags: self.available_tags,
774 default_thread_rate_limit_per_user: self.default_thread_rate_limit_per_user,
775 default_reaction_emoji: self.default_reaction_emoji,
776 default_sort_order: self.default_sort_order,
777 default_forum_layout: self.default_forum_layout.unwrap_or_default(),
778 flags: self.flags,
779 })
780 }
781
782 fn thread<E: DeError>(mut self) -> Result<ThreadChannel, E> {
783 Ok(ThreadChannel {
784 id: self.id,
785 guild_id: self.guild_id,
786 name: self.name()?,
787 parent_id: self.parent_id,
788 owner_id: self.owner_id,
789 nsfw: self.nsfw,
790 last_message_id: self.last_message_id,
791 rate_limit_per_user: self.rate_limit_per_user.unwrap_or_default(),
792 last_pin_timestamp: self.last_pin_timestamp,
793 message_count: self.message_count,
794 member_count: self.member_count,
795 total_message_sent: self.total_message_sent,
796 thread_metadata: self
797 .thread_metadata
798 .ok_or_else(|| E::missing_field("thread_metadata"))?,
799 member: self.member,
800 applied_tags: self.applied_tags,
801 flags: self.flags,
802 })
803 }
804}
805
806impl<'de> Deserialize<'de> for Channel {
807 fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
808 RawChannel::deserialize(deserializer)?.into_channel()
809 }
810}
811
812#[derive(Serialize)]
814struct Tagged<'a, T> {
815 #[serde(rename = "type")]
816 kind: ChannelType,
817 #[serde(flatten)]
818 channel: &'a T,
819}
820
821impl Serialize for Channel {
822 fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
823 let kind = self.kind();
824 match self {
825 Self::Text(channel) | Self::Announcement(channel) => {
826 Tagged { kind, channel }.serialize(serializer)
827 }
828 Self::Dm(channel) => Tagged { kind, channel }.serialize(serializer),
829 Self::Voice(channel) | Self::Stage(channel) => {
830 Tagged { kind, channel }.serialize(serializer)
831 }
832 Self::GroupDm(channel) => Tagged { kind, channel }.serialize(serializer),
833 Self::Category(channel) => Tagged { kind, channel }.serialize(serializer),
834 Self::AnnouncementThread(channel)
835 | Self::PublicThread(channel)
836 | Self::PrivateThread(channel) => Tagged { kind, channel }.serialize(serializer),
837 Self::Directory(channel) => Tagged { kind, channel }.serialize(serializer),
838 Self::Forum(channel) | Self::Media(channel) => {
839 Tagged { kind, channel }.serialize(serializer)
840 }
841 Self::Unknown(channel) => Tagged { kind, channel }.serialize(serializer),
842 }
843 }
844}
845
846#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
851#[non_exhaustive]
852#[doc(alias = "PermissionOverwrite")]
853pub struct Overwrite {
854 pub id: GenericId,
856 #[serde(rename = "type")]
858 pub kind: OverwriteType,
859 pub allow: Permissions,
861 pub deny: Permissions,
863}
864
865impl Overwrite {
866 #[must_use]
870 pub const fn new(
871 id: GenericId,
872 kind: OverwriteType,
873 allow: Permissions,
874 deny: Permissions,
875 ) -> Self {
876 Self {
877 id,
878 kind,
879 allow,
880 deny,
881 }
882 }
883
884 #[must_use]
897 pub const fn role(role_id: RoleId, allow: Permissions, deny: Permissions) -> Self {
898 Self::new(role_id.cast(), OverwriteType::Role, allow, deny)
899 }
900
901 #[must_use]
905 pub const fn member(user_id: UserId, allow: Permissions, deny: Permissions) -> Self {
906 Self::new(user_id.cast(), OverwriteType::Member, allow, deny)
907 }
908
909 #[must_use]
913 pub fn role_id(&self) -> Option<RoleId> {
914 (self.kind == OverwriteType::Role).then(|| self.id.cast())
915 }
916
917 #[must_use]
921 pub fn user_id(&self) -> Option<UserId> {
922 (self.kind == OverwriteType::Member).then(|| self.id.cast())
923 }
924}
925
926int_enum! {
927 pub enum OverwriteType: u8 {
931 Role = 0,
933 Member = 1,
935 }
936}
937
938int_enum! {
939 #[derive(Default)]
944 pub enum VideoQualityMode: u8 {
945 #[default]
947 Auto = 1,
948 Full = 2,
950 }
951}
952
953int_enum! {
954 pub enum SortOrderType: u8 {
958 LatestActivity = 0,
960 CreationDate = 1,
962 }
963}
964
965int_enum! {
966 #[derive(Default)]
970 pub enum ForumLayoutType: u8 {
971 #[default]
973 NotSet = 0,
974 ListView = 1,
976 GalleryView = 2,
978 }
979}
980
981int_enum! {
982 #[doc(alias = "ThreadAutoArchiveDuration")]
987 pub enum AutoArchiveDuration: u16 {
988 OneHour = 60,
990 OneDay = 1440,
992 ThreeDays = 4320,
994 OneWeek = 10080,
996 }
997}
998
999#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
1003#[non_exhaustive]
1004pub struct ThreadMetadata {
1005 pub archived: bool,
1007 pub auto_archive_duration: AutoArchiveDuration,
1009 pub archive_timestamp: Timestamp,
1011 pub locked: bool,
1013 #[serde(default, skip_serializing_if = "core::ops::Not::not")]
1015 pub invitable: bool,
1016 #[serde(default, skip_serializing_if = "Option::is_none")]
1018 pub create_timestamp: Option<Timestamp>,
1019}
1020
1021#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1025#[non_exhaustive]
1026pub struct ThreadMember {
1027 #[serde(default, skip_serializing_if = "Option::is_none")]
1029 pub id: Option<ChannelId>,
1030 #[serde(default, skip_serializing_if = "Option::is_none")]
1032 pub user_id: Option<UserId>,
1033 pub join_timestamp: Timestamp,
1035 pub flags: ThreadMemberFlags,
1037 #[serde(default, skip_serializing_if = "Option::is_none")]
1039 pub member: Option<Box<Member>>,
1040}
1041
1042int_flags! {
1043 pub struct ThreadMemberFlags: u64 {
1047 const HAS_INTERACTED = 1 << 0;
1052 const ALL_MESSAGES = 1 << 1;
1057 const ONLY_MENTIONS = 1 << 2;
1062 const NO_MESSAGES = 1 << 3;
1067 }
1068}
1069
1070#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
1075#[non_exhaustive]
1076pub struct DefaultReaction {
1077 pub emoji_id: Option<EmojiId>,
1079 pub emoji_name: Option<CompactString>,
1081}
1082
1083impl DefaultReaction {
1084 #[must_use]
1088 pub const fn custom(emoji_id: EmojiId) -> Self {
1089 Self {
1090 emoji_id: Some(emoji_id),
1091 emoji_name: None,
1092 }
1093 }
1094
1095 #[must_use]
1099 pub fn unicode(emoji: impl Into<CompactString>) -> Self {
1100 Self {
1101 emoji_id: None,
1102 emoji_name: Some(emoji.into()),
1103 }
1104 }
1105}
1106
1107#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
1112#[non_exhaustive]
1113pub struct ForumTag {
1114 pub id: TagId,
1116 pub name: CompactString,
1118 pub moderated: bool,
1120 pub emoji_id: Option<EmojiId>,
1122 pub emoji_name: Option<CompactString>,
1124}
1125
1126#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
1130#[non_exhaustive]
1131pub struct FollowedChannel {
1132 pub channel_id: ChannelId,
1134 pub webhook_id: WebhookId,
1136}
1137
1138int_flags! {
1139 pub struct ChannelFlags: u64 {
1143 const GUILD_FEED_REMOVED = 1 << 0;
1148 const PINNED = 1 << 1;
1150 const ACTIVE_CHANNELS_REMOVED = 1 << 2;
1155 const REQUIRE_TAG = 1 << 4;
1157 const IS_SPAM = 1 << 5;
1162 const IS_GUILD_RESOURCE_CHANNEL = 1 << 7;
1167 const CLYDE_AI = 1 << 8;
1172 const IS_SCHEDULED_FOR_DELETION = 1 << 9;
1177 const HIDE_MEDIA_DOWNLOAD_OPTIONS = 1 << 15;
1179 const CHANNEL_OBFUSCATED = 1 << 17;
1182 const IS_SPOILER_CHANNEL = 1 << 21;
1185 }
1186}