From a65eb9e05f17b0ffd089cf7b475d667e9b5d30cd Mon Sep 17 00:00:00 2001 From: brain Date: Tue, 16 Nov 2021 23:53:54 +0000 Subject: [PATCH] fix: message_reference was missing from created messages --- src/dpp/message.cpp | 7 ++++++ src/test.cpp | 55 ++++++++++++++++++++++++--------------------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/dpp/message.cpp b/src/dpp/message.cpp index 94e5bf2385..ef464c54e3 100644 --- a/src/dpp/message.cpp +++ b/src/dpp/message.cpp @@ -871,6 +871,13 @@ message& message::fill_from_json(json* d, cache_policy_t cp) { for (auto& e : (*d)["attachments"]) { this->attachments.emplace_back(attachment(this, &e)); } + if (d->find("message_reference") != d->end()) { + json& mr = (*d)["message_reference"]; + message_reference.channel_id = SnowflakeNotNull(&mr, "channel_id"); + message_reference.guild_id = SnowflakeNotNull(&mr, "guild_id"); + message_reference.message_id = SnowflakeNotNull(&mr, "message_id"); + message_reference.fail_if_not_exists = BoolNotNull(&mr, "fail_if_not_exists"); + } return *this; } diff --git a/src/test.cpp b/src/test.cpp index 8ff08e615a..62d8c59a8f 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -148,8 +148,10 @@ int main() } }); + bool message_tested = false; bot.on_message_create([&](const dpp::message_create_t & event) { - if (event.msg->author->id == bot.me.id) { + if (event.msg->author->id == bot.me.id && !message_tested) { + message_tested = true; set_test("MESSAGERECEIVE", true); set_test("MESSAGESGET", false); bot.messages_get(event.msg->channel_id, 0, event.msg->id, 0, 5, [](const dpp::confirmation_callback_t &cc){ @@ -171,32 +173,35 @@ int main() set_test("MESSAGESGET", false); } }); + set_test("MSGCREATESEND", false); event.send("MSGCREATESEND", [&bot, ch_id = event.msg->channel_id] (auto cc) { - if (!cc.is_error()) { - dpp::message m = std::get(cc.value); - if (m.channel_id == ch_id) { - set_test("MSGCREATESEND", true); - } else { - set_test("MSGCREATESEND", false); - } - bot.message_delete(m.id, m.channel_id); - } else { - set_test("MSGCREATESEND", false); - } - }); + if (!cc.is_error()) { + dpp::message m = std::get(cc.value); + if (m.channel_id == ch_id) { + set_test("MSGCREATESEND", true); + } else { + set_test("MSGCREATESEND", false); + } + bot.message_delete(m.id, m.channel_id); + } else { + set_test("MSGCREATESEND", false); + } + }); + set_test("MSGCREATEREPLY", false); event.reply("MSGCREATEREPLY", [&bot, ref_id = event.msg->id] (auto cc) { - if (!cc.is_error()) { - dpp::message m = std::get(cc.value); - if (m.message_reference.message_id == ref_id) { - set_test("MSGCREATEREPLY", true); - } else { - set_test("MSGCREATEREPLY", false); - } - bot.message_delete(m.id, m.channel_id); - } else { - set_test("MSGCREATEREPLY", false); - } - }); + if (!cc.is_error()) { + dpp::message m = std::get(cc.value); + if (m.message_reference.message_id == ref_id) { + set_test("MSGCREATEREPLY", true); + } else { + set_test("MSGCREATEREPLY", false); + std::cout << " *** " << ref_id << " -> " << m.message_reference.message_id << "\n"; + } + bot.message_delete(m.id, m.channel_id); + } else { + set_test("MSGCREATEREPLY", false); + } + }); } });