Skip to content

Commit

Permalink
refactor!(gencodecs): bitwise enumerators have been converted to macr…
Browse files Browse the repository at this point in the history
…os, convert types that should be u64bitmask
  • Loading branch information
lcsmuller committed Mar 4, 2022
1 parent 061b6b5 commit 2cd1d08
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 86 deletions.
7 changes: 5 additions & 2 deletions gencodecs/api/application.pre.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Application Datatypes
* **************************************************************************/

/** @defgroup DiscordApplicationFlags Application flags
* @{ */
PP_DEFINE(DISCORD_APPLICATION_GATEWAY_PRESENCE 1 << 12)
PP_DEFINE(DISCORD_APPLICATION_GATEWAY_PRESENCE_LIMITED 1 << 13)
PP_DEFINE(DISCORD_APPLICATION_GATEWAY_GUILD_MEMBERS 1 << 14)
Expand All @@ -10,6 +12,7 @@ PP_DEFINE(DISCORD_APPLICATION_VERIFICATION_PENDING_GUILD_LIMIT 1 << 16)
PP_DEFINE(DISCORD_APPLICATION_EMBEDDED 1 << 17)
PP_DEFINE(DISCORD_APPLICATION_GATEWAY_MESSAGE_CONTENT 1 << 18)
PP_DEFINE(DISCORD_APPLICATION_GATEWAY_MESSAGE_CONTENT_LIMITED 1 << 19)
/** @} DiscordApplicationFlags */

/** @CCORD_pub_struct{discord_application} */
PUB_STRUCT(discord_application)
Expand Down Expand Up @@ -60,6 +63,6 @@ PUB_STRUCT(discord_application)
FIELD_PTR(slug, char, *)
/** the application's default rich presence invite cover image hash */
FIELD_PTR(cover_image, char, *)
/** the application's public flags */
FIELD_SNOWFLAKE(flags)
/** the application's public flags @see DiscordApplicationFlags */
FIELD_BITMASK(flags)
STRUCT_END
87 changes: 46 additions & 41 deletions gencodecs/api/channel.pre.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@
* Channel Datatypes
* **************************************************************************/

/** @defgroup DiscordAPIChannelMessageFlags Message flags
* @ingroup DiscordAPIChannel
* @{ */

/** this message has been published to subscribed channels (via Channel
Following) */
PP_DEFINE(DISCORD_MESSAGE_CROSSPOSTED 1 << 0)
/** this message originated from a message in another channel (via Channel
Following) */
PP_DEFINE(DISCORD_MESSAGE_IS_CROSSPOST 1 << 1)
/** do not include any embed when serializing this message */
PP_DEFINE(DISCORD_MESSAGE_SUPRPRESS_EMBEDS 1 << 2)
/** the source message for this crosspost has been deleted (via Channel
Following) */
PP_DEFINE(DISCORD_MESSAGE_SOURCE_MESSAGE_DELETED 1 << 3)
/** this message came from the urgent message system */
PP_DEFINE(DISCORD_MESSAGE_URGENT 1 << 4)
/** this message has an associated thread, with the same ID as the message */
PP_DEFINE(DISCORD_MESSAGE_HAS_THREAD 1 << 5)
/** this message is only visible to the user who invoked the interaction */
PP_DEFINE(DISCORD_MESSAGE_EPHEMERAL 1 << 6)
/** this message is an interaction response and the bot is thinking */
PP_DEFINE(DISCORD_MESSAGE_LOADING 1 << 7)
/** this message failed to mention some roles and add the members to the
thread */
PP_DEFINE(DISCORD_MESSAGE_FAILED_TO_MENTION_SOME_ROLES_IN_THREAD 1 << 8)

/** @} DiscordAPIChannelMessageFlags */

ENUM(discord_channel_types)
/** a text channel within a server */
ENUMERATOR(DISCORD_CHANNEL_GUILD_TEXT, = 0)
Expand Down Expand Up @@ -71,32 +100,6 @@ ENUM(discord_message_activity_types)
ENUMERATOR_LAST(DISCORD_MESSAGE_ACTIVITY_JOIN_REQUEST, = 5)
ENUM_END

