diff options
| author | Kyle Clemens <[email protected]> | 2018-01-08 13:18:13 -0500 |
|---|---|---|
| committer | alex <[email protected]> | 2018-01-08 19:18:13 +0100 |
| commit | 6587655bf90d662191538b11884311e5aff4b120 (patch) | |
| tree | c27db8c664503cc9d18c49ce601ed66c06ce2fd7 /src | |
| parent | Set a travis caching timeout of 900 seconds (diff) | |
| download | serenity-6587655bf90d662191538b11884311e5aff4b120.tar.xz serenity-6587655bf90d662191538b11884311e5aff4b120.zip | |
Allow channels to be moved in and out of a category (#248)
Diffstat (limited to 'src')
| -rw-r--r-- | src/builder/edit_channel.rs | 18 | ||||
| -rw-r--r-- | src/model/guild/guild_id.rs | 6 | ||||
| -rw-r--r-- | src/model/guild/mod.rs | 7 | ||||
| -rw-r--r-- | src/model/guild/partial_guild.rs | 7 |
4 files changed, 30 insertions, 8 deletions
diff --git a/src/builder/edit_channel.rs b/src/builder/edit_channel.rs index 17df18d..2ea5707 100644 --- a/src/builder/edit_channel.rs +++ b/src/builder/edit_channel.rs @@ -1,5 +1,6 @@ use internal::prelude::*; use utils::VecMap; +use model::id::ChannelId; /// A builder to edit a [`GuildChannel`] for use via [`GuildChannel::edit`] /// @@ -72,4 +73,21 @@ impl EditChannel { self } + + /// The parent category of the channel. + /// + /// This is for [text] and [voice] channels only. + /// + /// [text]: ../model/enum.ChannelType.html#variant.Text + /// [voice]: ../model/enum.ChannelType.html#variant.Voice + pub fn category<C>(mut self, category: C) -> Self + where C: Into<Option<ChannelId>> { + let parent_id = match category.into() { + Some(c) => Value::Number(Number::from(c.0)), + None => Value::Null + }; + self.0.insert("parent_id", parent_id); + + self + } } diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs index 48ad55b..a86b6a9 100644 --- a/src/model/guild/guild_id.rs +++ b/src/model/guild/guild_id.rs @@ -107,16 +107,18 @@ impl GuildId { /// ```rust,ignore /// use serenity::model::{ChannelType, GuildId}; /// - /// let _channel = GuildId(7).create_channel("test", ChannelType::Voice); + /// let _channel = GuildId(7).create_channel("test", ChannelType::Voice, None); /// ``` /// /// [`GuildChannel`]: struct.GuildChannel.html /// [`http::create_channel`]: ../http/fn.create_channel.html /// [Manage Channels]: permissions/constant.MANAGE_CHANNELS.html - pub fn create_channel(&self, name: &str, kind: ChannelType) -> Result<GuildChannel> { + pub fn create_channel<C>(&self, name: &str, kind: ChannelType, category: C) -> Result<GuildChannel> + where C: Into<Option<ChannelId>> { let map = json!({ "name": name, "type": kind as u8, + "parent_id": category.into().map(|c| c.0) }); http::create_channel(self.0, &map) diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index d6cd75d..f514864 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -332,7 +332,7 @@ impl Guild { /// /// // assuming a `guild` has already been bound /// - /// let _ = guild.create_channel("my-test-channel", ChannelType::Text); + /// let _ = guild.create_channel("my-test-channel", ChannelType::Text, None); /// ``` /// /// # Errors @@ -343,7 +343,8 @@ impl Guild { /// [`Channel`]: struct.Channel.html /// [`ModelError::InvalidPermissions`]: enum.ModelError.html#variant.InvalidPermissions /// [Manage Channels]: permissions/constant.MANAGE_CHANNELS.html - pub fn create_channel(&self, name: &str, kind: ChannelType) -> Result<GuildChannel> { + pub fn create_channel<C>(&self, name: &str, kind: ChannelType, category: C) -> Result<GuildChannel> + where C: Into<Option<ChannelId>> { #[cfg(feature = "cache")] { let req = Permissions::MANAGE_CHANNELS; @@ -353,7 +354,7 @@ impl Guild { } } - self.id.create_channel(name, kind) + self.id.create_channel(name, kind, category) } /// Creates an emoji in the guild with a name and base64-encoded image. The diff --git a/src/model/guild/partial_guild.rs b/src/model/guild/partial_guild.rs index e67ca03..aebd6e7 100644 --- a/src/model/guild/partial_guild.rs +++ b/src/model/guild/partial_guild.rs @@ -96,15 +96,16 @@ impl PartialGuild { /// ```rust,ignore /// use serenity::model::ChannelType; /// - /// guild.create_channel("test", ChannelType::Voice); + /// guild.create_channel("test", ChannelType::Voice, None); /// ``` /// /// [`GuildChannel`]: struct.GuildChannel.html /// [`http::create_channel`]: ../http/fn.create_channel.html /// [Manage Channels]: permissions/constant.MANAGE_CHANNELS.html #[inline] - pub fn create_channel(&self, name: &str, kind: ChannelType) -> Result<GuildChannel> { - self.id.create_channel(name, kind) + pub fn create_channel<C>(&self, name: &str, kind: ChannelType, category: C) -> Result<GuildChannel> + where C: Into<Option<ChannelId>> { + self.id.create_channel(name, kind, category) } /// Creates an emoji in the guild with a name and base64-encoded image. |