Skip to main content

stoat/builders/
edit_channel.rs

1use stoat_models::v0::{Channel, DataEditChannel, FieldsChannel, VoiceInformation};
2
3use crate::{HttpClient, error::Error};
4
5pub struct EditChannelBuilder {
6    http: HttpClient,
7    channel_id: String,
8    data: DataEditChannel,
9}
10
11impl EditChannelBuilder {
12    pub fn new(http: HttpClient, channel_id: String) -> Self {
13        Self {
14            http,
15            channel_id,
16            data: DataEditChannel {
17                name: None,
18                description: None,
19                owner: None,
20                icon: None,
21                nsfw: None,
22                archived: None,
23                voice: None,
24                remove: Vec::new(),
25            },
26        }
27    }
28
29    pub fn name(&mut self, name: String) -> &mut Self {
30        self.data.name = Some(name);
31
32        self
33    }
34
35    pub fn description(&mut self, description: Option<String>) -> &mut Self {
36        if description.is_some() {
37            self.data.description = description
38        } else {
39            self.data.remove.push(FieldsChannel::Description);
40        }
41
42        self
43    }
44
45    pub fn owner(&mut self, owner: String) -> &mut Self {
46        self.data.owner = Some(owner);
47
48        self
49    }
50
51    pub fn icon(&mut self, icon: Option<String>) -> &mut Self {
52        if icon.is_some() {
53            self.data.icon = icon
54        } else {
55            self.data.remove.push(FieldsChannel::Icon);
56        }
57
58        self
59    }
60
61    pub fn nsfw(&mut self, nsfw: bool) -> &mut Self {
62        self.data.nsfw = Some(nsfw);
63
64        self
65    }
66
67    pub fn voice(&mut self, voice: Option<VoiceInformation>) -> &mut Self {
68        if voice.is_some() {
69            self.data.voice = voice
70        } else {
71            self.data.remove.push(FieldsChannel::Voice);
72        }
73
74        self
75    }
76
77    pub async fn build(&self) -> Result<Channel, Error> {
78        self.http.edit_channel(&self.channel_id, &self.data).await
79    }
80}