forked from cee-studio/orca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
discord-audit-log.c
60 lines (55 loc) · 1.8 KB
/
discord-audit-log.c
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
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h> /* PRIu64 */
#include "discord.h"
#include "discord-internal.h"
#include "cee-utils.h"
ORCAcode
discord_get_guild_audit_log(
struct discord *client,
const u64_snowflake_t guild_id,
struct discord_get_guild_audit_log_params *params,
struct discord_audit_log *p_audit_log)
{
if (!guild_id) {
log_error("Missing 'guild_id'");
return ORCA_MISSING_PARAMETER;
}
if (!p_audit_log) {
log_error("Missing 'p_audit_log'");
return ORCA_MISSING_PARAMETER;
}
char query[1024]="";
size_t offset=0;
if (params) {
if (params->user_id) {
offset += snprintf(query+offset, sizeof(query)-offset, \
"?user_id=%"PRIu64, params->user_id);
ASSERT_S(offset < sizeof(query), "Out of bounds write attempt");
}
if (params->action_type) {
offset += snprintf(query+offset, sizeof(query)-offset, \
"%saction_type=%d", (*query)?"&":"?", params->action_type);
ASSERT_S(offset < sizeof(query), "Out of bounds write attempt");
}
if (params->before) {
offset += snprintf(query+offset, sizeof(query)-offset, \
"%sbefore=%"PRIu64, (*query)?"&":"?", params->before);
ASSERT_S(offset < sizeof(query), "Out of bounds write attempt");
}
if (params->limit) {
offset += snprintf(query+offset, sizeof(query)-offset, \
"%slimit=%d", (*query)?"&":"?", params->limit);
ASSERT_S(offset < sizeof(query), "Out of bounds write attempt");
}
}
return discord_adapter_run(
&client->adapter,
&(struct ua_resp_handle){
.ok_cb = p_audit_log ? &discord_audit_log_from_json_v : NULL,
.ok_obj = &p_audit_log
},
NULL,
HTTP_GET,
"/guilds/%"PRIu64"/audit-logs%s", guild_id, query);
}