diff options
| author | Zeyla Hellyer <[email protected]> | 2018-01-27 19:14:14 -0800 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2018-01-27 19:14:14 -0800 |
| commit | ab1f11a37d64166c08f833042d7b3bcde2ea586d (patch) | |
| tree | 5275310e98869bed0c9d9e02cd4c71654cdd924b /src | |
| parent | Check message ID count in `delete_messages` (diff) | |
| download | serenity-ab1f11a37d64166c08f833042d7b3bcde2ea586d.tar.xz serenity-ab1f11a37d64166c08f833042d7b3bcde2ea586d.zip | |
Add functions to reorder a guild's channels
Add `http::edit_guild_channel_positions`, `Guild::reorder_channels`, and
`GuildId::reorder_channels`.
Diffstat (limited to 'src')
| -rw-r--r-- | src/http/mod.rs | 16 | ||||
| -rw-r--r-- | src/model/guild/guild_id.rs | 18 | ||||
| -rw-r--r-- | src/model/guild/mod.rs | 10 |
3 files changed, 44 insertions, 0 deletions
diff --git a/src/http/mod.rs b/src/http/mod.rs index 8abed78..b1a8379 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -708,6 +708,22 @@ pub fn edit_guild(guild_id: u64, map: &JsonMap) -> Result<PartialGuild> { .map_err(From::from) } +/// Edits the positions of a guild's channels. +pub fn edit_guild_channel_positions(guild_id: u64, value: &Value) + -> Result<()> { + let body = serde_json::to_string(value)?; + + verify( + 204, + request!( + Route::GuildsIdChannels(guild_id), + patch(body), + "/guilds/{}/channels", + guild_id, + ), + ) +} + /// Edits a [`Guild`]'s embed setting. /// /// [`Guild`]: ../model/struct.Guild.html 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<It>(&self, channels: It) -> Result<()> + where It: IntoIterator<Item = (ChannelId, u64)> { + 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<It>(&self, channels: It) -> Result<()> + where It: IntoIterator<Item = (ChannelId, u64)> { + 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 |