diff options
Diffstat (limited to 'discord')
-rw-r--r-- | discord/discord.cpp | 8 | ||||
-rw-r--r-- | discord/discord.hpp | 1 | ||||
-rw-r--r-- | discord/objects.cpp | 12 | ||||
-rw-r--r-- | discord/objects.hpp | 8 |
4 files changed, 29 insertions, 0 deletions
diff --git a/discord/discord.cpp b/discord/discord.cpp index 37ac59f..f04c136 100644 --- a/discord/discord.cpp +++ b/discord/discord.cpp @@ -172,6 +172,14 @@ void DiscordClient::DeleteMessage(Snowflake channel_id, Snowflake id) { m_http.MakeDELETE(path, [](auto) {}); } +void DiscordClient::EditMessage(Snowflake channel_id, Snowflake id, std::string content) { + std::string path = "/channels/" + std::to_string(channel_id) + "/messages/" + std::to_string(id); + MessageEditObject obj; + obj.Content = content; + nlohmann::json j = obj; + m_http.MakePATCH(path, j.dump(), [](auto) {}); +} + void DiscordClient::UpdateToken(std::string token) { m_token = token; m_http.SetAuth(token); diff --git a/discord/discord.hpp b/discord/discord.hpp index 87e09f4..707120e 100644 --- a/discord/discord.hpp +++ b/discord/discord.hpp @@ -70,6 +70,7 @@ public: void SendChatMessage(std::string content, Snowflake channel); void DeleteMessage(Snowflake channel_id, Snowflake id); + void EditMessage(Snowflake channel_id, Snowflake id, std::string content); void UpdateToken(std::string token); diff --git a/discord/objects.cpp b/discord/objects.cpp index ed556f4..1a8355e 100644 --- a/discord/objects.cpp +++ b/discord/objects.cpp @@ -295,6 +295,18 @@ void to_json(nlohmann::json &j, const CreateMessageObject &m) { j["content"] = m.Content; } +void to_json(nlohmann::json &j, const MessageEditObject &m) { + if (m.Content.size() > 0) + j["content"] = m.Content; + + // todo EmbedData to_json + // if (m.Embeds.size() > 0) + // j["embeds"] = m.Embeds; + + if (m.Flags != -1) + j["flags"] = m.Flags; +} + Snowflake::Snowflake() : m_num(Invalid) {} diff --git a/discord/objects.hpp b/discord/objects.hpp index a8bf082..e4b40b4 100644 --- a/discord/objects.hpp +++ b/discord/objects.hpp @@ -424,3 +424,11 @@ struct CreateMessageObject { friend void to_json(nlohmann::json &j, const CreateMessageObject &m); }; + +struct MessageEditObject { + std::string Content; // opt, null + std::vector<EmbedData> Embeds; // opt, null + int Flags = -1; // opt, null + + friend void to_json(nlohmann::json &j, const MessageEditObject &m); +}; |