blob: 23b0aa39d4b90ab016c8b85e158f54739b7b7df2 (
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
|
use super::{Invite, RichInvite};
use ::client::http;
use ::prelude_internal::*;
use super::{permissions, utils};
impl Invite {
/// Accepts the invite.
///
/// **Note**: This will fail if you are already in the [`Guild`], or are
/// banned. A ban is equivilant to an IP ban.
///
/// [`Guild`]: struct.Guild.html
pub fn accept(&self) -> Result<Invite> {
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
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.
///
/// Refer to the documentation for [`Invite::accept`] for restrictions on
/// accepting an invite.
///
/// [`Invite::accept`]: struct.Invite.html#method.accept
pub fn accept(&self) -> Result<Invite> {
http::accept_invite(&self.code)
}
/// Deletes the 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`]: 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)
}
}
|