aboutsummaryrefslogtreecommitdiff
path: root/src/utils/builder/edit_guild.rs
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-13 08:22:24 -0800
committerAustin Hellyer <[email protected]>2016-11-13 08:22:24 -0800
commitf633d1c9603079f584f4f715b308b33c0750ad3a (patch)
treef77bc0b630731676be880b11c24b90cffef8c537 /src/utils/builder/edit_guild.rs
parentDon't overflow on message length check (diff)
downloadserenity-f633d1c9603079f584f4f715b308b33c0750ad3a.tar.xz
serenity-f633d1c9603079f584f4f715b308b33c0750ad3a.zip
Move the builders to the utils
The builders aren't a large enough portion of the library to deserve their own root-level module, so move them to the `utils` module. Additionally, split them into separate files, as the library will be receiving more builders and the single-file pattern was getting rather large.
Diffstat (limited to 'src/utils/builder/edit_guild.rs')
-rw-r--r--src/utils/builder/edit_guild.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/utils/builder/edit_guild.rs b/src/utils/builder/edit_guild.rs
new file mode 100644
index 0000000..3ea9aaa
--- /dev/null
+++ b/src/utils/builder/edit_guild.rs
@@ -0,0 +1,53 @@
+use serde_json::builder::ObjectBuilder;
+use serde_json::Value;
+use std::default::Default;
+use ::model::{ChannelId, Region, VerificationLevel};
+
+pub struct EditGuild(pub ObjectBuilder);
+
+impl EditGuild {
+ pub fn afk_channel<C: Into<ChannelId>>(self, channel: Option<C>) -> Self {
+ EditGuild(match channel {
+ Some(channel) => self.0.insert("afk_channel_id", channel.into().0),
+ None => self.0.insert("afk-channel_id", Value::Null),
+ })
+ }
+
+ pub fn afk_timeout(self, timeout: u64) -> Self {
+ EditGuild(self.0.insert("afk_timeout", timeout))
+ }
+
+ pub fn icon(self, icon: Option<&str>) -> Self {
+ EditGuild(self.0
+ .insert("icon",
+ icon.map_or_else(|| Value::Null,
+ |x| Value::String(x.to_owned()))))
+ }
+
+ pub fn name(self, name: &str) -> Self {
+ EditGuild(self.0.insert("name", name))
+ }
+
+ pub fn region(self, region: Region) -> Self {
+ EditGuild(self.0.insert("region", region.name()))
+ }
+
+ pub fn splash(self, splash: Option<&str>) -> Self {
+ EditGuild(self.0
+ .insert("splash",
+ splash.map_or_else(|| Value::Null,
+ |x| Value::String(x.to_owned()))))
+ }
+
+ pub fn verification_level<V>(self, verification_level: V) -> Self
+ where V: Into<VerificationLevel> {
+ EditGuild(self.0.insert("verification_level",
+ verification_level.into().num()))
+ }
+}
+
+impl Default for EditGuild {
+ fn default() -> EditGuild {
+ EditGuild(ObjectBuilder::new())
+ }
+}