feat: delete one or more messages of an author
@@ -38,12 +38,9 @@ run(client *client, u64_snowflake_t channel_id, u64_snowflake_t author_id)
ja_u64 **list = NULL;
int count = 0;
for (int i = 0; messages[i]; i++) {
- if (messages[i]->author->id == author_id) {
+ if (messages[i]->author->id == author_id)
count ++;
}
- else
- messages[i]->id = 0;
- }
list = (NTL_T(ja_u64))ntl_calloc(count, sizeof(ja_u64));
for (int i = 0, j = 0; messages[i] && j < count; i++) {
@@ -51,17 +48,19 @@ run(client *client, u64_snowflake_t channel_id, u64_snowflake_t author_id)
list[j]->value = messages[i]->id;
j++;
}
- else
- messages[i]->id = 0;
}
ntl_free((ntl_t)messages, channel::message::dati_cleanup_v);
- size_t s = ja_u64_list_to_json(NULL, 0, list);
- char *json = (char *)malloc(s);
- ja_u64_list_to_json(json, s, list);
+ if (count == 1)
+ channel::delete_message::run(client, channel_id, list[0]->value);
+ else {
+ char *json = NULL;
+ json_ainject(&json,
+ "(messages):F",
+ ja_u64_list_to_json, list);
struct sized_buffer req_body = {
- .size = s,
+ .size = strlen(json),
.start = json
};
@@ -70,7 +69,8 @@ run(client *client, u64_snowflake_t channel_id, u64_snowflake_t author_id)
NULL,
&req_body,
HTTP_POST,
- "/channels/%llu/messages", channel_id);
+ "/channels/%llu/messages/bulk-delete", channel_id);
+ }
}
