aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2017-01-26 09:04:43 -0800
committerAustin Hellyer <[email protected]>2017-01-26 09:04:43 -0800
commitea14cfdcdcbb5d2563848b9e3cdc2207e0abfbea (patch)
treef88a8613abb479948719fdc47789dbb7a402875b /src
parentMake Guild::create_channel return a GuildChannel (diff)
downloadserenity-ea14cfdcdcbb5d2563848b9e3cdc2207e0abfbea.tar.xz
serenity-ea14cfdcdcbb5d2563848b9e3cdc2207e0abfbea.zip
Update examples for OOP update
Diffstat (limited to 'src')
-rw-r--r--src/client/context.rs8
-rw-r--r--src/model/channel.rs36
-rw-r--r--src/model/guild.rs15
-rw-r--r--src/model/user.rs48
4 files changed, 58 insertions, 49 deletions
diff --git a/src/client/context.rs b/src/client/context.rs
index e2371a0..bb87c35 100644
--- a/src/client/context.rs
+++ b/src/client/context.rs
@@ -161,7 +161,7 @@ impl Context {
///
/// ```rust,ignore
/// // assuming you are in a context
- /// context.broadcast_typing(context.channel_id);
+ /// let _ = context.broadcast_typing();
/// ```
///
/// # Errors
@@ -530,7 +530,7 @@ impl Context {
///
/// // assuming you are in a context
///
- /// let guild_id = message.guild_id.unwrap();
+ /// let guild_id = message.guild_id().unwrap();
/// context.get_guilds(GuildPagination::After(guild_id, 10)).unwrap();
/// ```
///
@@ -790,7 +790,7 @@ impl Context {
///
/// ```rust,ignore
/// // assuming you are in a context
- /// let _ = context.send_message(message.channel_id, |f| f.content("test"));
+ /// let _ = context.send_message(|f| f.content("test"));
/// ```
///
/// Send a message on `!ping` with a very descriptive [`Embed`]. This sends
@@ -829,7 +829,7 @@ impl Context {
/// let cache = CACHE.read().unwrap();
/// let channel = cache.get_guild_channel(message.channel_id);
///
- /// let _ = context.send_message(message.channel_id, |m| m
+ /// let _ = context.send_message(|m| m
/// .content("Pong! Here's some info")
/// .embed(|e| e
/// .colour(Colour::dark_gold())
diff --git a/src/model/channel.rs b/src/model/channel.rs
index 753b42f..b57f466 100644
--- a/src/model/channel.rs
+++ b/src/model/channel.rs
@@ -209,8 +209,6 @@ impl Channel {
/// Requires the [Manage Messages] permission, if the current user is not
/// the author of the message.
///
- /// (in practice, please do not do this)
- ///
/// [`Message`]: struct.Message.html
/// [`Message::delete`]: struct.Message.html#method.delete
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
@@ -278,11 +276,12 @@ impl Channel {
/// # Examples
///
/// ```rust,ignore
- /// use serenity::model::ChannelId;
+ /// use serenity::model::MessageId;
+ ///
+ /// let id = MessageId(81392407232380928);
///
- /// let messages = channel.get_messages(|g| g
- /// .before(20)
- /// .after(100)); // Maximum is 100.
+ /// // Maximum is 100.
+ /// let _messages = channel.get_messages(|g| g.after(id).limit(100));
/// ```
///
/// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html
@@ -1764,6 +1763,7 @@ impl PrivateChannel {
/// over the limit.
///
/// [`ClientError::MessageTooLong`]: ../client/enum.ClientError.html#variant.MessageTooLong
+ /// [`Message`]: struct.Message.html
pub fn send_message(&self, content: &str) -> Result<Message> {
if let Some(length_over) = Message::overflow_length(content) {
return Err(Error::Client(ClientError::MessageTooLong(length_over)));
@@ -1841,8 +1841,7 @@ impl GuildChannel {
/// Create an invite that can only be used 5 times:
///
/// ```rust,ignore
- /// let invite = channel.create_invite(|i| i
- /// .max_uses(5));
+ /// let invite = channel.create_invite(|i| i.max_uses(5));
/// ```
pub fn create_invite<F>(&self, f: F) -> Result<RichInvite>
where F: FnOnce(CreateInvite) -> CreateInvite {
@@ -1876,10 +1875,9 @@ impl GuildChannel {
/// permissions:
///
/// ```rust,ignore
+ /// use serenity::client::CACHE;
/// use serenity::model::{ChannelId, PermissionOverwrite, permissions};
///
- /// // assuming you are in a context
- ///
/// let channel_id = 7;
/// let user_id = 8;
///
@@ -1891,7 +1889,10 @@ impl GuildChannel {
/// kind: PermissionOverwriteType::Member(user_id),
/// };
///
- /// let _result = context.create_permission(channel_id, overwrite);
+ /// let cache = CACHE.read().unwrap();
+ /// let channel = cache.get_guild_channel(channel_id).unwrap();
+ ///
+ /// let _ = channel.create_permission(overwrite);
/// ```
///
/// Creating a permission overwrite for a role by specifying the
@@ -1900,10 +1901,9 @@ impl GuildChannel {
/// permissions:
///
/// ```rust,ignore
+ /// use serenity::client::CACHE;
/// use serenity::model::{ChannelId, PermissionOverwrite, permissions};
///
- /// // assuming you are in a context
- ///
/// let channel_id = 7;
/// let user_id = 8;
///
@@ -1915,13 +1915,17 @@ impl GuildChannel {
/// kind: PermissionOverwriteType::Member(user_id),
/// };
///
- /// let _result = context.create_permission(channel_id, overwrite);
+ /// let cache = CACHE.read().unwrap();
+ /// let channel = cache.get_guild_channel(channel_id).unwrap();
+ ///
+ /// let _ = channel.create_permission(overwrite);
/// ```
///
/// [`Channel`]: enum.Channel.html
/// [`Member`]: struct.Member.html
/// [`PermissionOverwrite`]: struct.PermissionOverwrite.html
/// [`PermissionOverwrite::Member`]: struct.PermissionOverwrite.html#variant.Member
+ /// [`PermissionOverwrite::Role`]: struct.PermissionOverwrite.html#variant.Role
/// [`Role`]: struct.Role.html
/// [Attach Files]: permissions/constant.ATTACH_FILES.html
/// [Manage Channels]: permissions/constant.MANAGE_CHANNELS.html
@@ -2026,9 +2030,7 @@ impl GuildChannel {
/// Change a voice channels name and bitrate:
///
/// ```rust,ignore
- /// channel.edit(|c| c
- /// .name("test")
- /// .bitrate(86400));
+ /// channel.edit(|c| c.name("test").bitrate(86400));
/// ```
pub fn edit<F>(&mut self, f: F) -> Result<()>
where F: FnOnce(EditChannel) -> EditChannel {
diff --git a/src/model/guild.rs b/src/model/guild.rs
index e77ba6f..0d557c6 100644
--- a/src/model/guild.rs
+++ b/src/model/guild.rs
@@ -573,9 +573,7 @@ impl Guild {
/// Mute a member and set their roles to just one role with a predefined Id:
///
/// ```rust,ignore
- /// guild.edit_member(user_id, |m| m
- /// .mute(true)
- /// .roles(&vec![role_id]));
+ /// guild.edit_member(user_id, |m| m.mute(true).roles(&vec![role_id]));
/// ```
#[inline]
pub fn edit_member<F, U>(&self, user_id: U, f: F) -> Result<()>
@@ -1324,9 +1322,7 @@ impl GuildId {
/// Mute a member and set their roles to just one role with a predefined Id:
///
/// ```rust,ignore
- /// guild.edit_member(user_id, |m| m
- /// .mute(true)
- /// .roles(&vec![role_id]));
+ /// guild.edit_member(user_id, |m| m.mute(true).roles(&vec![role_id]));
/// ```
#[inline]
pub fn edit_member<F, U>(&self, user_id: U, f: F) -> Result<()>
@@ -2106,9 +2102,7 @@ impl PartialGuild {
/// ```rust,ignore
/// use serenity::model::GuildId;
///
- /// GuildId(7).edit_member(user_id, |m| m
- /// .mute(true)
- /// .roles(&vec![role_id]));
+ /// GuildId(7).edit_member(user_id, |m| m.mute(true).roles(&vec![role_id]));
/// ```
#[inline]
pub fn edit_member<F, U>(&self, user_id: U, f: F) -> Result<()>
@@ -2440,8 +2434,7 @@ impl Role {
/// Make a role hoisted:
///
/// ```rust,ignore
- /// context.edit_role(guild_id, role_id, |r| r
- /// .hoist(true));
+ /// context.edit_role(guild_id, role_id, |r| r.hoist(true));
/// ```
///
/// [`Role`]: struct.Role.html
diff --git a/src/model/user.rs b/src/model/user.rs
index 42e8f32..961a54e 100644
--- a/src/model/user.rs
+++ b/src/model/user.rs
@@ -63,11 +63,7 @@ impl CurrentUser {
///
/// let avatar = serenity::utils::read_image("./avatar.png").unwrap();
///
- /// CACHE.write()
- /// .unwrap()
- /// .user
- /// .edit(|p| p
- /// .avatar(Some(&avatar)));
+ /// CACHE.write().unwrap().user.edit(|p| p.avatar(Some(&avatar)));
/// ```
pub fn edit<F>(&mut self, f: F) -> Result<()>
where F: FnOnce(EditProfile) -> EditProfile {
@@ -162,6 +158,18 @@ impl User {
}
/// Deletes a profile note from a user.
+ ///
+ /// # Examples
+ ///
+ /// Delete a note for a [`Message`]'s author:
+ ///
+ /// ```rust,ignore
+ /// // assuming you are in a context
+ ///
+ /// let _ = message.author.delete_note();
+ /// ```
+ ///
+ /// [`Message`]: struct.Message.html
#[inline]
pub fn delete_note(&self) -> Result<()> {
self.id.delete_note()
@@ -176,7 +184,8 @@ impl User {
///
/// ```rust,ignore
/// // assuming you are in a context
- /// let _ = context.message.author.dm("Hello!");
+ ///
+ /// let _ = message.author.direct_message("Hello!");
/// ```
///
/// [`PrivateChannel`]: struct.PrivateChannel.html
@@ -219,6 +228,16 @@ impl User {
/// This is an alias of [direct_message].
///
+ /// # Examples
+ ///
+ /// Sending a message:
+ ///
+ /// ```rust,ignore
+ /// // assuming you are in a context
+ ///
+ /// let _ = message.author.dm("Hello!");
+ /// ```
+ ///
/// [direct_message]: #method.direct_message
#[inline]
pub fn dm(&self, content: &str) -> Result<Message> {
@@ -237,7 +256,8 @@ impl User {
///
/// ```rust,ignore
/// // assuming a `message` has been bound
- /// let _ = context.edit_note(message.author, "test note");
+ ///
+ /// let _ = message.author.edit_note("test note");
/// ```
///
/// # Errors
@@ -275,15 +295,9 @@ impl User {
user_id.into().get()
}
- /// Check if a user has a [`Role`]. This will retrieve the
- /// [`Guild`] from the [`Cache`] if it is available, and then check if that
- /// guild has the given [`Role`].
- ///
- /// If the [`Guild`] is not present, then the guild will be retrieved from
- /// the API and the cache will be updated with it.
- ///
- /// If there are issues with requesting the API, then `false` will be
- /// returned.
+ /// Check if a user has a [`Role`]. This will retrieve the [`Guild`] from
+ /// the [`Cache`] if it is available, and then check if that guild has the
+ /// given [`Role`].
///
/// Three forms of data may be passed in to the guild parameter: either a
/// [`Guild`] itself, a [`GuildId`], or a `u64`.
@@ -294,7 +308,7 @@ impl User {
///
/// ```rust,ignore
/// // Assumes a 'guild' and `role_id` have already been bound
- /// context.message.author.has_role(guild, role_id);
+ /// let _ = message.author.has_role(guild, role_id);
/// ```
///
/// [`Guild`]: struct.Guild.html