add ability to edit messages

This commit is contained in:
ouwou
2020-08-30 22:55:36 -04:00
parent 44b7989f50
commit 9b1bc8f145
12 changed files with 120 additions and 1 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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) {}

View File

@@ -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);
};