From 79390deb7f99fca3d300816cdb72d5647bc62252 Mon Sep 17 00:00:00 2001 From: Austin Hellyer Date: Sat, 5 Nov 2016 15:29:16 -0700 Subject: Finalize invite-related documentation --- src/client/context.rs | 21 +++++++++++++++++-- src/model/invite.rs | 57 ++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 60 insertions(+), 18 deletions(-) (limited to 'src') 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 { 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 { 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 { 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 { + 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 { 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 { + 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) } } -- cgit v1.2.3