aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-05 15:29:16 -0700
committerAustin Hellyer <[email protected]>2016-11-05 15:29:16 -0700
commit79390deb7f99fca3d300816cdb72d5647bc62252 (patch)
tree9b4255dbb15fbc6e42aa4d43668ecd87f699063f /src
parentAdd message reactions (diff)
downloadserenity-79390deb7f99fca3d300816cdb72d5647bc62252.tar.xz
serenity-79390deb7f99fca3d300816cdb72d5647bc62252.zip
Finalize invite-related documentation
Diffstat (limited to 'src')
-rw-r--r--src/client/context.rs21
-rw-r--r--src/model/invite.rs57
2 files changed, 60 insertions, 18 deletions
diff --git a/src/client/context.rs b/src/client/context.rs
index 2d3d3e4..ef314eb 100644
--- a/src/client/context.rs
+++ b/src/client/context.rs
@@ -38,6 +38,12 @@ impl Context {
}
}
+ /// Accepts the given invite.
+ ///
+ /// Refer to the documentation for [`Invite::accept`] for restrictions on
+ /// accepting an invite.
+ ///
+ /// [`Invite::accept`]: ../model/struct.Invite.html#method.accept
pub fn accept_invite(&self, invite: &str) -> Result<Invite> {
let code = utils::parse_invite(invite);
@@ -292,13 +298,24 @@ impl Context {
integration_id.into().0)
}
- /*
+ /// Deletes the given invite.
+ ///
+ /// Refer to the documentation for [`Invite::delete`] for restrictions on
+ /// deleting an invite.
+ ///
+ /// # Errors
+ ///
+ /// Returns a [`ClientError::InvalidPermissions`] if the current user does
+ /// not have the required [permission].
+ ///
+ /// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
+ /// [`Invite::delete`]: ../model/struct.Invite.html#method.delete
+ /// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
pub fn delete_invite(&self, invite: &str) -> Result<Invite> {
let code = utils::parse_invite(invite);
http::delete_invite(code)
}
- */
/// Deletes a [Message](../model/struct.Message.html) given its ID.
///
diff --git a/src/model/invite.rs b/src/model/invite.rs
index 4324a67..5cb9cb9 100644
--- a/src/model/invite.rs
+++ b/src/model/invite.rs
@@ -1,47 +1,72 @@
use super::{Invite, RichInvite};
use ::client::http;
use ::prelude::*;
+use super::{permissions, utils};
impl Invite {
- /// Accepts an invite.
+ /// Accepts the invite.
///
- /// Refer to the documentation for [`Context::accept_invite`] for
- /// restrictions on accepting an invite.
+ /// **Note**: This will fail if you are already in the [`Guild`], or are
+ /// banned. A ban is equivilant to an IP ban.
///
- /// [`Context::accept_invite`]: ../client/struct.Context.html#method.accept_invite
+ /// [`Guild`]: struct.Guild.html
pub fn accept(&self) -> Result<Invite> {
http::accept_invite(&self.code)
}
- /// Deletes an invite.
+ /// Deletes the invite.
///
- /// Refer to the documentation for [`Context::delete_invite`] for more
- /// information.
+ /// **Note**: Requires the [Manage Guild] permission.
///
- /// [`Context::delete_invite`]: ../client/struct.Context.html#method.delete_invite
+ /// # Errors
+ ///
+ /// Returns a [`ClientError::InvalidPermissions`] if the current user does
+ /// not have the required [permission].
+ ///
+ /// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
+ /// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
pub fn delete(&self) -> Result<Invite> {
+ let req = permissions::MANAGE_GUILD;
+
+ if !try!(utils::user_has_perms(self.channel.id, req)) {
+ return Err(Error::Client(ClientError::InvalidPermissions(req)));
+ }
+
http::delete_invite(&self.code)
}
}
impl RichInvite {
- /// Accepts an invite.
+ /// Accepts the invite.
///
- /// Refer to the documentation for [`Context::accept_invite`] for
- /// restrictions on accepting an invite.
+ /// Refer to the documentation for [`Invite::accept`] for restrictions on
+ /// accepting an invite.
///
- /// [`Context::accept_invite`]: ../client/struct.Context.html#method.accept_invite
+ /// [`Invite::accept`]: struct.Invite.html#method.accept
pub fn accept(&self) -> Result<Invite> {
http::accept_invite(&self.code)
}
- /// Deletes an invite.
+ /// Deletes the invite.
///
- /// Refer to the documentation for [`Context::delete_invite`] for more
- /// information.
+ /// Refer to the documentation for [`Invite::delete`] for restrictions on
+ /// deleting an invite.
///
- /// [`Context::delete_invite`]: ../client/struct.Context.html#method.delete_invite
+ /// # Errors
+ ///
+ /// Returns a [`ClientError::InvalidPermissions`] if the current user does
+ /// not have the required [permission].
+ ///
+ /// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
+ /// [`Invite::delete`]: struct.Invite.html#method.delete
+ /// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
pub fn delete(&self) -> Result<Invite> {
+ let req = permissions::MANAGE_GUILD;
+
+ if !try!(utils::user_has_perms(self.channel.id, req)) {
+ return Err(Error::Client(ClientError::InvalidPermissions(req)));
+ }
+
http::delete_invite(&self.code)
}
}