aboutsummaryrefslogtreecommitdiff
path: root/src/utils/builder
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/builder')
-rw-r--r--src/utils/builder/create_embed.rs391
-rw-r--r--src/utils/builder/create_invite.rs84
-rw-r--r--src/utils/builder/create_message.rs86
-rw-r--r--src/utils/builder/edit_channel.rs80
-rw-r--r--src/utils/builder/edit_guild.rs165
-rw-r--r--src/utils/builder/edit_member.rs71
-rw-r--r--src/utils/builder/edit_profile.rs93
-rw-r--r--src/utils/builder/edit_role.rs125
-rw-r--r--src/utils/builder/execute_webhook.rs129
-rw-r--r--src/utils/builder/get_messages.rs75
-rw-r--r--src/utils/builder/mod.rs33
11 files changed, 0 insertions, 1332 deletions
diff --git a/src/utils/builder/create_embed.rs b/src/utils/builder/create_embed.rs
deleted file mode 100644
index 457a960..0000000
--- a/src/utils/builder/create_embed.rs
+++ /dev/null
@@ -1,391 +0,0 @@
-//! Developer note:
-//!
-//! This is a set of embed builders for rich embeds.
-//!
-//! These are used in the [`Context::send_message`] and
-//! [`ExecuteWebhook::embeds`] methods, both as part of builders.
-//!
-//! The only builder that should be exposed is [`CreateEmbed`]. The rest of
-//! these have no real reason for being exposed, but are for completeness' sake.
-//!
-//! Documentation for embeds can be found [here].
-//!
-//! [`Context::send_message`]: ../../client/struct.Context.html#method.send_message
-//! [`CreateEmbed`]: struct.CreateEmbed.html
-//! [`ExecuteWebhook::embeds`]: struct.ExecuteWebhook.html#method.embeds
-//! [here]: https://discordapp.com/developers/docs/resources/channel#embed-object
-
-use serde_json::Value;
-use std::default::Default;
-use time::Tm;
-use ::internal::prelude::*;
-use ::model::Embed;
-use ::utils::Colour;
-
-/// A builder to create a fake [`Embed`] object, for use with the
-/// [`Context::send_message`] and [`ExecuteWebhook::embeds`] methods.
-///
-/// # Examples
-///
-/// Refer to the documentation for [`Context::send_message`] for a very in-depth
-/// example on how to use this.
-///
-/// [`Context::send_message`]: ../../client/struct.Context.html#method.send_message
-/// [`Embed`]: ../../model/struct.Embed.html
-/// [`ExecuteWebhook::embeds`]: struct.ExecuteWebhook.html#method.embeds
-#[derive(Clone, Debug)]
-pub struct CreateEmbed(pub Map<String, Value>);
-
-impl CreateEmbed {
- /// Set the author of the embed.
- ///
- /// Refer to the documentation for [`CreateEmbedAuthor`] for more
- /// information.
- ///
- /// [`CreateEmbedAuthor`]: struct.CreateEmbedAuthor.html
- pub fn author<F>(mut self, f: F) -> Self
- where F: FnOnce(CreateEmbedAuthor) -> CreateEmbedAuthor {
- let author = f(CreateEmbedAuthor::default()).0;
-
- self.0.insert("author".to_owned(), Value::Object(author));
-
- CreateEmbed(self.0)
- }
-
- /// Set the colour of the left-hand side of the embed.
- ///
- /// This is an alias of [`colour`].
- ///
- /// [`colour`]: #method.colour
- pub fn color<C: Into<Colour>>(self, colour: C) -> Self {
- self.colour(colour.into())
- }
-
- /// Set the colour of the left-hand side of the embed.
- pub fn colour<C: Into<Colour>>(mut self, colour: C) -> Self {
- self.0.insert("color".to_owned(), Value::Number(Number::from(colour.into().0 as u64)));
-
- CreateEmbed(self.0)
- }
-
- /// Set the description of the embed.
- ///
- /// **Note**: This can't be longer than 2048 characters.
- pub fn description(mut self, description: &str) -> Self {
- self.0.insert("description".to_owned(), Value::String(description.to_owned()));
-
- CreateEmbed(self.0)
- }
-
- /// Set a field. Note that this will not overwrite other fields, and will
- /// add to them.
- ///
- /// Refer to the documentation for [`CreateEmbedField`] for more
- /// information.
- ///
- /// **Note**: Maximum amount of characters you can put is 256 in a field
- /// name and 1024 in a field value and a field is inline by default.
- ///
- /// [`CreateEmbedField`]: struct.CreateEmbedField.html
- pub fn field<F>(mut self, f: F) -> Self
- where F: FnOnce(CreateEmbedField) -> CreateEmbedField {
- let field = f(CreateEmbedField::default()).0;
-
- {
- let key = "fields".to_owned();
-
- let entry = self.0.remove(&key).unwrap_or_else(|| Value::Array(vec![]));
- let mut arr = match entry {
- Value::Array(inner) => inner,
- _ => {
- // The type of `entry` should always be a `Value::Array`.
- //
- // Theoretically this never happens, but you never know.
- //
- // In the event that it does, just return the current value.
- return CreateEmbed(self.0);
- },
- };
- arr.push(Value::Object(field));
-
- self.0.insert("fields".to_owned(), Value::Array(arr));
- }
-
- CreateEmbed(self.0)
- }
-
- /// Set the footer of the embed.
- ///
- /// Refer to the documentation for [`CreateEmbedFooter`] for more
- /// information.
- ///
- /// [`CreateEmbedFooter`]: struct.CreateEmbedFooter.html
- pub fn footer<F>(mut self, f: F) -> Self
- where F: FnOnce(CreateEmbedFooter) -> CreateEmbedFooter {
- let footer = f(CreateEmbedFooter::default()).0;
-
- self.0.insert("footer".to_owned(), Value::Object(footer));
-
- CreateEmbed(self.0)
- }
-
- /// Set the image associated with the embed. This only supports HTTP(S).
- pub fn image(mut self, url: &str) -> Self {
- let image = json!({
- "url": url.to_owned()
- });
-
- self.0.insert("image".to_owned(), image);
-
- CreateEmbed(self.0)
- }
-
- /// Set the thumbnail of the embed. This only supports HTTP(S).
- pub fn thumbnail(mut self, url: &str) -> Self {
- let thumbnail = json!({
- "url": url.to_owned(),
- });
-
- self.0.insert("thumbnail".to_owned(), thumbnail);
-
- CreateEmbed(self.0)
- }
-
- /// Set the timestamp.
- ///
- /// **Note**: This timestamp must be in ISO-8601 format. It must also be
- /// in UTC format.
- ///
- /// # Examples
- ///
- /// You may pass a direct string:
- ///
- /// - `2017-01-03T23:00:00`
- /// - `2004-06-08T16:04:23`
- /// - `2004-06-08T16:04:23`
- ///
- /// Or a `time::Tm`:
- ///
- /// ```rust,ignore
- /// extern crate time;
- ///
- /// let now = time::now();
- ///
- /// embed = embed.timestamp(now);
- /// // ...
- /// ```
- pub fn timestamp<T: Into<Timestamp>>(mut self, timestamp: T) -> Self {
- self.0.insert("timestamp".to_owned(), Value::String(timestamp.into().ts));
-
- CreateEmbed(self.0)
- }
-
- /// Set the title of the embed.
- pub fn title(mut self, title: &str) -> Self {
- self.0.insert("title".to_owned(), Value::String(title.to_owned()));
-
- CreateEmbed(self.0)
- }
-
- /// Set the URL to direct to when clicking on the title.
- pub fn url(mut self, url: &str) -> Self {
- self.0.insert("url".to_owned(), Value::String(url.to_owned()));
-
- CreateEmbed(self.0)
- }
-}
-
-impl Default for CreateEmbed {
- /// Creates a builder with default values, setting the `type` to `rich`.
- fn default() -> CreateEmbed {
- let mut map = Map::new();
- map.insert("type".to_owned(), Value::String("rich".to_owned()));
-
- CreateEmbed(map)
- }
-}
-
-impl From<Embed> for CreateEmbed {
- /// Converts the fields of an embed into the values for a new embed builder.
- ///
- /// Some values - such as Proxy URLs - are not preserved.
- fn from(embed: Embed) -> CreateEmbed {
- let mut b = CreateEmbed::default()
- .colour(embed.colour);
-
- if let Some(author) = embed.author {
- b = b.author(move |mut a| {
- a = a.name(&author.name);
-
- if let Some(icon_url) = author.icon_url {
- a = a.icon_url(&icon_url);
- }
-
- if let Some(url) = author.url {
- a = a.url(&url);
- }
-
- a
- });
- }
-
- if let Some(description) = embed.description {
- b = b.description(&description);
- }
-
- for field in embed.fields {
- b = b.field(move |f| f
- .inline(field.inline)
- .name(&field.name)
- .value(&field.value));
- }
-
- if let Some(image) = embed.image {
- b = b.image(&image.url);
- }
-
- if let Some(timestamp) = embed.timestamp {
- b = b.timestamp(timestamp);
- }
-
- if let Some(thumbnail) = embed.thumbnail {
- b = b.thumbnail(&thumbnail.url);
- }
-
- if let Some(url) = embed.url {
- b = b.url(&url);
- }
-
- if let Some(title) = embed.title {
- b = b.title(&title);
- }
-
- b
- }
-}
-
-/// A builder to create a fake [`Embed`] object's author, for use with the
-/// [`CreateEmbed::author`] method.
-///
-/// Requires that you specify a [`name`].
-///
-/// [`Embed`]: ../../model/struct.Embed.html
-/// [`CreateEmbed::author`]: struct.CreateEmbed.html#method.author
-/// [`name`]: #method.name
-#[derive(Clone, Debug, Default)]
-pub struct CreateEmbedAuthor(pub Map<String, Value>);
-
-impl CreateEmbedAuthor {
- /// Set the URL of the author's icon.
- pub fn icon_url(mut self, icon_url: &str) -> Self {
- self.0.insert("icon_url".to_owned(), Value::String(icon_url.to_owned()));
-
- self
- }
-
- /// Set the author's name.
- pub fn name(mut self, name: &str) -> Self {
- self.0.insert("name".to_owned(), Value::String(name.to_owned()));
-
- self
- }
-
- /// Set the author's URL.
- pub fn url(mut self, url: &str) -> Self {
- self.0.insert("url".to_owned(), Value::String(url.to_owned()));
-
- self
- }
-}
-
-/// A builder to create a fake [`Embed`] object's field, for use with the
-/// [`CreateEmbed::field`] method.
-///
-/// This does not require any field be set. `inline` is set to `true` by
-/// default.
-///
-/// [`Embed`]: ../../model/struct.Embed.html
-/// [`CreateEmbed::field`]: struct.CreateEmbed.html#method.field
-#[derive(Clone, Debug)]
-pub struct CreateEmbedField(pub Map<String, Value>);
-
-impl CreateEmbedField {
- /// Set whether the field is inlined. Set to true by default.
- pub fn inline(mut self, inline: bool) -> Self {
- self.0.insert("inline".to_owned(), Value::Bool(inline));
-
- self
- }
-
- /// Set the field's name. It can't be longer than 256 characters.
- pub fn name(mut self, name: &str) -> Self {
- self.0.insert("name".to_owned(), Value::String(name.to_owned()));
-
- self
- }
-
- /// Set the field's value. It can't be longer than 1024 characters.
- pub fn value(mut self, value: &str) -> Self {
- self.0.insert("value".to_owned(), Value::String(value.to_owned()));
-
- self
- }
-}
-
-impl Default for CreateEmbedField {
- /// Creates a builder with default values, setting the value of `inline` to
- /// `true`.
- fn default() -> CreateEmbedField {
- let mut map = Map::new();
- map.insert("inline".to_owned(), Value::Bool(true));
-
- CreateEmbedField(map)
- }
-}
-
-/// A builder to create a fake [`Embed`] object's footer, for use with the
-/// [`CreateEmbed::footer`] method.
-///
-/// This does not require any field be set.
-///
-/// [`Embed`]: ../../model/struct.Embed.html
-/// [`CreateEmbed::footer`]: struct.CreateEmbed.html#method.footer
-#[derive(Clone, Debug, Default)]
-pub struct CreateEmbedFooter(pub Map<String, Value>);
-
-impl CreateEmbedFooter {
- /// Set the icon URL's value. This only supports HTTP(S).
- pub fn icon_url(mut self, icon_url: &str) -> Self {
- self.0.insert("icon_url".to_owned(), Value::String(icon_url.to_owned()));
-
- self
- }
-
- /// Set the footer's text.
- pub fn text(mut self, text: &str) -> Self {
- self.0.insert("text".to_owned(), Value::String(text.to_owned()));
-
- self
- }
-}
-
-#[derive(Clone, Debug)]
-pub struct Timestamp {
- pub ts: String,
-}
-
-impl From<String> for Timestamp {
- fn from(ts: String) -> Self {
- Timestamp {
- ts: ts,
- }
- }
-}
-
-impl From<Tm> for Timestamp {
- fn from(tm: Tm) -> Self {
- Timestamp {
- ts: tm.to_utc().rfc3339().to_string(),
- }
- }
-}
diff --git a/src/utils/builder/create_invite.rs b/src/utils/builder/create_invite.rs
deleted file mode 100644
index 6ff2a67..0000000
--- a/src/utils/builder/create_invite.rs
+++ /dev/null
@@ -1,84 +0,0 @@
-use serde_json::Value;
-use std::default::Default;
-use ::internal::prelude::*;
-
-/// A builder to create a [`RichInvite`] for use via [`Context::create_invite`].
-///
-/// This is a structured and cleaner way of creating an invite, as all
-/// parameters are optional.
-///
-/// # Examples
-///
-/// Create an invite with a max age of 3600 seconds and 10 max uses:
-///
-/// ```rust,ignore
-/// use serenity::Client;
-/// use std::env;
-///
-/// let mut client = Client::login(&env::var("DISCORD_BOT_TOKEN").unwrap());
-///
-/// client.on_message(|_, message| {
-/// if message.content == "!invite" {
-/// let invite = message.channel_id.create_invite(|i| i
-/// .max_age(3600)
-/// .max_uses(10));
-/// }
-/// });
-/// ```
-///
-/// [`Context::create_invite`]: ../../client/struct.Context.html#method.create_invite
-/// [`RichInvite`]: ../../model/struct.Invite.html
-#[derive(Clone, Debug)]
-pub struct CreateInvite(pub JsonMap);
-
-impl CreateInvite {
- /// The duration that the invite will be valid for.
- ///
- /// Set to `0` for an invite which does not expire after an amount of time.
- ///
- /// Defaults to `86400`, or 24 hours.
- pub fn max_age(mut self, max_age: u64) -> Self {
- self.0.insert("max_age".to_owned(), Value::Number(Number::from(max_age)));
-
- self
- }
-
- /// The number of uses that the invite will be valid for.
- ///
- /// Set to `0` for an invite which does not expire after a number of uses.
- ///
- /// Defaults to `0`.
- pub fn max_uses(mut self, max_uses: u64) -> Self {
- self.0.insert("max_uses".to_owned(), Value::Number(Number::from(max_uses)));
-
- self
- }
-
- /// Whether an invite grants a temporary membership.
- ///
- /// Defaults to `false`.
- pub fn temporary(mut self, temporary: bool) -> Self {
- self.0.insert("temporary".to_owned(), Value::Bool(temporary));
-
- self
- }
-
- /// Whether or not to try to reuse a similar invite.
- ///
- /// Defaults to `false`.
- pub fn unique(mut self, unique: bool) -> Self {
- self.0.insert("unique".to_owned(), Value::Bool(unique));
-
- self
- }
-}
-
-impl Default for CreateInvite {
- /// Creates a builder with default values, setting `validate` to `null`.
- fn default() -> CreateInvite {
- let mut map = Map::new();
- map.insert("validate".to_owned(), Value::Null);
-
- CreateInvite(map)
- }
-}
diff --git a/src/utils/builder/create_message.rs b/src/utils/builder/create_message.rs
deleted file mode 100644
index 5c3b6eb..0000000
--- a/src/utils/builder/create_message.rs
+++ /dev/null
@@ -1,86 +0,0 @@
-use super::CreateEmbed;
-use ::internal::prelude::*;
-
-/// A builder to specify the contents of an [`rest::send_message`] request,
-/// primarily meant for use through [`Context::send_message`].
-///
-/// There are two situations where different field requirements are present:
-///
-/// 1. When sending an [`embed`], no other field is required;
-/// 2. Otherwise, [`content`] is the only required field that is required to be
-/// set.
-///
-/// Note that if you only need to send the content of a message, without
-/// specifying other fields, then [`Context::say`] may be a more preferable
-/// option.
-///
-/// # Examples
-///
-/// Sending a message with a content of `"test"` and applying text-to-speech:
-///
-/// ```rust,no_run
-/// use serenity::model::ChannelId;
-///
-/// let channel_id = ChannelId(7);
-///
-/// let _ = channel_id.send_message(|m| m
-/// .content("test")
-/// .tts(true)
-/// .embed(|e| e
-/// .title("This is an embed")
-/// .description("With a description")));
-/// ```
-///
-/// [`Context::say`]: ../../client/struct.Context.html#method.say
-/// [`Context::send_message`]: ../../client/struct.Context.html#method.send_message
-/// [`content`]: #method.content
-/// [`embed`]: #method.embed
-/// [`rest::send_message`]: ../../client/rest/fn.send_message.html
-#[derive(Clone, Debug)]
-pub struct CreateMessage(pub Map<String, Value>);
-
-impl CreateMessage {
- /// Set the content of the message.
- ///
- /// **Note**: Message contents must be under 2000 unicode code points.
- pub fn content(mut self, content: &str) -> Self {
- self.0.insert("content".to_owned(), Value::String(content.to_owned()));
-
- CreateMessage(self.0)
- }
-
- /// Set an embed for the message.
- pub fn embed<F>(mut self, f: F) -> Self
- where F: FnOnce(CreateEmbed) -> CreateEmbed {
- let embed = Value::Object(f(CreateEmbed::default()).0);
-
- self.0.insert("embed".to_owned(), embed);
-
- CreateMessage(self.0)
- }
-
- /// Set whether the message is text-to-speech.
- ///
- /// Think carefully before setting this to `true`.
- ///
- /// Defaults to `false`.
- pub fn tts(mut self, tts: bool) -> Self {
- self.0.insert("tts".to_owned(), Value::Bool(tts));
-
- CreateMessage(self.0)
- }
-}
-
-impl Default for CreateMessage {
- /// Creates a map for sending a [`Message`], setting [`tts`] to `false` by
- /// default.
- ///
- /// [`Message`]: ../../model/struct.Message.html
- /// [`tts`]: #method.tts
- fn default() -> CreateMessage {
- let mut map = Map::default();
- map.insert("tts".to_owned(), Value::Bool(false));
-
- CreateMessage(map)
- }
-}
diff --git a/src/utils/builder/edit_channel.rs b/src/utils/builder/edit_channel.rs
deleted file mode 100644
index 4d0955e..0000000
--- a/src/utils/builder/edit_channel.rs
+++ /dev/null
@@ -1,80 +0,0 @@
-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
- }
-}
diff --git a/src/utils/builder/edit_guild.rs b/src/utils/builder/edit_guild.rs
deleted file mode 100644
index e423fc2..0000000
--- a/src/utils/builder/edit_guild.rs
+++ /dev/null
@@ -1,165 +0,0 @@
-use ::internal::prelude::*;
-use ::model::{ChannelId, Region, UserId, VerificationLevel};
-
-/// A builder to optionally edit certain fields of a [`Guild`]. This is meant
-/// for usage with [`Context::edit_guild`] and [`LiveGuild::edit`].
-///
-/// **Note**: Editing a guild requires that the current user have the
-/// [Manage Guild] permission.
-///
-/// [`Context::edit_guild`]: ../../client/struct.Context.html
-/// [`Guild`]: ../../model/struct.Guild.html
-/// [`LiveGuild::edit`]: ../../model/struct.LiveGuild.html#method.edit
-/// [Manage Guild]: ../../model/permissions/constant.MANAGE_GUILD.html
-#[derive(Clone, Debug, Default)]
-pub struct EditGuild(pub Map<String, Value>);
-
-impl EditGuild {
- /// Set the "AFK voice channel" that users are to move to if they have been
- /// AFK for an amount of time, configurable by [`afk_timeout`].
- ///
- /// The given channel must be either some valid voice channel, or `None` to
- /// not set an AFK channel. The library does not check if a channel is
- /// valid.
- ///
- /// [`afk_timeout`]: #method.afk_timeout
- pub fn afk_channel<C: Into<ChannelId>>(mut self, channel: Option<C>) -> Self {
- self.0.insert("afk_channel_id".to_owned(), match channel {
- Some(channel) => Value::Number(Number::from(channel.into().0)),
- None => Value::Null,
- });
-
- self
- }
-
- /// Set the amount of time a user is to be moved to the AFK channel -
- /// configured via [`afk_channel`] - after being AFK.
- ///
- /// [`afk_channel`]: #method.afk_channel
- pub fn afk_timeout(mut self, timeout: u64) -> Self {
- self.0.insert("afk_timeout".to_owned(), Value::Number(Number::from(timeout)));
-
- self
- }
-
- /// Set the icon of the guild. Pass `None` to remove the icon.
- ///
- /// # Examples
- ///
- /// Using the utility function - [`utils::read_image`] - to read an image
- /// from the cwd and encode it in base64 to send to Discord.
- ///
- /// ```rust,ignore
- /// use serenity::utils;
- ///
- /// // assuming a `guild` has already been bound
- ///
- /// let base64_icon = utils::read_image("./guild_icon.png")
- /// .expect("Failed to read image");
- ///
- /// let _ = guild.edit(|g| g.icon(base64_icon));
- /// ```
- ///
- /// [`utils::read_image`]: ../../utils/fn.read_image.html
- pub fn icon(mut self, icon: Option<&str>) -> Self {
- self.0.insert("icon".to_owned(), icon.map_or_else(|| Value::Null, |x| Value::String(x.to_owned())));
-
- self
- }
-
- /// Set the name of the guild.
- ///
- /// **Note**: Must be between (and including) 2-100 chracters.
- pub fn name(mut self, name: &str) -> Self {
- self.0.insert("name".to_owned(), Value::String(name.to_owned()));
-
- self
- }
-
- /// Transfers the ownership of the guild to another user by Id.
- ///
- /// **Note**: The current user must be the owner of the guild.
- pub fn owner<U: Into<UserId>>(mut self, user_id: U) -> Self {
- self.0.insert("owner_id".to_owned(), Value::Number(Number::from(user_id.into().0)));
-
- self
- }
-
- /// Set the voice region of the server.
- ///
- /// # Examples
- ///
- /// Setting the region to [`Region::UsWest`]:
- ///
- /// ```rust,ignore
- /// use serenity::model::Region;
- ///
- /// // assuming a `guild` has already been bound
- ///
- /// if let Err(why) = guild.edit(|g| g.region(Region::UsWest)) {
- /// println!("Error editing guild's region: {:?}", why);
- /// }
- /// ```
- ///
- /// [`Region::UsWest`]: ../../model/enum.Region.html#variant.UsWest
- pub fn region(mut self, region: Region) -> Self {
- self.0.insert("region".to_owned(), Value::String(region.name().to_owned()));
-
- self
- }
-
- /// Set the splash image of the guild on the invitation page.
- ///
- /// Requires that the guild have the [`InviteSplash`] feature enabled.
- /// You can check this through a guild's [`features`] list.
- ///
- /// [`InviteSplash`]: ../../model/enum.Feature.html#variant.InviteSplash
- /// [`features`]: ../../model/struct.LiveGuild.html#structfield.features
- pub fn splash(mut self, splash: Option<&str>) -> Self {
- let splash = splash.map_or(Value::Null, |x| Value::String(x.to_owned()));
-
- self.0.insert("splash".to_owned(), splash);
-
- self
- }
-
- /// Set the verification level of the guild. This can restrict what a
- /// user must have prior to being able to send messages in a guild.
- ///
- /// Refer to the documentation for [`VerificationLevel`] for more
- /// information on each variant.
- ///
- /// [`VerificationLevel`]: ../../model/enum.VerificationLevel.html
- ///
- /// # Examples
- ///
- /// Setting the verification level to [`High`][`VerificationLevel::High`]:
- ///
- /// ```rust,ignore
- /// use serenity::model::VerificationLevel;
- ///
- /// // assuming a `guild` has already been bound
- ///
- /// if let Err(why) = guild.edit(|g| g.verification_level(VerificationLevel::High)) {
- /// println!("Error setting verification level: {:?}", why);
- /// }
- ///
- /// // additionally, you may pass in just an integer of the verification
- /// // level
- ///
- /// if let Err(why) = guild.edit(|g| g.verification_level(3)) {
- /// println!("Error setting verification level: {:?}", why);
- /// }
- /// ```
- ///
- /// [`VerificationLevel`]: ../../model/enum.VerificationLevel.html
- /// [`VerificationLevel::High`]: ../../model/enum.VerificationLevel.html#variant.High
- pub fn verification_level<V>(mut self, verification_level: V) -> Self
- where V: Into<VerificationLevel> {
- let num = Value::Number(Number::from(verification_level.into().num()));
-
- self.0.insert("verification_level".to_owned(), num);
-
- self
- }
-}
diff --git a/src/utils/builder/edit_member.rs b/src/utils/builder/edit_member.rs
deleted file mode 100644
index af35bf9..0000000
--- a/src/utils/builder/edit_member.rs
+++ /dev/null
@@ -1,71 +0,0 @@
-use ::model::{ChannelId, RoleId};
-use ::internal::prelude::*;
-
-/// A builder which edits the properties of a [`Member`], to be used in
-/// conjunction with [`Context::edit_member`] and [`Member::edit`].
-///
-/// [`Context::edit_member`]: ../../client/struct.Context.html#method.edit_member
-/// [`Member`]: ../../model/struct.Member.html
-/// [`Member::edit`]: ../../model/struct.Member.html#method.edit
-#[derive(Clone, Debug, Default)]
-pub struct EditMember(pub JsonMap);
-
-impl EditMember {
- /// Whether to deafen the member.
- ///
- /// Requires the [Deafen Members] permission.
- ///
- /// [Deafen Members]: ../../model/permissions/constant.DEAFEN_MEMBERS.html
- pub fn deafen(mut self, deafen: bool) -> Self {
- self.0.insert("deaf".to_owned(), Value::Bool(deafen));
-
- self
- }
-
- /// Whether to mute the member.
- ///
- /// Requires the [Mute Members] permission.
- ///
- /// [Mute Members]: ../../model/permissions/constant.MUTE_MEMBERS.html
- pub fn mute(mut self, mute: bool) -> Self {
- self.0.insert("mute".to_owned(), Value::Bool(mute));
-
- self
- }
-
- /// Changes the member's nickname. Pass an empty string to reset the
- /// nickname.
- ///
- /// Requires the [Manage Nicknames] permission.
- ///
- /// [Manage Nicknames]: ../../model/permissions/constant.MANAGE_NICKNAMES.html
- pub fn nickname(mut self, nickname: &str) -> Self {
- self.0.insert("nick".to_owned(), Value::String(nickname.to_owned()));
-
- self
- }
-
- /// Set the list of roles that the member should have.
- ///
- /// Requires the [Manage Roles] permission to modify.
- ///
- /// [Manage Roles]: ../../model/permissions/constant.MANAGE_ROLES.html
- pub fn roles(mut self, roles: &[RoleId]) -> Self {
- let role_ids = roles.iter().map(|x| Value::Number(Number::from(x.0))).collect();
-
- self.0.insert("roles".to_owned(), Value::Array(role_ids));
-
- self
- }
-
- /// The Id of the voice channel to move the member to.
- ///
- /// Requires the [Move Members] permission.
- ///
- /// [Move Members]: ../../model/permissions/constant.MOVE_MEMBERS.html
- pub fn voice_channel<C: Into<ChannelId>>(mut self, channel_id: C) -> Self {
- self.0.insert("channel_id".to_owned(), Value::Number(Number::from(channel_id.into().0)));
-
- self
- }
-}
diff --git a/src/utils/builder/edit_profile.rs b/src/utils/builder/edit_profile.rs
deleted file mode 100644
index 64bd7a9..0000000
--- a/src/utils/builder/edit_profile.rs
+++ /dev/null
@@ -1,93 +0,0 @@
-use ::internal::prelude::*;
-
-/// A builder to edit the current user's settings, to be used in conjunction
-/// with [`Context::edit_profile`].
-///
-/// [`Context::edit_profile`]: ../../client/struct.Context.html#method.edit_profile
-#[derive(Clone, Debug, Default)]
-pub struct EditProfile(pub JsonMap);
-
-impl EditProfile {
- /// Sets the avatar of the current user. `None` can be passed to remove an
- /// avatar.
- ///
- /// A base64-encoded string is accepted as the avatar content.
- ///
- /// # Examples
- ///
- /// A utility method - [`utils::read_image`] - is provided to read an
- /// image from a file and return its contents in base64-encoded form:
- ///
- /// ```rust,ignore
- /// use serenity::utils;
- ///
- /// // assuming a `context` has been bound
- ///
- /// let base64 = utils::read_image("./my_image.jpg")
- /// .expect("Failed to read image");
- ///
- /// let _ = context.edit_profile(|profile| {
- /// profile.avatar(Some(&base64))
- /// });
- /// ```
- ///
- /// [`utils::read_image`]: ../fn.read_image.html
- pub fn avatar(mut self, avatar: Option<&str>) -> Self {
- let avatar = avatar.map_or(Value::Null, |x| Value::String(x.to_owned()));
-
- self.0.insert("avatar".to_owned(), avatar);
-
- self
- }
-
- /// Modifies the current user's email address.
- ///
- /// Note that when modifying the email address, the current password must
- /// also be [provided].
- ///
- /// No validation is performed on this by the library.
- ///
- /// **Note**: This can only be used by user accounts.
- ///
- /// [provided]: #method.password
- pub fn email(mut self, email: &str) -> Self {
- self.0.insert("email".to_owned(), Value::String(email.to_owned()));
-
- self
- }
-
- /// Modifies the current user's password.
- ///
- /// Note that when modifying the password, the current password must also be
- /// [provided].
- ///
- /// [provided]: #method.password
- pub fn new_password(mut self, new_password: &str) -> Self {
- self.0.insert("new_password".to_owned(), Value::String(new_password.to_owned()));
-
- self
- }
-
- /// Used for providing the current password as verification when
- /// [modifying the password] or [modifying the associated email address].
- ///
- /// [modifying the password]: #method.new_password
- /// [modifying the associated email address]: #method.email
- pub fn password(mut self, password: &str) -> Self {
- self.0.insert("password".to_owned(), Value::String(password.to_owned()));
-
- self
- }
-
- /// Modifies the current user's username.
- ///
- /// When modifying the username, if another user has the same _new_ username
- /// and current discriminator, a new unique discriminator will be assigned.
- /// If there are no available discriminators with the requested username,
- /// an error will occur.
- pub fn username(mut self, username: &str) -> Self {
- self.0.insert("username".to_owned(), Value::String(username.to_owned()));
-
- self
- }
-}
diff --git a/src/utils/builder/edit_role.rs b/src/utils/builder/edit_role.rs
deleted file mode 100644
index 6a44912..0000000
--- a/src/utils/builder/edit_role.rs
+++ /dev/null
@@ -1,125 +0,0 @@
-use std::default::Default;
-use ::internal::prelude::*;
-use ::model::{Permissions, Role, permissions};
-
-/// A builer to create or edit a [`Role`] for use via a number of model and
-/// context methods.
-///
-/// These are:
-///
-/// - [`Context::create_role`]
-/// - [`Context::edit_role`]
-/// - [`Guild::create_role`]
-/// - [`Role::edit`]
-///
-/// Defaults are provided for each parameter on role creation.
-///
-/// # Examples
-///
-/// Create a hoisted, mentionable role named "a test role":
-///
-/// ```rust,ignore
-/// // assuming a `channel_id` and `guild_id` has been bound
-/// let role = channel_id.create_role(guild_id, |r| r
-/// .hoist(true)
-/// .mentionable(true)
-/// .name("a test role"));
-/// ```
-///
-/// [`Context::create_role`]: ../../client/struct.Context.html#method.create_role
-/// [`Context::edit_role`]: ../../client/struct.Context.html#method.edit_role
-/// [`Guild::create_role`]: ../../model/struct.Guild.html#method.create_role
-/// [`Role`]: ../../model/struct.Role.html
-/// [`Role::edit`]: ../../model/struct.Role.html#method.edit
-#[derive(Clone, Debug)]
-pub struct EditRole(pub JsonMap);
-
-impl EditRole {
- /// Creates a new builder with the values of the given [`Role`].
- ///
- /// [`Role`]: ../../model/struct.Role.html
- pub fn new(role: &Role) -> Self {
- let mut map = Map::new();
- map.insert("color".to_owned(), Value::Number(Number::from(role.colour.0)));
- map.insert("hoist".to_owned(), Value::Bool(role.hoist));
- map.insert("managed".to_owned(), Value::Bool(role.managed));
- map.insert("mentionable".to_owned(), Value::Bool(role.mentionable));
- map.insert("name".to_owned(), Value::String(role.name.clone()));
- map.insert("permissions".to_owned(), Value::Number(Number::from(role.permissions.bits())));
- map.insert("position".to_owned(), Value::Number(Number::from(role.position)));
-
- EditRole(map)
- }
-
- /// Sets the colour of the role.
- pub fn colour(mut self, colour: u64) -> Self {
- self.0.insert("color".to_owned(), Value::Number(Number::from(colour)));
-
- self
- }
-
- /// Whether or not to hoist the role above lower-positioned role in the user
- /// list.
- pub fn hoist(mut self, hoist: bool) -> Self {
- self.0.insert("hoist".to_owned(), Value::Bool(hoist));
-
- self
- }
-
- /// Whether or not to make the role mentionable, notifying its users.
- pub fn mentionable(mut self, mentionable: bool) -> Self {
- self.0.insert("mentionable".to_owned(), Value::Bool(mentionable));
-
- self
- }
-
- /// The name of the role to set.
- pub fn name(mut self, name: &str) -> Self {
- self.0.insert("name".to_owned(), Value::String(name.to_owned()));
-
- self
- }
-
- /// The set of permissions to assign the role.
- pub fn permissions(mut self, permissions: Permissions) -> Self {
- self.0.insert("permissions".to_owned(), Value::Number(Number::from(permissions.bits())));
-
- self
- }
-
- /// The position to assign the role in the role list. This correlates to the
- /// role's position in the user list.
- pub fn position(mut self, position: u8) -> Self {
- self.0.insert("position".to_owned(), Value::Number(Number::from(position)));
-
- self
- }
-}
-
-impl Default for EditRole {
- /// Creates a builder with default parameters.
- ///
- /// The defaults are:
- ///
- /// - **color**: 10070709
- /// - **hoist**: false
- /// - **mentionable**: false
- /// - **name**: new role
- /// - **permissions**: the [general permissions set]
- /// - **position**: 1
- ///
- /// [general permissions set]: ../../model/permissions/constant.PRESET_GENERAL.html
- fn default() -> EditRole {
- let mut map = Map::new();
- let permissions = Number::from(permissions::PRESET_GENERAL.bits());
-
- map.insert("color".to_owned(), Value::Number(Number::from(10070709)));
- map.insert("hoist".to_owned(), Value::Bool(false));
- map.insert("mentionable".to_owned(), Value::Bool(false));
- map.insert("name".to_owned(), Value::String("new role".to_owned()));
- map.insert("permissions".to_owned(), Value::Number(permissions));
- map.insert("position".to_owned(), Value::Number(Number::from(1)));
-
- EditRole(map)
- }
-}
diff --git a/src/utils/builder/execute_webhook.rs b/src/utils/builder/execute_webhook.rs
deleted file mode 100644
index ee898de..0000000
--- a/src/utils/builder/execute_webhook.rs
+++ /dev/null
@@ -1,129 +0,0 @@
-use serde_json::Value;
-use std::default::Default;
-use ::internal::prelude::*;
-
-/// A builder to create the inner content of a [`Webhook`]'s execution.
-///
-/// This is a structured way of cleanly creating the inner execution payload,
-/// to reduce potential argument counts.
-///
-/// Refer to the documentation for [`execute_webhook`] on restrictions with
-/// execution payloads and its fields.
-///
-/// # Examples
-///
-/// Creating two embeds, and then sending them as part of the delivery
-/// payload of [`Webhook::execute`]:
-///
-/// ```rust,ignore
-/// use serenity::client::rest;
-/// use serenity::model::Embed;
-/// use serenity::utils::Colour;
-///
-/// let id = 245037420704169985;
-/// let token = "ig5AO-wdVWpCBtUUMxmgsWryqgsW3DChbKYOINftJ4DCrUbnkedoYZD0VOH1QLr-S3sV";
-///
-/// let webhook = rest::get_webhook_with_token(id, token)
-/// .expect("valid webhook");
-///
-/// let website = Embed::fake(|e| e
-/// .title("The Rust Language Website")
-/// .description("Rust is a systems programming language.")
-/// .colour(Colour::from_rgb(222, 165, 132)));
-///
-/// let resources = Embed::fake(|e| e
-/// .title("Rust Resources")
-/// .description("A few resources to help with learning Rust")
-/// .colour(0xDEA584)
-/// .field(|f| f
-/// .inline(false)
-/// .name("The Rust Book")
-/// .value("A comprehensive resource for all topics related to Rust"))
-/// .field(|f| f
-/// .inline(false)
-/// .name("Rust by Example")
-/// .value("A collection of Rust examples on topics, useable in-browser")));
-///
-/// let _ = webhook.execute(|w| w
-/// .content("Here's some information on Rust:")
-/// .embeds(vec![website, resources]));
-/// ```
-///
-/// [`Webhook`]: ../../model/struct.Webhook.html
-/// [`Webhook::execute`]: ../../model/struct.Webhook.html#method.execute
-/// [`execute_webhook`]: ../../client/rest/fn.execute_webhook.html
-#[derive(Clone, Debug)]
-pub struct ExecuteWebhook(pub JsonMap);
-
-impl ExecuteWebhook {
- /// Override the default avatar of the webhook with an image URL.
- pub fn avatar_url(mut self, avatar_url: &str) -> Self {
- self.0.insert("avatar_url".to_owned(), Value::String(avatar_url.to_owned()));
-
- self
- }
-
- /// Set the content of the message.
- ///
- /// Note that when setting at least one embed via [`embeds`], this may be
- /// omitted.
- ///
- /// [`embeds`]: #method.embeds
- pub fn content(mut self, content: &str) -> Self {
- self.0.insert("content".to_owned(), Value::String(content.to_owned()));
-
- self
- }
-
- /// Set the embeds associated with the message.
- ///
- /// This should be used in combination with [`Embed::fake`], creating one
- /// or more fake embeds to send to the API.
- ///
- /// # Examples
- ///
- /// Refer to the [struct-level documentation] for an example on how to use
- /// embeds.
- ///
- /// [`Embed::fake`]: ../../model/struct.Embed.html#method.fake
- /// [`Webhook::execute`]: ../../model/struct.Webhook.html#method.execute
- /// [struct-level documentation]: #examples
- pub fn embeds(mut self, embeds: Vec<Value>) -> Self {
- self.0.insert("embeds".to_owned(), Value::Array(embeds));
-
- self
- }
-
- /// Whether the message is a text-to-speech message.
- ///
- /// Think carefully before setting this to `true`.
- pub fn tts(mut self, tts: bool) -> Self {
- self.0.insert("tts".to_owned(), Value::Bool(tts));
-
- self
- }
-
- /// Override the default username of the webhook.
- pub fn username(mut self, username: &str) -> Self {
- self.0.insert("username".to_owned(), Value::String(username.to_owned()));
-
- self
- }
-}
-
-impl Default for ExecuteWebhook {
- /// Returns a default set of values for a [`Webhook`] execution.
- ///
- /// The only default value is [`tts`] being set to `true`. In the event that
- /// there is a bug that Discord defaults `tts` to `true`, at least
- /// serenity won't be a part of it.
- ///
- /// [`Webhook`]: ../../model/struct.Webhook.html
- /// [`tts`]: #method.tts
- fn default() -> ExecuteWebhook {
- let mut map = Map::new();
- map.insert("tts".to_owned(), Value::Bool(false));
-
- ExecuteWebhook(map)
- }
-}
diff --git a/src/utils/builder/get_messages.rs b/src/utils/builder/get_messages.rs
deleted file mode 100644
index cc4658c..0000000
--- a/src/utils/builder/get_messages.rs
+++ /dev/null
@@ -1,75 +0,0 @@
-use std::collections::BTreeMap;
-use ::model::MessageId;
-
-/// Builds a request for a request to the API to retrieve messages.
-///
-/// This can have 2 different sets of parameters. The first set is around where
-/// to get the messages:
-///
-/// - `after`
-/// - `around`
-/// - `before`
-/// - `most_recent`
-///
-/// These can not be mixed, and the first in the list alphabetically will be
-/// used. If one is not specified, `most_recent` will be used.
-///
-/// The fourth parameter is to specify the number of messages to retrieve. This
-/// does not _need_ to be called and defaults to a value of 50.
-///
-/// This should be used only for retrieving messages; see
-/// [`Client::get_messages`] for examples.
-///
-/// [`Client::get_messages`]: ../../client/struct.Client.html#method.get_messages
-#[derive(Clone, Debug, Default)]
-pub struct GetMessages(pub BTreeMap<String, u64>);
-
-impl GetMessages {
- /// Indicates to retrieve the messages after a specific message, given by
- /// its Id.
- pub fn after<M: Into<MessageId>>(mut self, message_id: M) -> Self {
- self.0.insert("after".to_owned(), message_id.into().0);
-
- self
- }
-
- /// Indicates to retrieve the messages _around_ a specific message in either
- /// direction (before+after) the given message.
- pub fn around<M: Into<MessageId>>(mut self, message_id: M) -> Self {
- self.0.insert("around".to_owned(), message_id.into().0);
-
- self
- }
-
- /// Indicates to retrieve the messages before a specific message, given by
- /// its Id.
- pub fn before<M: Into<MessageId>>(mut self, message_id: M) -> Self {
- self.0.insert("before".to_owned(), message_id.into().0);
-
- self
- }
-
- /// The maximum number of messages to retrieve for the query.
- ///
- /// If this is not specified, a default value of 50 is used.
- ///
- /// **Note**: This field is capped to 100 messages due to a Discord
- /// limitation. If an amount larger than 100 is supplied, it will be
- /// reduced.
- pub fn limit(mut self, limit: u64) -> Self {
- self.0.insert("limit".to_owned(), if limit > 100 {
- 100
- } else {
- limit
- });
-
- self
- }
-
- /// This is a function that is here for completeness. You do not need to
- /// call this - except to clear previous calls to `after`, `around`, and
- /// `before` - as it is the default value.
- pub fn most_recent(self) -> Self {
- self
- }
-}
diff --git a/src/utils/builder/mod.rs b/src/utils/builder/mod.rs
deleted file mode 100644
index 3fc0f05..0000000
--- a/src/utils/builder/mod.rs
+++ /dev/null
@@ -1,33 +0,0 @@
-//! A set of builders used to make using methods on certain structs simpler to
-//! use.
-//!
-//! These are used when not all parameters are required, all parameters are
-//! optional, and/or sane default values for required parameters can be applied
-//! by a builder.
-
-mod create_embed;
-mod create_invite;
-mod create_message;
-mod edit_channel;
-mod edit_guild;
-mod edit_member;
-mod edit_profile;
-mod edit_role;
-mod execute_webhook;
-mod get_messages;
-
-pub use self::create_embed::{
- CreateEmbed,
- CreateEmbedAuthor,
- CreateEmbedFooter,
- CreateEmbedField,
-};
-pub use self::create_invite::CreateInvite;
-pub use self::create_message::CreateMessage;
-pub use self::edit_channel::EditChannel;
-pub use self::edit_guild::EditGuild;
-pub use self::edit_member::EditMember;
-pub use self::edit_profile::EditProfile;
-pub use self::edit_role::EditRole;
-pub use self::execute_webhook::ExecuteWebhook;
-pub use self::get_messages::GetMessages;