ENUM(discord_message_flags)
/** this message has been published to subscribed channels (via Channel
Following) */
ENUMERATOR(DISCORD_MESSAGE_CROSSPOSTED, = 1 << 0)
/** this message originated from a message in another channel (via Channel
Following) */
ENUMERATOR(DISCORD_MESSAGE_IS_CROSSPOST, = 1 << 1)
/** do not include any embed when serializing this message */
ENUMERATOR(DISCORD_MESSAGE_SUPRPRESS_EMBEDS, = 1 << 2)
/** the source message for this crosspost has been deleted (via Channel
Following) */
ENUMERATOR(DISCORD_MESSAGE_SOURCE_MESSAGE_DELETED, = 1 << 3)
/** this message came from the urgent message system */
ENUMERATOR(DISCORD_MESSAGE_URGENT, = 1 << 4)
/** this message has an associated thread, with the same ID as the message */
ENUMERATOR(DISCORD_MESSAGE_HAS_THREAD, = 1 << 5)
/** this message is only visible to the user who invoked the interaction */
ENUMERATOR(DISCORD_MESSAGE_EPHEMERAL, = 1 << 6)
/** this message is an interaction response and the bot is thinking */
ENUMERATOR(DISCORD_MESSAGE_LOADING, = 1 << 7)
/** this message failed to mention some roles and add the members to the
thread */
ENUMERATOR_LAST(DISCORD_MESSAGE_FAILED_TO_MENTION_SOME_ROLES_IN_THREAD,
= 1 << 8)
ENUM_END

/** @CCORD_pub_struct{discord_channel} */
PUB_STRUCT(discord_channel)
/** the ID of this channel */
Expand Down Expand Up @@ -228,8 +231,8 @@ PUB_STRUCT(discord_message)
/** data showing the source of a crosspost, channel follow add, pin, or
reply message */
FIELD_STRUCT_PTR(message_reference, discord_message_reference, *)
/** message flags combined as a bitfield */
FIELD_ENUM(flags, discord_message_flags)
/** @ref DiscordAPIChannelMessageFlags combined as a bitfield */
FIELD_BITMASK(flags)
/** the message associated with the message_reference */
FIELD_STRUCT_PTR(referenced_message, discord_message, *)
/** sent if the message is a response to an interaction */
Expand Down Expand Up @@ -294,9 +297,9 @@ STRUCT(discord_overwrite)
FIELD_SNOWFLAKE(id)
/** either 0 (role) or 1 (member) */
FIELD(type, int, 0)
/** permission bit set */
/** @ref DiscordPermissions bit set */
FIELD_SNOWFLAKE(allow)
/** permission bit set */
/** @ref DiscordPermissions bit set */
FIELD_SNOWFLAKE(deny)
STRUCT_END

Expand Down Expand Up @@ -332,7 +335,7 @@ STRUCT(discord_thread_member)
/** the time the current user last joined the thread */
FIELD_TIMESTAMP(join_timestamp)
/** any user-thread settings, currently only used for notifications */
FIELD(flags, int, 0)
FIELD_BITMASK(flags)
STRUCT_END

/** @CCORD_pub_list{discord_thread_members} */
Expand Down Expand Up @@ -707,10 +710,10 @@ PUB_STRUCT(discord_create_message)
COND_WRITE(this->attachments != NULL)
FIELD_STRUCT_PTR(attachments, discord_attachments, *)
COND_END
/** message flags combined as a bitfield (only `SUPPRESS_EMBEDS` can be
set */
/** @ref DiscordAPIChannelMessageFlags combined as a bitfield (only
`SUPPRESS_EMBEDS` can be set) */
COND_WRITE(this->flags != 0)
FIELD_ENUM(flags, discord_message_flags)
FIELD_BITMASK(flags)
COND_END
STRUCT_END

