Skip to content

Commit

Permalink
feat: ✨ add more gateway events; update examples; update deserialize …
Browse files Browse the repository at this point in the history
…function

Removed a lot of the safe type-checking which caused problems with the addition of the variant deserializer. They have been removed to ensure struct deserialization.
  • Loading branch information
Xminent committed Nov 2, 2023
1 parent 3e3c31c commit 26d5fd4
Show file tree
Hide file tree
Showing 61 changed files with 1,266 additions and 122 deletions.
10 changes: 8 additions & 2 deletions examples/simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ std::function<void(Event)> handle_event(HttpClient &http)
http.create_message(
msg.channel_id)
.with_content(fmt::format(
"You said: {}",
msg.content))
"{} said: {}\nAvatar: {}",
msg.author
.username,
msg.content,
msg.author.avatar ?
*msg.author
.avatar :
"null"))
.send();

if (!res) {
Expand Down
10 changes: 8 additions & 2 deletions examples/simple_with_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,14 @@ std::function<void(Event)> handle_event(HttpClient &http)
http.create_message(
msg.channel_id)
.with_content(fmt::format(
"You said: {}",
msg.content))
"{} said: {}\nAvatar: {}",
msg.author
.username,
msg.content,
msg.author.avatar ?
*msg.author
.avatar :
"null"))
.send();

