From ab1f11a37d64166c08f833042d7b3bcde2ea586d Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Sat, 27 Jan 2018 19:14:14 -0800 Subject: Add functions to reorder a guild's channels Add `http::edit_guild_channel_positions`, `Guild::reorder_channels`, and `GuildId::reorder_channels`. --- src/model/guild/guild_id.rs | 18 ++++++++++++++++++ src/model/guild/mod.rs | 10 ++++++++++ 2 files changed, 28 insertions(+) (limited to 'src/model') diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs index a86b6a9..3cce275 100644 --- a/src/model/guild/guild_id.rs +++ b/src/model/guild/guild_id.rs @@ -433,6 +433,24 @@ impl GuildId { http::get_guild_prune_count(self.0, &map) } + /// Re-orders the channels of the guild. + /// + /// Accepts an iterator of a tuple of the channel ID to modify and its new + /// position. + /// + /// Although not required, you should specify all channels' positions, + /// regardless of whether they were updated. Otherwise, positioning can + /// sometimes get weird. + pub fn reorder_channels(&self, channels: It) -> Result<()> + where It: IntoIterator { + let items = channels.into_iter().map(|(id, pos)| json!({ + "id": id, + "position": pos, + })).collect(); + + http::edit_guild_channel_positions(self.0, &Value::Array(items)) + } + /// Returns the Id of the shard associated with the guild. /// /// When the cache is enabled this will automatically retrieve the total diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index 9d576ea..9a51956 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -1343,6 +1343,16 @@ impl Guild { self.id.prune_count(days) } + /// Re-orders the channels of the guild. + /// + /// Although not required, you should specify all channels' positions, + /// regardless of whether they were updated. Otherwise, positioning can + /// sometimes get weird. + pub fn reorder_channels(&self, channels: It) -> Result<()> + where It: IntoIterator { + self.id.reorder_channels(channels) + } + /// Returns the Id of the shard associated with the guild. /// /// When the cache is enabled this will automatically retrieve the total -- cgit v1.2.3