diff options
| author | Kyle Clemens <[email protected]> | 2018-04-11 10:50:12 -0400 |
|---|---|---|
| committer | alex <[email protected]> | 2018-04-11 16:50:12 +0200 |
| commit | bd195dea4422f516b727868209116ff868e3941b (patch) | |
| tree | 0b2d8fc385b30d3891d3387cffa0ff5226cd2188 /src/http/mod.rs | |
| parent | Be consistent with the note style (diff) | |
| download | serenity-bd195dea4422f516b727868209116ff868e3941b.tar.xz serenity-bd195dea4422f516b727868209116ff868e3941b.zip | |
do not include optional params if they are None in audit logs (#303)
Diffstat (limited to 'src/http/mod.rs')
| -rw-r--r-- | src/http/mod.rs | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/http/mod.rs b/src/http/mod.rs index 40f177b..a80f53a 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -1102,15 +1102,32 @@ pub fn get_audit_logs(guild_id: u64, user_id: Option<u64>, before: Option<u64>, limit: Option<u8>) -> Result<AuditLogs> { + let mut params = Vec::with_capacity(4); + + if let Some(action_type) = action_type { + params.push(format!("action_type={}", action_type)); + } + if let Some(user_id) = user_id { + params.push(format!("user_id={}", user_id)); + } + if let Some(before) = before { + params.push(format!("before={}", before)); + } + if let Some(limit) = limit { + params.push(format!("limit={}", limit)); + } + + let mut query_string = params.join("&"); + if !query_string.is_empty() { + query_string.insert(0, '?'); + } + let response = request!( Route::GuildsIdAuditLogs(guild_id), get, - "/guilds/{}/audit-logs?user_id={}&action_type={}&before={}&limit={}", + "/guilds/{}/audit-logs{}", guild_id, - user_id.unwrap_or(0), - action_type.unwrap_or(0), - before.unwrap_or(0), - limit.unwrap_or(50), + query_string ); serde_json::from_reader::<HyperResponse, AuditLogs>(response) |