Skip to content

Commit 6573d30

Browse files
committed
feat!: update requests that might accept 'reason'
Breaking change that may modify the function signature of requests that are accepting of X-Audit-Log-Reason Closes #101
1 parent fcbb753 commit 6573d30

33 files changed

+362
-274
lines changed

examples/ban.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ on_unban(struct discord *client, const struct discord_message *event)
6161
u64snowflake target_id = 0ULL;
6262
sscanf(event->content, "%" SCNu64, &target_id);
6363

64-
discord_remove_guild_ban(client, event->guild_id, target_id, NULL);
64+
struct discord_remove_guild_ban params = {
65+
.reason = "Someone really likes you!"
66+
};
67+
discord_remove_guild_ban(client, event->guild_id, target_id, &params,
68+
NULL);
6569
}
6670

6771
void

examples/channel.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ on_channel_create(struct discord *client, const struct discord_message *event)
7878
{
7979
if (event->author->bot) return;
8080

81-
struct discord_create_guild_channel params = { .name = event->content };
81+
struct discord_create_guild_channel params = {
82+
.name = event->content,
83+
.reason = "Shiny new channel",
84+
};
8285
discord_create_guild_channel(client, event->guild_id, &params, NULL);
8386
}
8487

@@ -88,7 +91,10 @@ on_channel_rename_this(struct discord *client,
8891
{
8992
if (event->author->bot) return;
9093

91-
struct discord_modify_channel params = { .name = event->content };
94+
struct discord_modify_channel params = {
95+
.name = event->content,
96+
.reason = "Clicks better",
97+
};
9298
discord_modify_channel(client, event->channel_id, &params, NULL);
9399
}
94100

@@ -98,7 +104,8 @@ on_channel_delete_this(struct discord *client,
98104
{
99105
if (event->author->bot) return;
100106

101-
discord_delete_channel(client, event->channel_id, NULL);
107+
struct discord_delete_channel params = { .reason = "Stinky channel" };
108+
discord_delete_channel(client, event->channel_id, &params, NULL);
102109
}
103110

104111
void

examples/guild.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ on_role_delete(struct discord *client, const struct discord_message *event)
8383
return;
8484
}
8585

86-
discord_delete_guild_role(client, event->guild_id, role_id, NULL);
86+
struct discord_delete_guild_role params = { .reason = "Stinky role" };
87+
discord_delete_guild_role(client, event->guild_id, role_id, &params, NULL);
8788
}
8889

8990
void
@@ -100,8 +101,11 @@ on_role_member_add(struct discord *client, const struct discord_message *event)
100101
return;
101102
}
102103

104+
struct discord_add_guild_member_role params = {
105+
.reason = "Special role for a special member",
106+
};
103107
discord_add_guild_member_role(client, event->guild_id, user_id, role_id,
104-
NULL);
108+
&params, NULL);
105109
}
106110

107111
void
@@ -119,8 +123,11 @@ on_role_member_remove(struct discord *client,
119123
return;
120124
}
121125

126+
struct discord_remove_guild_member_role params = {
127+
.reason = "Didn't deserve it",
128+
};
122129
discord_remove_guild_member_role(client, event->guild_id, user_id, role_id,
123-
NULL);
130+
&params, NULL);
124131
}
125132

126133
void

examples/invite.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ on_invite_delete(struct discord *client, const struct discord_message *event)
7979
.fail = &fail,
8080
.keep = event,
8181
};
82-
discord_delete_invite(client, event->content, &ret);
82+
struct discord_delete_invite params = { .reason = "Stale invite" };
83+
discord_delete_invite(client, event->content, &params, &ret);
8384
}
8485

8586
int

examples/pin.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ on_pin(struct discord *client, const struct discord_message *event)
4242
msg_id = event->referenced_message->id;
4343
}
4444

45-
discord_pin_message(client, event->channel_id, msg_id, NULL);
45+
struct discord_pin_message params = { .reason = "Important message" };
46+
discord_pin_message(client, event->channel_id, msg_id, &params, NULL);
4647
}
4748

4849
void
@@ -60,7 +61,8 @@ on_unpin(struct discord *client, const struct discord_message *event)
6061
msg_id = event->referenced_message->id;
6162
}
6263

63-
discord_unpin_message(client, event->channel_id, msg_id, NULL);
64+
struct discord_unpin_message params = { .reason = "No longer relevant" };
65+
discord_unpin_message(client, event->channel_id, msg_id, &params, NULL);
6466
}
6567

6668
void

