aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--definitions/structs/invite.yml15
-rw-r--r--definitions/structs/rich_invite.yml40
-rw-r--r--src/client/context.rs21
-rw-r--r--src/model/invite.rs57
4 files changed, 110 insertions, 23 deletions
diff --git a/definitions/structs/invite.yml b/definitions/structs/invite.yml
index 4ccf0ea..4ed0b3f 100644
--- a/definitions/structs/invite.yml
+++ b/definitions/structs/invite.yml
@@ -1,12 +1,21 @@
---
name: Invite
-description: Information about an invite
+description: Information about an invite.
fields:
- name: code
+ description: The unique code for the invite.
type: string
- name: channel
- description: "A representation of the minimal amount of info needed about
- the channel being invited to."
+ description: >
+ A representation of the minimal amount of information needed about the
+ [`PublicChannel`] being invited to.
+
+ [`PublicChannel`]: struct.PublicChannel.html
type: InviteChannel
- name: guild
+ description: >
+ A representation of the minimal amount of information needed about the
+ [`Guild`] being invited to.
+
+ [`Guild`]: struct.Guild.html
type: InviteGuild
diff --git a/definitions/structs/rich_invite.yml b/definitions/structs/rich_invite.yml
index b275833..ff80fa8 100644
--- a/definitions/structs/rich_invite.yml
+++ b/definitions/structs/rich_invite.yml
@@ -1,23 +1,59 @@
---
name: RichInvite
-description: "Detailed information about an invite. This information can only
- be retrieved by anyone with the 'MANAGE_GUILD' permission."
+description: >
+ Detailed information about an invite. This information can only be retrieved
+ by anyone with the [Manage Guild] permission. Otherwise, a minimal amount of
+ information can be retrieved via the [`Invite`] struct.
+
+ [`Invite`]: struct.Invite.html
+ [Manage Guild]: permissions/constant.MANAGE_GUILD.html
fields:
- name: channel
+ description: >
+ A representation of the minimal amount of information needed about the
+ [`PublicChannel`] being invited to.
+
+ [`PublicChannel`]: struct.PublicChannel.html
type: InviteChannel
- name: code
+ description: The unique code for the invite.
type: string
- name: created_at
+ description: When the invite was created.
type: string
- name: guild
+ description: >
+ A representation of the minimal amount of information needed about the
+ [`Guild`] being invited to.
+
+ [`Guild`]: struct.Guild.html
type: InviteGuild
- name: inviter
+ description: The user that created the invite.
type: User
- name: max_age
+ description: >
+ The maximum age of the invite in seconds, from when it was created.
type: u64
- name: max_uses
+ description: >
+ The maximum number of times that an invite may be used before it expires.
+
+ Note that this does not supercede the [`max_age`] value, if the value of
+ [`temporary`] is `true`. If the value of `temporary` is `false`, then the
+ invite _will_ self-expire after the given number of max uses.
+
+ If the value is `0`, then the invite is permanent.
+
+ [`max_age`]: #structfield.max_age
+ [`temporary`]: #structfield.temporary
type: u64
- name: temporary
+ description: >
+ Whether the invite self-expires after a certain amount of time or uses.
type: bool
- name: uses
+ description: >
+ The maximum amount of times that an invite may be used before it
+ self-expires.
type: u64
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)
}
}