if (!res) {
Expand Down
9 changes: 6 additions & 3 deletions include/ekizu/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <ekizu/guild_member.hpp>
#include <ekizu/permissions.hpp>
#include <ekizu/presence.hpp>

namespace ekizu
{
Expand Down Expand Up @@ -100,12 +101,14 @@ struct ThreadMember {
std::optional<Snowflake> id;
/// ID of the user.
std::optional<Snowflake> user_id;
/// Time the user last joined the thread.
/// Timestamp of when the member joined the thread.
std::string join_timestamp;
/// Any user-thread settings, currently only used for notifications.
int32_t flags{};
/// Additional information about the user.
uint64_t flags;
/// Member associated with the thread.
std::optional<GuildMember> member;
/// Presence information for the member.
std::optional<Presence> presence;
};

EKIZU_EXPORT void to_json(nlohmann::json &j, const ThreadMember &m);
Expand Down
6 changes: 3 additions & 3 deletions include/ekizu/command_data.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef EKIZU_MODELS_COMMAND_DATA_HPP
#define EKIZU_MODELS_COMMAND_DATA_HPP
#ifndef EKIZU_COMMAND_DATA_HPP
#define EKIZU_COMMAND_DATA_HPP

#include <ekizu/command_data_resolved.hpp>

Expand Down Expand Up @@ -38,4 +38,4 @@ EKIZU_EXPORT void to_json(nlohmann::json &j, const CommandData &c);
EKIZU_EXPORT void from_json(const nlohmann::json &j, CommandData &c);
} // namespace ekizu

#endif // EKIZU_MODELS_COMMAND_DATA_HPP
#endif // EKIZU_COMMAND_DATA_HPP
12 changes: 9 additions & 3 deletions include/ekizu/command_data_resolved.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef EKIZU_MODELS_COMMAND_INTERACTION_DATA_RESOLVED_HPP
#define EKIZU_MODELS_COMMAND_INTERACTION_DATA_RESOLVED_HPP
#ifndef EKIZU_COMMAND_DATA_RESOLVED_HPP
#define EKIZU_COMMAND_DATA_RESOLVED_HPP

#include <ekizu/member_flags.hpp>
#include <ekizu/message.hpp>
Expand All @@ -21,6 +21,9 @@ struct InteractionChannel {
std::optional<ThreadMetadata> thread_metadata;
};

EKIZU_EXPORT void to_json(nlohmann::json &j, const InteractionChannel &c);
EKIZU_EXPORT void from_json(const nlohmann::json &j, InteractionChannel &c);

struct InteractionMember {
/// Member's guild avatar.
std::optional<std::string> avatar;
Expand All @@ -41,6 +44,9 @@ struct InteractionMember {
std::vector<Snowflake> roles;
};

EKIZU_EXPORT void to_json(nlohmann::json &j, const InteractionMember &m);
EKIZU_EXPORT void from_json(const nlohmann::json &j, InteractionMember &m);

struct CommandInteractionDataResolved {
/// Map of resolved attachments.
std::unordered_map<Snowflake, Attachment> attachments;
Expand All @@ -64,4 +70,4 @@ EKIZU_EXPORT void from_json(const nlohmann::json &j,
CommandInteractionDataResolved &r);
} // namespace ekizu

#endif // EKIZU_MODELS_COMMAND_INTERACTION_DATA_RESOLVED_HPP
#endif // EKIZU_COMMAND_DATA_RESOLVED_HPP
9 changes: 9 additions & 0 deletions include/ekizu/emoji.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ struct Emoji {

EKIZU_EXPORT void to_json(nlohmann::json &j, const Emoji &e);
EKIZU_EXPORT void from_json(const nlohmann::json &j, Emoji &e);

struct EKIZU_EXPORT PartialEmoji {
Snowflake id{};
std::string name;
std::optional<bool> animated;
};

EKIZU_EXPORT void to_json(nlohmann::json &j, const PartialEmoji &p);
EKIZU_EXPORT void from_json(const nlohmann::json &j, PartialEmoji &p);
} // namespace ekizu

#endif // EKIZU_EMOJI_HPP
40 changes: 32 additions & 8 deletions include/ekizu/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <ekizu/gateway/guild_member_add.hpp>
#include <ekizu/gateway/guild_member_remove.hpp>
#include <ekizu/gateway/guild_member_update.hpp>
#include <ekizu/gateway/guild_members_chunk.hpp>
#include <ekizu/gateway/guild_role_create.hpp>
#include <ekizu/gateway/guild_role_delete.hpp>
#include <ekizu/gateway/guild_role_update.hpp>
#include <ekizu/gateway/guild_scheduled_event_create.hpp>
Expand All @@ -26,33 +28,55 @@
#include <ekizu/gateway/integration_create.hpp>
#include <ekizu/gateway/integration_delete.hpp>
#include <ekizu/gateway/integration_update.hpp>
#include <ekizu/gateway/interaction_create.hpp>
#include <ekizu/gateway/invite_create.hpp>
#include <ekizu/gateway/invite_delete.hpp>
#include <ekizu/gateway/log.hpp>
#include <ekizu/gateway/message_create.hpp>
#include <ekizu/gateway/message_delete.hpp>
#include <ekizu/gateway/message_delete_bulk.hpp>
#include <ekizu/gateway/message_reaction_add.hpp>
#include <ekizu/gateway/message_reaction_remove.hpp>
#include <ekizu/gateway/message_reaction_remove_all.hpp>
#include <ekizu/gateway/message_reaction_remove_emoji.hpp>
#include <ekizu/gateway/message_update.hpp>
#include <ekizu/gateway/presence_update.hpp>
#include <ekizu/gateway/ready.hpp>
#include <ekizu/gateway/resumed.hpp>
#include <ekizu/gateway/stage_instance_create.hpp>
#include <ekizu/gateway/stage_instance_delete.hpp>
#include <ekizu/gateway/stage_instance_update.hpp>
#include <ekizu/gateway/thread_create.hpp>
#include <ekizu/gateway/thread_delete.hpp>
#include <ekizu/gateway/thread_list_sync.hpp>
#include <ekizu/gateway/thread_member_update.hpp>
#include <ekizu/gateway/thread_members_update.hpp>
#include <ekizu/gateway/thread_update.hpp>
#include <ekizu/gateway/typing_start.hpp>
#include <ekizu/gateway/user_update.hpp>
#include <ekizu/gateway/voice_server_update.hpp>
#include <ekizu/gateway/voice_state_update.hpp>
#include <ekizu/gateway/webhooks_update.hpp>

namespace ekizu
{
using Event = std::variant<
GuildBanAdd, GuildBanRemove, ChannelCreate, ChannelDelete,
ChannelPinsUpdate, ChannelUpdate, GuildCreate, GuildDelete,
GuildEmojisUpdate, GuildIntegrationsUpdate, GuildMemberAdd,
GuildMemberRemove, GuildMemberUpdate, GuildRoleDelete, GuildRoleUpdate,
GuildScheduledEventCreate, GuildScheduledEventDelete,
GuildScheduledEventUpdate, GuildScheduledEventUserAdd,
GuildScheduledEventUserRemove, GuildStickersUpdate, GuildUpdate,
IntegrationCreate, IntegrationDelete, IntegrationUpdate, InviteCreate,
InviteDelete, Log, MessageCreate, MessageDelete, MessageDeleteBulk,
MessageReactionRemoveAll, MessageReactionRemoveEmoji, MessageUpdate,
PresenceUpdate, Ready, Resumed>;
GuildMemberRemove, GuildMemberUpdate, GuildMembersChunk, GuildRoleCreate,
GuildRoleDelete, GuildRoleUpdate, GuildScheduledEventCreate,
GuildScheduledEventDelete, GuildScheduledEventUpdate,
GuildScheduledEventUserAdd, GuildScheduledEventUserRemove,
GuildStickersUpdate, GuildUpdate, IntegrationCreate, IntegrationDelete,
IntegrationUpdate, InteractionCreate, InviteCreate, InviteDelete, Log,
MessageCreate, MessageDelete, MessageDeleteBulk, MessageReactionAdd,
MessageReactionRemove, MessageReactionRemoveAll,
MessageReactionRemoveEmoji, MessageUpdate, PresenceUpdate, Ready,
Resumed, StageInstanceCreate, StageInstanceDelete, StageInstanceUpdate,
ThreadCreate, ThreadDelete, ThreadListSync, ThreadMemberUpdate,
ThreadMembersUpdate, ThreadUpdate, TypingStart, UserUpdate,
VoiceServerUpdate, VoiceStateUpdate, WebhooksUpdate>;
} // namespace ekizu

#endif // EKIZU_EVENT_HPP
50 changes: 0 additions & 50 deletions include/ekizu/event_dispatcher.hpp

This file was deleted.

30 changes: 30 additions & 0 deletions include/ekizu/gateway/guild_members_chunk.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef EKIZU_GATEWAY_GUILD_MEMBERS_CHUNK_HPP
#define EKIZU_GATEWAY_GUILD_MEMBERS_CHUNK_HPP

#include <ekizu/guild_member.hpp>
#include <ekizu/presence.hpp>

namespace ekizu
{
struct GuildMembersChunk {
/// ID of the guild.
Snowflake guild_id;
/// Set of guild members.
std::vector<GuildMember> members;
/// Chunk index in the expected chunks for this response (0 <= chunk_index < chunk_count).
int chunk_index;
/// Total number of expected chunks for this response.
int chunk_count;
/// When passing an invalid ID to REQUEST_GUILD_MEMBERS, it will be returned here.
std::optional<std::vector<Snowflake> > not_found;
/// When passing true to REQUEST_GUILD_MEMBERS, presences of the returned members will be here.
std::optional<std::vector<Presence> > presences;
/// Nonce used in the Guild Members Request.
std::optional<std::string> nonce;
};

EKIZU_EXPORT void to_json(nlohmann::json &j, const GuildMembersChunk &c);
EKIZU_EXPORT void from_json(const nlohmann::json &j, GuildMembersChunk &c);
} // namespace ekizu

#endif // EKIZU_GATEWAY_GUILD_MEMBERS_CHUNK_HPP
11 changes: 11 additions & 0 deletions include/ekizu/gateway/interaction_create.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <ekizu/interaction.hpp>

namespace ekizu
{
struct InteractionCreate {
Interaction interaction;
};

EKIZU_EXPORT void to_json(nlohmann::json &j, const InteractionCreate &c);
EKIZU_EXPORT void from_json(const nlohmann::json &j, InteractionCreate &c);
} // namespace ekizu
30 changes: 30 additions & 0 deletions include/ekizu/gateway/message_reaction_add.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef EKIZU_GATEWAY_MESSAGE_REACTION_ADD_HPP
#define EKIZU_GATEWAY_MESSAGE_REACTION_ADD_HPP

#include <ekizu/emoji.hpp>
#include <ekizu/guild_member.hpp>

namespace ekizu
{
struct MessageReactionAdd {
/// ID of the user.
Snowflake user_id;
/// ID of the channel.
Snowflake channel_id;
/// ID of the message.
Snowflake message_id;
/// ID of the guild (if applicable).
std::optional<Snowflake> guild_id;
/// Member who reacted (if it happened in a guild).
std::optional<GuildMember> member;
/// Emoji used to react.
PartialEmoji emoji;
/// ID of the user who authored the reacted message.
Snowflake message_author_id;
};

EKIZU_EXPORT void to_json(nlohmann::json &j, const MessageReactionAdd &e);
EKIZU_EXPORT void from_json(const nlohmann::json &j, MessageReactionAdd &e);
} // namespace ekizu

#endif // EKIZU_GATEWAY_MESSAGE_REACTION_ADD_HPP
25 changes: 25 additions & 0 deletions include/ekizu/gateway/message_reaction_remove.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef EKIZU_GATEWAY_MESSAGE_REACTION_REMOVE_HPP
#define EKIZU_GATEWAY_MESSAGE_REACTION_REMOVE_HPP

#include <ekizu/emoji.hpp>

namespace ekizu
{
struct MessageReactionRemove {
/// ID of the user.
Snowflake user_id;
/// ID of the channel.
Snowflake channel_id;
/// ID of the message.
Snowflake message_id;
/// ID of the guild (if applicable).
std::optional<Snowflake> guild_id;
/// Emoji used to react.
PartialEmoji emoji;
};

EKIZU_EXPORT void to_json(nlohmann::json &j, const MessageReactionRemove &e);
EKIZU_EXPORT void from_json(const nlohmann::json &j, MessageReactionRemove &e);
} // namespace ekizu

#endif // EKIZU_GATEWAY_MESSAGE_REACTION_REMOVE_HPP
16 changes: 16 additions & 0 deletions include/ekizu/gateway/stage_instance_create.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef EKIZU_GATEWAY_STAGE_INSTANCE_CREATE_HPP
#define EKIZU_GATEWAY_STAGE_INSTANCE_CREATE_HPP

#include <ekizu/stage_instance.hpp>

namespace ekizu
{
struct StageInstanceCreate {
StageInstance stage_instance;
};

EKIZU_EXPORT void to_json(nlohmann::json &j, const StageInstanceCreate &s);
EKIZU_EXPORT void from_json(const nlohmann::json &j, StageInstanceCreate &s);
} // namespace ekizu

#endif // EKIZU_GATEWAY_STAGE_INSTANCE_CREATE_HPP
16 changes: 16 additions & 0 deletions include/ekizu/gateway/stage_instance_delete.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef EKIZU_GATEWAY_STAGE_INSTANCE_DELETE_HPP
#define EKIZU_GATEWAY_STAGE_INSTANCE_DELETE_HPP

#include <ekizu/stage_instance.hpp>

namespace ekizu
{
struct StageInstanceDelete {
StageInstance stage_instance;
};

EKIZU_EXPORT void to_json(nlohmann::json &j, const StageInstanceDelete &s);
EKIZU_EXPORT void from_json(const nlohmann::json &j, StageInstanceDelete &s);
} // namespace ekizu

#endif // EKIZU_GATEWAY_STAGE_INSTANCE_DELETE_HPP
16 changes: 16 additions & 0 deletions include/ekizu/gateway/stage_instance_update.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef EKIZU_GATEWAY_STAGE_INSTANCE_UPDATE_HPP
#define EKIZU_GATEWAY_STAGE_INSTANCE_UPDATE_HPP

#include <ekizu/stage_instance.hpp>

namespace ekizu
{
struct StageInstanceUpdate {
StageInstance stage_instance;
};

EKIZU_EXPORT void to_json(nlohmann::json &j, const StageInstanceUpdate &s);
EKIZU_EXPORT void from_json(const nlohmann::json &j, StageInstanceUpdate &s);
} // namespace ekizu

#endif // EKIZU_GATEWAY_STAGE_INSTANCE_UPDATE_HPP
Loading

0 comments on commit 26d5fd4

Please sign in to comment.