include/auto_moderation.h

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ CCORDcode discord_get_auto_moderation_rule(
4848
*
4949
* @param client the client created with discord_init()
5050
* @param guild_id the guild to create the rule in
51+
* @param params request parameters
5152
* @CCORD_ret_obj{ret,auto_moderation_rule}
5253
* @CCORD_return
5354
*/
@@ -64,6 +65,7 @@ CCORDcode discord_create_auto_moderation_rule(
6465
* @param client the client created with discord_init()
6566
* @param guild_id the guild where the rule to be modified is at
6667
* @param auto_moderation_rule_id the rule to be modified
68+
* @param params request parameters
6769
* @CCORD_ret_obj{ret,auto_moderation_rule}
6870
* @CCORD_return
6971
*/
@@ -81,13 +83,15 @@ CCORDcode discord_modify_auto_moderation_rule(
8183
* @param client the client created with discord_init()
8284
* @param guild_id the guild where the rule to be deleted is at
8385
* @param auto_moderation_rule_id the rule to be deleted
86+
* @param params request parameters
8487
* @CCORD_ret{ret}
8588
* @CCORD_return
8689
*/
8790
CCORDcode discord_delete_auto_moderation_rule(
8891
struct discord *client,
8992
u64snowflake guild_id,
9093
u64snowflake auto_moderation_rule_id,
94+
struct discord_delete_auto_moderation_rule *params,
9195
struct discord_ret *ret);
9296

9397
/** @} DiscordAPIAutoModeration */

include/channel.h

+15-4
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@ CCORDcode discord_modify_channel(struct discord *client,
5656
*
5757
* @param client the client created with discord_init()
5858
* @param channel_id the channel to be deleted
59+
* @param params request parameters
5960
* @CCORD_ret_obj{ret,channel}
6061
* @CCORD_return
6162
*/
6263
CCORDcode discord_delete_channel(struct discord *client,
6364
u64snowflake channel_id,
65+
struct discord_delete_channel *params,
6466
struct discord_ret_channel *ret);
6567

6668
/**
@@ -266,11 +268,13 @@ CCORDcode discord_edit_message(struct discord *client,
266268
* @param channel_id the channel that the message belongs to
267269
* @param message_id the message that will be purged of reactions from
268270
* particular emoji
271+
* @param params request parameters
269272
* @CCORD_return
270273
*/
271274
CCORDcode discord_delete_message(struct discord *client,
272275
u64snowflake channel_id,
273276
u64snowflake message_id,
277+
struct discord_delete_message *params,
274278
struct discord_ret *ret);
275279

276280
/**
@@ -340,13 +344,16 @@ CCORDcode discord_create_channel_invite(
340344
* @param client the client created with discord_init()
341345
* @param channel_id the channel to the permission deleted
342346
* @param overwrite_id the id of the overwritten permission
347+
* @param params request parameters
343348
* @CCORD_ret{ret}
344349
* @CCORD_return
345350
*/
346-
CCORDcode discord_delete_channel_permission(struct discord *client,
347-
u64snowflake channel_id,
348-
u64snowflake overwrite_id,
349-
struct discord_ret *ret);
351+
CCORDcode discord_delete_channel_permission(
352+
struct discord *client,
353+
u64snowflake channel_id,
354+
u64snowflake overwrite_id,
355+
struct discord_delete_channel_permission *params,
356+
struct discord_ret *ret);
350357

351358
/**
352359
* @brief Post a typing indicator for the specified channel
@@ -394,12 +401,14 @@ CCORDcode discord_get_pinned_messages(struct discord *client,
394401
* @param client the client created with discord_init()
395402
* @param channel_id channel to pin the message on
396403
* @param message_id message to be pinned
404+
* @param params request parameters
397405
* @CCORD_ret{ret}
398406
* @CCORD_return
399407
*/
400408
CCORDcode discord_pin_message(struct discord *client,
401409
u64snowflake channel_id,
402410
u64snowflake message_id,
411+
struct discord_pin_message *params,
403412
struct discord_ret *ret);
404413

405414
/**
@@ -408,12 +417,14 @@ CCORDcode discord_pin_message(struct discord *client,
408417
* @param client the client created with discord_init()
409418
* @param channel_id channel for the message to be unpinned
410419
* @param message_id message to be unpinned
420+
* @param params request parameters
411421
* @CCORD_ret{ret}
412422
* @CCORD_return
413423
*/
414424
CCORDcode discord_unpin_message(struct discord *client,
415425
u64snowflake channel_id,
416426
u64snowflake message_id,
427+
struct discord_unpin_message *params,
417428
struct discord_ret *ret);
418429

419430
/**

include/discord-request.h

+21-13
Original file line numberDiff line numberDiff line change
@@ -40,48 +40,56 @@ typedef struct {
4040
/**
4141
* @brief Helper for setting attributes for a specs-generated return struct
4242
*
43-
* @param attr attributes handler to be initialized
44-
* @param type datatype of the struct
45-
* @param ret dispatch attributes
43+
* @param[out] attr @ref discord_attributes handler to be initialized
44+
* @param[in] type datatype of the struct
45+
* @param[in] ret dispatch attributes
46+
* @param[in] _reason reason for request (if available)
4647
*/
47-
#define DISCORD_ATTR_INIT(attr, type, ret) \
48+
#define DISCORD_ATTR_INIT(attr, type, ret, _reason) \
4849
do { \
4950
(attr).response.size = sizeof(struct type); \
5051
(attr).response.init = (cast_init)type##_init; \
5152
(attr).response.from_json = (cast_from_json)type##_from_json; \
5253
(attr).response.cleanup = (cast_cleanup)type##_cleanup; \
54+
(attr).reason = _reason; \
5355
if (ret) _RET_COPY_TYPED(attr.dispatch, *ret); \
5456
} while (0)
5557

5658
/**
5759
* @brief Helper for setting attributes for a specs-generated list
5860
*
59-
* @param attr attributes handler to be initialized
60-
* @param type datatype of the list
61-
* @param ret dispatch attributes
61+
* @param[out] attr @ref discord_attributes handler to be initialized
62+
* @param[in] type datatype of the list
63+
* @param[in] ret dispatch attributes
64+
* @param[in] _reason reason for request (if available)
6265
*/
63-
#define DISCORD_ATTR_LIST_INIT(attr, type, ret) \
66+
#define DISCORD_ATTR_LIST_INIT(attr, type, ret, _reason) \
6467
do { \
6568
(attr).response.size = sizeof(struct type); \
6669
(attr).response.from_json = (cast_from_json)type##_from_json; \
6770
(attr).response.cleanup = (cast_cleanup)type##_cleanup; \
71+
(attr).reason = _reason; \
6872
if (ret) _RET_COPY_TYPED(attr.dispatch, *ret); \
6973
} while (0)
7074

7175
/**
7276
* @brief Helper for setting attributes for attruests that doensn't expect a
7377
* response object
7478
*
75-
* @param attr attributes handler to be initialized
76-
* @param ret dispatch attributes
79+
* @param[out] attr @ref discord_attributes handler to be initialized
80+
* @param[in] ret dispatch attributes
81+
* @param[in] _reason reason for request (if available)
7782
*/
78-
#define DISCORD_ATTR_BLANK_INIT(attr, ret) \
79-
if (ret) _RET_COPY_TYPELESS(attr.dispatch, *ret)
83+
#define DISCORD_ATTR_BLANK_INIT(attr, ret, _reason) \
84+
do { \
85+
(attr).reason = _reason; \
86+
if (ret) _RET_COPY_TYPELESS(attr.dispatch, *ret); \
87+
} while (0)
8088

8189
/**
8290
* @brief Helper for initializing attachments ids
8391
*
84-
* @param attchs a @ref discord_attachments to have its IDs initialized
92+
* @param[in,out] attchs a @ref discord_attachments to have its IDs initialized
8593
*/
8694
#define DISCORD_ATTACHMENTS_IDS_INIT(attchs) \
8795
do { \

include/emoji.h

+2
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,14 @@ CCORDcode discord_modify_guild_emoji(struct discord *client,
7777
* @param client the client created with discord_init()
7878
* @param guild_id guild the emoji belongs to
7979
* @param emoji_id the emoji to be deleted
80+
* @param params request parameters
8081
* @CCORD_ret{ret}
8182
* @CCORD_return
8283
*/
8384
CCORDcode discord_delete_guild_emoji(struct discord *client,
8485
u64snowflake guild_id,
8586
u64snowflake emoji_id,
87+
struct discord_delete_guild_emoji *params,
8688
struct discord_ret *ret);
8789

8890
/** @example emoji.c

include/gateway.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
* @param ret a sized buffer containing the response JSON
2424
* @CCORD_return
2525
*/
26-
CCORDcode discord_get_gateway(struct discord *client,
27-
struct ccord_szbuf *ret);
26+
CCORDcode discord_get_gateway(struct discord *client, struct ccord_szbuf *ret);
2827

2928
/**
3029
* @brief Get a single valid WSS URL, and additional metadata that can help
@@ -52,13 +51,15 @@ CCORDcode discord_get_gateway_bot(struct discord *client,
5251
* @param client the client created with discord_init()
5352
* @param guild_id the guild the member belongs to
5453
* @param user_id the user to be disconnected
54+
* @param params request parameters
5555
* @CCORD_ret_obj{ret,guild_member}
5656
* @CCORD_return
5757
*/
5858
CCORDcode discord_disconnect_guild_member(
5959
struct discord *client,
6060
u64snowflake guild_id,
6161
u64snowflake user_id,
62+
struct discord_modify_guild_member *params,
6263
struct discord_ret_guild_member *ret);
6364

6465
/**

0 commit comments

Comments
 (0)