From a201d5905ad9188e890eeb0cc0aee8d4fb9dcf3c Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Thu, 20 Aug 2020 03:19:16 -0400 Subject: rudimentary chat --- discord/discord.hpp | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'discord/discord.hpp') diff --git a/discord/discord.hpp b/discord/discord.hpp index fa09ce2..4ece752 100644 --- a/discord/discord.hpp +++ b/discord/discord.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include struct Snowflake { @@ -33,6 +34,7 @@ struct Snowflake { private: friend struct std::hash; + friend struct std::less; unsigned long long m_num; }; @@ -43,6 +45,13 @@ struct hash { return k.m_num; } }; + +template<> +struct less { + bool operator()(const Snowflake &l, const Snowflake &r) const { + return l.m_num < r.m_num; + } +}; } // namespace std enum class GatewayOp : int { @@ -222,6 +231,62 @@ struct UserSettingsData { friend void from_json(const nlohmann::json &j, UserSettingsData &m); }; +enum class MessageType { + DEFAULT = 0, + RECIPIENT_ADD = 1, + RECIPIENT_REMOVE = 2, + CALL = 3, + CHANNEL_NaME_CHANGE = 4, + CHANNEL_ICON_CHANGE = 5, + CHANNEL_PINNED_MESSAGE = 6, + GUILD_MEMBER_JOIN = 6, + USER_PREMIUM_GUILD_SUBSCRIPTION = 7, + USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1 = 8, + USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2 = 9, + USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3 = 10, + CHANNEL_FOLLOW_ADD = 12, + GUILD_DISCOVERY_DISQUALIFIED = 13, + GUILD_DISCOVERY_REQUALIFIED = 14, +}; + +enum class MessageFlags { + NONE = 0, + CROSSPOSTED = 1 << 0, + IS_CROSSPOST = 1 << 1, + SUPPRESS_EMBEDS = 1 << 2, + SOURCE_MESSAGE_DELETE = 1 << 3, + URGENT = 1 << 4, +}; + +struct MessageData { + Snowflake ID; // + Snowflake ChannelID; // + Snowflake GuildID; // opt + UserData Author; // + // GuildMemberData Member; // opt + std::string Content; // + std::string Timestamp; // + std::string EditedTimestamp; // null + bool IsTTS; // + bool DoesMentionEveryone; // + std::vector Mentions; // + // std::vector MentionRoles; // + // std::vector MentionChannels; // opt + // std::vector Attachments; // + // std::vector Embeds; // + // std::vector Reactions; // opt + std::string Nonce; // opt + bool IsPinned; // + Snowflake WebhookID; // opt + MessageType Type; // + // MessageActivityData Activity; // opt + // MessageApplicationData Application; // opt + // MessageReferenceData MessageReference; // opt + MessageFlags Flags = MessageFlags::NONE; // opt + + friend void from_json(const nlohmann::json &j, MessageData &m); +}; + struct ReadyEventData { int GatewayVersion; // UserData User; // @@ -307,10 +372,15 @@ public: bool IsStarted() const; using Guilds_t = std::unordered_map; + using Messages_t = std::unordered_map; + const Guilds_t &GetGuilds() const; const UserSettingsData &GetUserSettings() const; std::vector> GetUserSortedGuilds() const; + std::unordered_set GetMessagesForChannel(Snowflake id) const; + void UpdateSettingsGuildPositions(const std::vector &pos); + void FetchMessagesInChannel(Snowflake id, std::function &)> cb); void UpdateToken(std::string token); @@ -330,6 +400,10 @@ private: void StoreGuild(Snowflake id, const GuildData &g); Guilds_t m_guilds; + void StoreMessage(Snowflake id, const MessageData &m); + Messages_t m_messages; + std::unordered_map> m_chan_to_message_map; + UserSettingsData m_user_settings; Websocket m_websocket; -- cgit v1.2.3