spectacles_model/
channel.rs1use chrono::{DateTime, FixedOffset};
3use serde_repr::{Deserialize_repr, Serialize_repr};
4
5use crate::{Snowflake, User};
6
7#[derive(Serialize, Deserialize, Debug, Clone, Default)]
9pub struct Channel {
10 pub id: Snowflake,
12 #[serde(rename = "type")]
14 pub kind: Option<ChannelType>,
15 #[serde(default)]
17 pub guild_id: Option<Snowflake>,
18 #[serde(default)]
20 pub position: Option<i32>,
21 #[serde(default)]
23 pub permission_overwrites: Option<Vec<PermissionOverwrites>>,
24 #[serde(default)]
26 pub name: Option<String>,
27 #[serde(default)]
29 pub topic: Option<String>,
30 #[serde(default)]
32 pub nsfw: Option<bool>,
33 #[serde(default)]
35 pub last_message_id: Option<Snowflake>,
36 #[serde(default)]
38 pub bitrate: Option<i32>,
39 #[serde(default)]
41 pub user_limit: Option<i32>,
42 #[serde(default)]
44 pub rate_limit_per_user: Option<i32>,
45 #[serde(default)]
47 pub recipients: Option<Vec<User>>,
48 #[serde(default)]
50 pub icon: Option<String>,
51 #[serde(default)]
53 pub owner_id: Option<Snowflake>,
54 #[serde(default)]
56 pub application_id: Option<Snowflake>,
57 #[serde(default)]
59 pub parent_id: Option<Snowflake>,
60 #[serde(default)]
62 pub last_pin_timestamp: Option<DateTime<FixedOffset>>
63}
64
65impl ToString for Channel {
66 fn to_string(&self) -> String {
67 format!("<#{}>", self.id.0)
68 }
69}
70
71#[derive(Serialize, Clone, Debug, Default)]
73pub struct CreateChannelOptions {
74 name: String,
75 #[serde(rename = "type")]
76 kind: Option<ChannelType>,
77 #[serde(skip_serializing_if = "Option::is_none")]
78 position: Option<i32>,
79 #[serde(skip_serializing_if = "Option::is_none")]
80 topic: Option<String>,
81 #[serde(skip_serializing_if = "Option::is_none")]
82 nsfw: Option<bool>,
83 #[serde(skip_serializing_if = "Option::is_none")]
84 rate_limit_per_user: Option<i8>,
85 #[serde(skip_serializing_if = "Option::is_none")]
86 bitrate: Option<i32>,
87 #[serde(skip_serializing_if = "Option::is_none")]
88 user_limit: Option<i32>,
89 #[serde(skip_serializing_if = "Option::is_none")]
90 permission_overwrites: Option<Vec<PermissionOverwrites>>,
91 #[serde(skip_serializing_if = "Option::is_none")]
92 parent_id: Option<Snowflake>,
93}
94
95#[derive(Serialize, Clone, Debug, Default)]
97pub struct ModifyChannelOptions {
98 #[serde(skip_serializing_if = "Option::is_none")]
99 name: Option<String>,
100 #[serde(skip_serializing_if = "Option::is_none")]
101 position: Option<i32>,
102 #[serde(skip_serializing_if = "Option::is_none")]
103 topic: Option<String>,
104 #[serde(skip_serializing_if = "Option::is_none")]
105 nsfw: Option<bool>,
106 #[serde(skip_serializing_if = "Option::is_none")]
107 rate_limit_per_user: Option<i8>,
108 #[serde(skip_serializing_if = "Option::is_none")]
109 bitrate: Option<i32>,
110 #[serde(skip_serializing_if = "Option::is_none")]
111 user_limit: Option<i32>,
112 #[serde(skip_serializing_if = "Option::is_none")]
115 parent_id: Option<Snowflake>
116}
117
118impl ModifyChannelOptions {
119 pub fn new() -> Self {
120 ModifyChannelOptions::default()
121 }
122
123 pub fn name(mut self, new_name: &str) -> Self {
125 self.name = Some(new_name.to_string());
126 self
127 }
128
129 pub fn set_position(mut self, pos: i32) -> Self {
131 self.position = Some(pos);
132 self
133 }
134
135 pub fn topic(mut self, top: &str) -> Self {
137 self.topic = Some(top.to_string());
138 self
139 }
140
141 pub fn nsfw(mut self, opt: bool) -> Self {
143 self.nsfw = Some(opt);
144 self
145 }
146
147 pub fn rate_limit_per_user(mut self, secs: i8) -> Self {
149 self.rate_limit_per_user = Some(secs);
150 self
151 }
152
153 pub fn user_limit(mut self, limit: i32) -> Self {
155 self.user_limit = Some(limit);
156 self
157 }
158
159 pub fn parent_id(mut self, id: u64) -> Self {
169 self.parent_id = Some(id.into());
170 self
171 }
172}
173#[derive(Serialize, Deserialize, Debug, Clone, Default)]
175pub struct PermissionOverwrites {
176 pub id: Snowflake,
178 #[serde(rename = "type")]
180 pub kind: String,
181 pub allow: i32,
183 pub deny: i32
185}
186
187#[derive(Serialize_repr, Deserialize_repr, Debug, Clone)]
189#[repr(u8)]
190pub enum ChannelType {
191 Text,
192 DM,
193 Voice,
194 GroupDM,
195 Category,
196 News,
197 Store
198}