Expand All @@ -734,10 +737,10 @@ PUB_STRUCT(discord_edit_message)
FIELD_PTR(content, char, *)
/** embedded `rich` content (up to 6000 characters) */
FIELD_STRUCT_PTR(embeds, discord_embeds, *)
/** message flags combined as a bitfield (only `SUPPRESS_EMBEDS` can be
set */
/** @ref DiscordAPIChannelMessageFlags combined as a bitfield (only
`SUPPRESS_EMBEDS` can be set) */
COND_WRITE(this->flags != 0)
FIELD_ENUM(flags, discord_message_flags)
FIELD_BITMASK(flags)
COND_END
/** allowed mentions for the message */
COND_WRITE(this->allowed_mentions != NULL)
Expand All @@ -761,13 +764,15 @@ STRUCT_END

/** @CCORD_pub_struct{discord_edit_channel_permissions} */
PUB_STRUCT(discord_edit_channel_permissions)
/** the bitwise value of all allowed permissions (default \"0\") */
/** the bitwise value of all allowed permissions (default \"0\")
@see @ref DiscordPermissions */
COND_WRITE(this->allow != 0)
FIELD_PRINTF(allow, u64bitmask, "%" PRIu64, "%" SCNu64)
FIELD_BITMASK(allow)
COND_END
/** the bitwise value of all disallowed permissions (default \"0\") */
/** the bitwise value of all disallowed permissions (default \"0\")
@see @ref DiscordPermissions */
COND_WRITE(this->deny != 0)
FIELD_PRINTF(deny, u64bitmask, "%" PRIu64, "%" SCNu64)
FIELD_BITMASK(deny)
COND_END
/** 0 for a role or 1 for a member */
FIELD(type, int, 0)
Expand Down
18 changes: 15 additions & 3 deletions gencodecs/api/gateway.pre.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
* Gateway Datatypes
* **************************************************************************/

/** @defgroup DiscordInternalGatewayIntents Gateway intents
* @brief Events user is interested on listening to
* @ingroup DiscordInternalGateway
* @{ */
PP_DEFINE(DISCORD_GATEWAY_GUILDS 1 << 0)
PP_DEFINE(DISCORD_GATEWAY_GUILD_MEMBERS 1 << 1)
PP_DEFINE(DISCORD_GATEWAY_GUILD_BANS 1 << 2)
Expand All @@ -17,7 +21,12 @@ PP_DEFINE(DISCORD_GATEWAY_GUILD_MESSAGE_TYPING 1 << 11)
PP_DEFINE(DISCORD_GATEWAY_DIRECT_MESSAGES 1 << 12)
PP_DEFINE(DISCORD_GATEWAY_DIRECT_MESSAGE_REACTIONS 1 << 13)
PP_DEFINE(DISCORD_GATEWAY_DIRECT_MESSAGE_TYPING 1 << 14)
/** @} DiscordInternalGatewayIntents */

/** @defgroup DiscordActivityFlags Gateway activity flags
* @brief Describe user activities
* @ingroup DiscordConstants
* @{ */
PP_DEFINE(DISCORD_ACTIVITY_INSTANCE 1 << 0)
PP_DEFINE(DISCORD_ACTIVITY_JOIN 1 << 1)
PP_DEFINE(DISCORD_ACTIVITY_SPECTATE 1 << 2)
Expand All @@ -27,6 +36,7 @@ PP_DEFINE(DISCORD_ACTIVITY_PLAY 1 << 5)
PP_DEFINE(DISCORD_ACTIVITY_PARTY_PRIVACY_FRIENDS 1 << 6)
PP_DEFINE(DISCORD_ACTIVITY_PARTY_PRIVACY_VOICE_CHANNEL 1 << 7)
PP_DEFINE(DISCORD_ACTIVITY_EMBEDDED 1 << 8)
/** @} DiscordActivityFlags */

ENUM(discord_gateway_close_opcodes)
ENUMERATOR(DISCORD_GATEWAY_CLOSE_REASON_UNKNOWN_ERROR, = 4000)
Expand Down Expand Up @@ -149,7 +159,8 @@ PUB_STRUCT(discord_identify)
#endif
/** presence structure for initial presence information */
FIELD_STRUCT_PTR(presence, discord_presence_update, *)
/** the gateway intents you wish to receive */
/** the gateway intents you wish to receive
@see @ref DiscordInternalGatewayIntents */
FIELD_BITMASK(intents)
STRUCT_END

