Skip to content

Commit

Permalink
fix: message_reference was missing from created messages
Browse files Browse the repository at this point in the history
  • Loading branch information
braindigitalis committed Nov 16, 2021
1 parent 31211a9 commit a65eb9e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
7 changes: 7 additions & 0 deletions src/dpp/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
55 changes: 30 additions & 25 deletions src/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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<dpp::message>(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<dpp::message>(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<dpp::message>(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<dpp::message>(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);
}
});
}
});

Expand Down

0 comments on commit a65eb9e

Please sign in to comment.