blob: 58773d146a413809ac6a6518a2db76f93501ecb3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
use super::{Invite, RichInvite};
use ::client::http;
use ::internal::prelude::*;
use super::{permissions, utils};
#[cfg(feature = "state")]
use ::client::STATE;
impl Invite {
/// Accepts the invite, placing the current user in the [`Guild`] that the
/// invite was for.
///
/// Refer to [`http::accept_invite`] for more information.
///
/// **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.
///
/// # Errors
///
/// If the `state` features is enabled, then this returns a
/// [`ClientError::InvalidOperationAsBot`] if the current user does not have
/// the required [permission].
///
/// [`ClientError::InvalidOperationAsBot`]: enum.ClientError.html#variant.InvalidOperationAsBot
/// [`Guild`]: struct.Guild.html
/// [`http::accept_invite`]: ../client/http/fn.accept_invite.html
/// [permission]: permissions/index.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)
}
/// Deletes the invite.
///
/// **Note**: Requires the [Manage Guild] permission.
///
/// # 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
/// [permission]: permissions/index.html
#[cfg(feature="methods")]
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 the invite, placing the current user in the [`Guild`] that the
/// invite was for.
///
/// Refer to [`http::accept_invite`] for more information.
///
/// **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.
///
/// # Errors
///
/// Returns a [`ClientError::InvalidOperationAsBot`] if the current user is
/// a bot user.
///
/// [`ClientError::InvalidOperationAsBot`]: enum.ClientError.html#variant.InvalidOperationAsBot
/// [`Guild`]: struct.Guild.html
/// [`http::accept_invite`]: ../client/http/fn.accept_invite.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)
}
/// Deletes the invite.
///
/// Refer to [`http::delete_invite`] for more information.
///
/// **Note**: Requires the [Manage Guild] permission.
///
/// # Errors
///
/// If the `state` feature is enabled, then this 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
/// [`http::delete_invite`]: ../client/http/fn.delete_invite.html
/// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
/// [permission]: permissions/index.html
#[cfg(feature="methods")]
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)
}
}
|