Files
abaddon/discord/message.hpp
2020-11-02 17:36:10 -05:00

173 lines
4.9 KiB
C++

#pragma once
#include "snowflake.hpp"
#include "json.hpp"
#include "user.hpp"
#include "sticker.hpp"
#include <string>
#include <vector>
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 = 7,
USER_PREMIUM_GUILD_SUBSCRIPTION = 8,
USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1 = 9,
USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2 = 10,
USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3 = 11,
CHANNEL_FOLLOW_ADD = 12,
GUILD_DISCOVERY_DISQUALIFIED = 14,
GUILD_DISCOVERY_REQUALIFIED = 15,
INLINE_REPLY = 19,
};
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 EmbedFooterData {
std::string Text; //
std::string IconURL; // opt
std::string ProxyIconURL; // opt
friend void from_json(const nlohmann::json &j, EmbedFooterData &m);
};
struct EmbedImageData {
std::string URL; // opt
std::string ProxyURL; // opt
int Height = 0; // opt
int Width = 0; // opt
friend void from_json(const nlohmann::json &j, EmbedImageData &m);
};
struct EmbedThumbnailData {
std::string URL; // opt
std::string ProxyURL; // opt
int Height = 0; // opt
int Width = 0; // opt
friend void from_json(const nlohmann::json &j, EmbedThumbnailData &m);
};
struct EmbedVideoData {
std::string URL; // opt
int Height = 0; // opt
int Width = 0; // opt
friend void from_json(const nlohmann::json &j, EmbedVideoData &m);
};
struct EmbedProviderData {
std::string Name; // opt
std::string URL; // opt, null (docs wrong)
friend void from_json(const nlohmann::json &j, EmbedProviderData &m);
};
struct EmbedAuthorData {
std::string Name; // opt
std::string URL; // opt
std::string IconURL; // opt
std::string ProxyIconURL; // opt
friend void from_json(const nlohmann::json &j, EmbedAuthorData &m);
};
struct EmbedFieldData {
std::string Name; //
std::string Value; //
bool Inline = false; // opt
friend void from_json(const nlohmann::json &j, EmbedFieldData &m);
};
struct EmbedData {
std::string Title; // opt
std::string Type; // opt
std::string Description; // opt
std::string URL; // opt
std::string Timestamp; // opt
int Color = -1; // opt
EmbedFooterData Footer; // opt
EmbedImageData Image; // opt
EmbedThumbnailData Thumbnail; // opt
EmbedVideoData Video; // opt
EmbedProviderData Provider; // opt
EmbedAuthorData Author; // opt
std::vector<EmbedFieldData> Fields; // opt
friend void from_json(const nlohmann::json &j, EmbedData &m);
};
struct AttachmentData {
Snowflake ID; //
std::string Filename; //
int Bytes; //
std::string URL; //
std::string ProxyURL; //
int Height = -1; // opt, null
int Width = -1; // opt, null
friend void from_json(const nlohmann::json &j, AttachmentData &m);
};
struct MessageReferenceData {
std::optional<Snowflake> MessageID;
std::optional<Snowflake> ChannelID;
std::optional<Snowflake> GuildID;
friend void from_json(const nlohmann::json &j, MessageReferenceData &m);
friend void to_json(nlohmann::json &j, const MessageReferenceData &m);
};
struct Message {
Snowflake ID;
Snowflake ChannelID;
std::optional<Snowflake> GuildID;
User Author;
// std::optional<GuildMember> Member;
std::string Content;
std::string Timestamp;
std::string EditedTimestamp; // null
bool IsTTS;
bool DoesMentionEveryone;
std::vector<User> Mentions;
// std::vector<Role> MentionRoles;
// std::optional<std::vector<ChannelMentionData>> MentionChannels;
std::vector<AttachmentData> Attachments;
std::vector<EmbedData> Embeds;
// std::optional<std::vector<ReactionData>> Reactions;
std::optional<std::string> Nonce;
bool IsPinned;
std::optional<Snowflake> WebhookID;
MessageType Type;
// std::optional<MessageActivityData> Activity;
// std::optional<MessageApplicationData> Application;
std::optional<MessageReferenceData> MessageReference;
std::optional<MessageFlags> Flags = MessageFlags::NONE;
std::optional<std::vector<Sticker>> Stickers;
friend void from_json(const nlohmann::json &j, Message &m);
void from_json_edited(const nlohmann::json &j); // for MESSAGE_UPDATE
// custom fields to track changes
void SetDeleted();
void SetEdited();
bool IsDeleted() const;
bool IsEdited() const;
private:
bool m_deleted = false;
bool m_edited = false;
};