aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-16 17:53:34 -0800
committerAustin Hellyer <[email protected]>2016-11-16 18:01:26 -0800
commitcabad4681d9557cf3a2357bdbd849d2a657250c3 (patch)
tree767370094aa57f257c5d031923ab1de2588abd93 /src
parentAdd Colour::from_rgb (diff)
downloadserenity-cabad4681d9557cf3a2357bdbd849d2a657250c3.tar.xz
serenity-cabad4681d9557cf3a2357bdbd849d2a657250c3.zip
Accepting invites only works for user accounts
They do not work for bot users. So return a `ClientError::InvalidOperationAsBot` if someone tries to.
Diffstat (limited to 'src')
-rw-r--r--src/client/context.rs16
-rw-r--r--src/model/invite.rs46
2 files changed, 59 insertions, 3 deletions
diff --git a/src/client/context.rs b/src/client/context.rs
index 1046361..522361a 100644
--- a/src/client/context.rs
+++ b/src/client/context.rs
@@ -48,8 +48,24 @@ impl Context {
/// Refer to the documentation for [`Invite::accept`] for restrictions on
/// accepting an invite.
///
+ /// **Note**: Requires that the current user be a user account. Bots can not
+ /// accept invites. Instead they must be accepted via OAuth2 authorization
+ /// links. These are in the format of:
+ ///
+ /// `https://discordapp.com/oauth2/authorize?client_id=CLIENT_ID&scope=bot`
+ ///
+ /// # Errors
+ ///
+ /// Returns a [`ClientError::InvalidOperationAsBot`] if the current user is
+ /// a bot user.
+ ///
+ /// [`ClientError::InvalidOperationAsBot`]: enum.ClientError.html#variant.InvalidOperationAsBot
/// [`Invite::accept`]: ../model/struct.Invite.html#method.accept
pub fn accept_invite(&self, invite: &str) -> Result<Invite> {
+ if self.login_type == LoginType::Bot {
+ return Err(Error::Client(ClientError::InvalidOperationAsBot));
+ }
+
let code = utils::parse_invite(invite);
http::accept_invite(code)
diff --git a/src/model/invite.rs b/src/model/invite.rs
index c33647e..55467e0 100644
--- a/src/model/invite.rs
+++ b/src/model/invite.rs
@@ -3,15 +3,39 @@ use ::client::http;
use ::internal::prelude::*;
use super::{permissions, utils};
+#[cfg(feature = "state")]
+use ::client::STATE;
+
impl Invite {
- /// Accepts the invite.
+ /// Accepts the invite, placing the current user in the [`Guild`] that the
+ /// invite was for. This will fire the [`Client::on_guild_create`] handler
+ /// once the associated event is received.
///
- /// **Note**: This will fail if you are already in the [`Guild`], or are
+ /// **Note**: This will fail if you are already in the `Guild`, or are
/// banned. A ban is equivilant to an IP ban.
///
+ /// **Note**: Requires that the current user be a user account. Bots can not
+ /// accept invites. Instead they must be accepted via OAuth2 authorization
+ /// links. These are in the format of:
+ ///
+ /// `https://discordapp.com/oauth2/authorize?client_id=CLIENT_ID&scope=bot`
+ ///
+ /// # Errors
+ ///
+ /// Returns a [`ClientError::InvalidOperationAsBot`] if the current user is
+ /// a bot user.
+ ///
+ /// [`ClientError::InvalidOperationAsBot`]: enum.ClientError.html#variant.InvalidOperationAsBot
+ /// [`Client::on_guild_create`]: ../client/struct.Client.html#method.on_guild_create
/// [`Guild`]: struct.Guild.html
#[cfg(feature="methods")]
pub fn accept(&self) -> Result<Invite> {
+ feature_state_enabled! {{
+ if STATE.lock().unwrap().user.bot {
+ return Err(Error::Client(ClientError::InvalidOperationAsBot));
+ }
+ }}
+
http::accept_invite(&self.code)
}
@@ -39,14 +63,30 @@ impl Invite {
}
impl RichInvite {
- /// Accepts the invite.
+ /// Accepts the invite, placing the current user in the [`Guild`] that the
+ /// invite was for. This will fire the [`Client::on_guild_create`] handler
+ /// once the associated event is received.
///
/// Refer to the documentation for [`Invite::accept`] for restrictions on
/// accepting an invite.
///
+ /// **Note**: Requires that the current user be a user account.
+ ///
+ /// # Errors
+ ///
+ /// Returns a [`ClientError::InvalidOperationAsBot`] if the current user is
+ /// a bot user.
+ ///
+ /// [`ClientError::InvalidOperationAsBot`]: enum.ClientError.html#variant.InvalidOperationAsBot
/// [`Invite::accept`]: struct.Invite.html#method.accept
#[cfg(feature="methods")]
pub fn accept(&self) -> Result<Invite> {
+ feature_state_enabled! {{
+ if STATE.lock().unwrap().user.bot {
+ return Err(Error::Client(ClientError::InvalidOperationAsBot));
+ }
+ }}
+
http::accept_invite(&self.code)
}