Expand Down Expand Up @@ -247,8 +258,9 @@ STRUCT(discord_activity)
COND_END
/** whether or not the activity is an instanced game session */
FIELD(instance, bool, false)
/** activity flags bitwise mask, describes what they payload includes */
FIELD_SNOWFLAKE(flags)
/** activity flags bitwise mask, describes what they payload includes
@see @ref DiscordActivityFlags */
FIELD_BITMASK(flags)
/** the custom buttons shown in the Rich Presence (max 2) */
COND_WRITE(this->buttons != NULL)
FIELD_STRUCT_PTR(buttons, discord_activity_buttons, *)
Expand Down
40 changes: 22 additions & 18 deletions gencodecs/api/guild.pre.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
* Guild Datatypes
* **************************************************************************/

/** @defgroup DiscordAPIGuildSystemChannelFlags System channel flags
* @ingroup DiscordAPIGuild
* @{ */

/** suppress member join notifications */
PP_DEFINE(DISCORD_SYSTEM_SUPPRESS_JOIN_NOTIFICATIONS 1 << 0)
/** suppress server boost notifications */
PP_DEFINE(DISCORD_SYSTEM_SUPPRESS_PREMIUM_NOTIFICATIONS 1 << 1)
/** suppress server setup tips */
PP_DEFINE(DISCORD_SYSTEM_SUPPRESS_GUILD_REMINDER_NOTIFICATIONS 1 << 2)
/** hide member join sticker reply buttons */
PP_DEFINE(DISCORD_SYSTEM_SUPPRESS_JOIN_NOTIFICATION_REPLIES 1 << 3)

/** @} DiscordAPIGuildSystemChannelFlags */

ENUM(discord_message_notification_level)
/** members will receive notifications for all messages by default */
ENUMERATOR(DISCORD_MESSAGE_NOTIFICATION_ALL_MESSAGES, = 0)
Expand Down Expand Up @@ -57,17 +72,6 @@ ENUM(discord_premium_tier)
ENUMERATOR_LAST(DISCORD_PREMIUM_TIER_3, = 3)
ENUM_END

ENUM(discord_system_channel_flags)
/** suppress member join notifications */
ENUMERATOR(DISCORD_SYSTEM_SUPPRESS_JOIN_NOTIFICATIONS, = 1 << 0)
/** suppress server boost notifications */
ENUMERATOR(DISCORD_SYSTEM_SUPPRESS_PREMIUM_NOTIFICATIONS, = 1 << 1)
/** suppress server setup tips */
ENUMERATOR(DISCORD_SYSTEM_SUPPRESS_GUILD_REMINDER_NOTIFICATIONS, = 1 << 2)
/** hide member join sticker reply buttons */
ENUMERATOR_LAST(DISCORD_SYSTEM_SUPPRESS_JOIN_NOTIFICATION_REPLIES, = 1 << 3)
ENUM_END

ENUM(discord_integration_expire_behaviors)
ENUMERATOR(DISCORD_INTEGRATION_REMOVE_ROLE, = 0)
ENUMERATOR_LAST(DISCORD_INTEGRATION_KICK, = 1)
Expand All @@ -94,7 +98,7 @@ PUB_STRUCT(discord_guild)
FIELD(owner, bool, false)
/** id of owner */
FIELD_SNOWFLAKE(owner_id)
/** total permissions for the user in the guild (exclues overwrites) */
/** total permissions for the user in the guild (excludes overwrites) */
COND_WRITE(this->permissions != NULL)
FIELD_PTR(permissions, char, *)
COND_END
Expand Down Expand Up @@ -126,8 +130,8 @@ PUB_STRUCT(discord_guild)
/** the id of the channel where guild notices such as welcome messages and
boost events are posted */
FIELD_SNOWFLAKE(system_channel_id)
/** system channel flags */
FIELD_ENUM(system_channel_flags, discord_system_channel_flags)
/** @ref DiscordAPIGuildSystemChannelFlags */
FIELD_BITMASK(system_channel_flags)
/** the id of the channel where Community guilds can display rules and/or
guidelines */
FIELD_SNOWFLAKE(rules_channel_id)
Expand Down Expand Up @@ -462,8 +466,8 @@ PUB_STRUCT(discord_create_guild)
/** the ID of the channel when guild notices such as welcome messages and
boost events are posted */
FIELD_SNOWFLAKE(system_channel_id)
/** system channel flags */
FIELD_ENUM(system_channel_flags, discord_system_channel_flags)
/** @ref DiscordAPIGuildSystemChannelFlags */
FIELD_BITMASK(system_channel_flags)
STRUCT_END

