aboutsummaryrefslogtreecommitdiff
path: root/src/builder/edit_channel.rs
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-05-22 17:02:00 -0700
committerZeyla Hellyer <[email protected]>2017-05-22 17:02:00 -0700
commit9969be60cf320797c37b317da24d9a08fd5eafa5 (patch)
treef27bf7a57af95bbc11990b1edcea9cca99276964 /src/builder/edit_channel.rs
parentReasonably derive Debug on items (diff)
downloadserenity-9969be60cf320797c37b317da24d9a08fd5eafa5.tar.xz
serenity-9969be60cf320797c37b317da24d9a08fd5eafa5.zip
Restructure modules
Modules are now separated into a fashion where the library can be used for most use cases, without needing to compile the rest. The core of serenity, with no features enabled, contains only the struct (model) definitions, constants, and prelude. Models do not have most functions compiled in, as that is separated into the `model` feature. The `client` module has been split into 3 modules: `client`, `gateway`, and `http`. `http` contains functions to interact with the REST API. `gateway` contains the Shard to interact with the gateway, requiring `http` for retrieving the gateway URL. `client` requires both of the other features and acts as an abstracted interface over both the gateway and REST APIs, handling the event loop. The `builder` module has been separated from `utils`, and can now be optionally compiled in. It and the `http` feature are required by the `model` feature due to a large number of methods requiring access to them. `utils` now contains a number of utilities, such as the Colour struct, the `MessageBuilder`, and mention parsing functions. Each of the original `ext` modules are still featured, with `cache` not requiring any feature to be enabled, `framework` requiring the `client`, `model`, and `utils`, and `voice` requiring `gateway`. In total the features and their requirements are: - `builder`: none - `cache`: none - `client`: `gateway`, `http` - `framework`: `client`, `model`, `utils` - `gateway`: `http` - `http`: none - `model`: `builder`, `http` - `utils`: none - `voice`: `gateway` The default features are `builder`, `cache`, `client`, `framework`, `gateway`, `model`, `http`, and `utils`. To help with forwards compatibility, modules have been re-exported from their original locations.
Diffstat (limited to 'src/builder/edit_channel.rs')
-rw-r--r--src/builder/edit_channel.rs80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/builder/edit_channel.rs b/src/builder/edit_channel.rs
new file mode 100644
index 0000000..2bf8979
--- /dev/null
+++ b/src/builder/edit_channel.rs
@@ -0,0 +1,80 @@
+use ::internal::prelude::*;
+
+/// A builder to edit a [`GuildChannel`] for use via one of a couple methods.
+///
+/// These methods are:
+///
+/// - [`Context::edit_channel`]
+/// - [`GuildChannel::edit`]
+///
+/// Defaults are not directly provided by the builder itself.
+///
+/// # Examples
+///
+/// Edit a channel, providing a new name and topic:
+///
+/// ```rust,ignore
+/// // assuming a channel has already been bound
+/// if let Err(why) = channel::edit(|c| c.name("new name").topic("a test topic")) {
+/// // properly handle the error
+/// }
+/// ```
+///
+/// [`Context::edit_channel`]: ../client/struct.Context.html#method.edit_channel
+/// [`GuildChannel`]: ../model/struct.GuildChannel.html
+/// [`GuildChannel::edit`]: ../model/struct.GuildChannel.html#method.edit
+#[derive(Clone, Debug, Default)]
+pub struct EditChannel(pub JsonMap);
+
+impl EditChannel {
+ /// The bitrate of the channel in bits.
+ ///
+ /// This is for [voice] channels only.
+ ///
+ /// [voice]: ../model/enum.ChannelType.html#variant.Voice
+ pub fn bitrate(mut self, bitrate: u64) -> Self {
+ self.0.insert("bitrate".to_owned(), Value::Number(Number::from(bitrate)));
+
+ self
+ }
+
+ /// The name of the channel.
+ ///
+ /// Must be between 2 and 100 characters long.
+ pub fn name(mut self, name: &str) -> Self {
+ self.0.insert("name".to_owned(), Value::String(name.to_owned()));
+
+ self
+ }
+
+ /// The position of the channel in the channel list.
+ pub fn position(mut self, position: u64) -> Self {
+ self.0.insert("position".to_owned(), Value::Number(Number::from(position)));
+
+ self
+ }
+
+ /// The topic of the channel. Can be empty.
+ ///
+ /// Must be between 0 and 1024 characters long.
+ ///
+ /// This is for [text] channels only.
+ ///
+ /// [text]: ../model/enum.ChannelType.html#variant.Text
+ pub fn topic(mut self, topic: &str) -> Self {
+ self.0.insert("topic".to_owned(), Value::String(topic.to_owned()));
+
+ self
+ }
+
+ /// The number of users that may be in the channel simultaneously.
+ ///
+ /// This is for [voice] channels only.
+ ///
+ /// [voice]: ../model/enum.ChannelType.html#variant.Voice
+ pub fn user_limit(mut self, user_limit: u64) -> Self {
+ self.0.insert("user_limit".to_owned(), Value::Number(Number::from(user_limit)));
+
+ self
+ }
+}