mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-19 20:11:59 +03:00
add ability to edit messages
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user