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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
use crate::json_to_vec;
use crate::request::prelude::*;
use twilight_model::{
id::{ChannelId, UserId},
invite::{Invite, TargetUserType},
};
#[derive(Default, Serialize)]
struct CreateInviteFields {
max_age: Option<u64>,
max_uses: Option<u64>,
temporary: Option<bool>,
unique: Option<bool>,
target_user: Option<String>,
target_user_type: Option<TargetUserType>,
}
pub struct CreateInvite<'a> {
channel_id: ChannelId,
fields: CreateInviteFields,
fut: Option<Pending<'a, Invite>>,
http: &'a Client,
reason: Option<String>,
}
impl<'a> CreateInvite<'a> {
pub(crate) fn new(http: &'a Client, channel_id: ChannelId) -> Self {
Self {
channel_id,
fields: CreateInviteFields::default(),
fut: None,
http,
reason: None,
}
}
pub fn max_age(mut self, max_age: u64) -> Self {
self.fields.max_age.replace(max_age);
self
}
pub fn max_uses(mut self, max_uses: u64) -> Self {
self.fields.max_uses.replace(max_uses);
self
}
pub fn temporary(mut self, temporary: bool) -> Self {
self.fields.temporary.replace(temporary);
self
}
pub fn unique(mut self, unique: bool) -> Self {
self.fields.unique.replace(unique);
self
}
pub fn target_user(mut self, target_user: UserId) -> Self {
self.fields.target_user.replace(target_user.0.to_string());
self
}
pub fn target_user_type(mut self, target_user_type: TargetUserType) -> Self {
self.fields.target_user_type.replace(target_user_type);
self
}
pub fn reason(mut self, reason: impl Into<String>) -> Self {
self.reason.replace(reason.into());
self
}
fn start(&mut self) -> Result<()> {
let request = if let Some(reason) = &self.reason {
let headers = audit_header(&reason)?;
Request::from((
json_to_vec(&self.fields)?,
headers,
Route::CreateInvite {
channel_id: self.channel_id.0,
},
))
} else {
Request::from((
json_to_vec(&self.fields)?,
Route::CreateInvite {
channel_id: self.channel_id.0,
},
))
};
self.fut.replace(Box::pin(self.http.request(request)));
Ok(())
}
}
poll_req!(CreateInvite<'_>, Invite);