/** @CCORD_pub_struct{discord_modify_guild} */
Expand Down Expand Up @@ -497,8 +501,8 @@ PUB_STRUCT(discord_modify_guild)
/** the ID of the channel when guild notices such as welcome messages and
boost events are posted */
FIELD_SNOWFLAKE(system_channel_id)
/** system channel flags */
FIELD_ENUM(system_channel_flags, discord_system_channel_flags)
/** @ref DiscordAPIGuildSystemChannelFlags */
FIELD_BITMASK(system_channel_flags)
/** the ID of the channel where Community guilds display rules and/or
guidelines */
FIELD_SNOWFLAKE(rules_channel_id)
Expand Down
10 changes: 5 additions & 5 deletions gencodecs/api/interactions.pre.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ STRUCT(discord_interaction_callback_data)
COND_WRITE(this->embeds != NULL)
FIELD_STRUCT_PTR(embeds, discord_embeds, *)
COND_END
/** message flags combined as a bitfield (only
/** @ref DiscordAPIChannelMessageFlags combined as a bitfield (only
@ref DISCORD_MESSAGE_SUPRESS_EMBEDS and @ref DISCORD_MESSAGE_EPHEMERAL
can be set) */
COND_WRITE(this->flags != 0)
FIELD_ENUM(flags, discord_message_flags)
FIELD_BITMASK(flags)
COND_END
/** attachment objects with filename and description */
COND_WRITE(this->attachments != NULL)
Expand Down Expand Up @@ -222,10 +222,10 @@ PUB_STRUCT(discord_create_followup_message)
COND_WRITE(this->attachments != NULL)
FIELD_STRUCT_PTR(attachments, discord_attachments, *)
COND_END
/** message flags combined as a bitfield (only `SUPPRESS_EMBEDS` can be
set) */
/** @ref DiscordAPIChannelMessageFlags combined as a bitfield (only
`SUPPRESS_EMBEDS` can be set) */
COND_WRITE(this->flags != 0)
FIELD_SNOWFLAKE(flags)
FIELD_BITMASK(flags)
COND_END
STRUCT_END

Expand Down
9 changes: 8 additions & 1 deletion gencodecs/api/permissions.pre.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
* Permissions Datatypes
* **************************************************************************/

/** @defgroup DiscordPermissions Discord permissions
* @see https://discord.com/developers/docs/topics/permissions#permissions
* @ingroup DiscordConstants
* @{ */

/** Allows creation of instant invites */
PP_DEFINE(DISCORD_PERM_CREATE_INSTANT_INVITE 1 << 0)
/** Allows kicking members */
Expand Down Expand Up @@ -93,6 +98,8 @@ PP_DEFINE(DISCORD_PERM_START_EMBEDDED_ACTIVITIES 1 << 39)
channels */
PP_DEFINE(DISCORD_PERM_MODERATE_MEMBERS 1 << 40)

/** @} DiscordPermissions */

/** @CCORD_pub_struct{discord_role} */
PUB_STRUCT(discord_role)
/** role id */
Expand All @@ -114,7 +121,7 @@ PUB_STRUCT(discord_role)
/** position of this role */
FIELD(position, int, 0)
/** permission bit set */
FIELD_PTR(permissions, char, *)
FIELD_BITMASK(permissions)
/** whether this role is managed by an integration */
FIELD(managed, bool, false)
/** whether this roleis mentionable */
Expand Down
Loading

0 comments on commit 2cd1d08

Please sign in to comment.