aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-01-27 19:14:14 -0800
committerZeyla Hellyer <[email protected]>2018-01-27 19:14:14 -0800
commitab1f11a37d64166c08f833042d7b3bcde2ea586d (patch)
tree5275310e98869bed0c9d9e02cd4c71654cdd924b /src/model
parentCheck message ID count in `delete_messages` (diff)
downloadserenity-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/model')
-rw-r--r--src/model/guild/guild_id.rs18
-rw-r--r--src/model/guild/mod.rs10
2 files changed, 28 insertions, 0 deletions
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