diff options
-rw-r--r-- | src/discord/discord.cpp | 15 | ||||
-rw-r--r-- | src/discord/discord.hpp | 4 | ||||
-rw-r--r-- | src/windows/mainwindow.cpp | 6 | ||||
-rw-r--r-- | src/windows/mainwindow.hpp | 1 |
4 files changed, 26 insertions, 0 deletions
diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index 2808e17..6739493 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -1204,6 +1204,10 @@ void DiscordClient::SetUserAgent(const std::string &agent) { m_websocket.SetUserAgent(agent); } +void DiscordClient::SetDumpReady(bool dump) { + m_dump_ready = dump; +} + bool DiscordClient::IsChannelMuted(Snowflake id) const noexcept { return m_muted_channels.find(id) != m_muted_channels.end(); } @@ -1566,6 +1570,17 @@ void DiscordClient::ProcessNewGuild(GuildData &guild) { void DiscordClient::HandleGatewayReady(const GatewayMessage &msg) { m_ready_received = true; + + if (m_dump_ready) { + const auto name = "./payload_ready-" + Glib::DateTime::create_now_utc().format("%Y-%m-%d_%H-%M-%S") + ".json"; + auto *fp = std::fopen(name.c_str(), "wb"); + if (fp != nullptr) { + const auto contents = msg.Data.dump(4); + std::fwrite(contents.data(), contents.size(), 1, fp); + std::fclose(fp); + } + } + ReadyEventData data = msg.Data; for (auto &g : data.Guilds) ProcessNewGuild(g); diff --git a/src/discord/discord.hpp b/src/discord/discord.hpp index c2bea7d..685d096 100644 --- a/src/discord/discord.hpp +++ b/src/discord/discord.hpp @@ -211,6 +211,8 @@ public: void UpdateToken(const std::string &token); void SetUserAgent(const std::string &agent); + void SetDumpReady(bool dump); + bool IsChannelMuted(Snowflake id) const noexcept; bool IsGuildMuted(Snowflake id) const noexcept; int GetUnreadStateForChannel(Snowflake id) const noexcept; @@ -229,6 +231,8 @@ private: std::vector<uint8_t> m_decompress_buf; z_stream m_zstream; + bool m_dump_ready = false; + static std::string GetAPIURL(); static std::string GetGatewayURL(); diff --git a/src/windows/mainwindow.cpp b/src/windows/mainwindow.cpp index 8a85d49..f1d16ec 100644 --- a/src/windows/mainwindow.cpp +++ b/src/windows/mainwindow.cpp @@ -255,8 +255,10 @@ void MainWindow::SetupMenu() { m_menu_file.set_submenu(m_menu_file_sub); m_menu_file_reload_css.set_label("Reload CSS"); m_menu_file_clear_cache.set_label("Clear file cache"); + m_menu_file_dump_ready.set_label("Dump ready message"); m_menu_file_sub.append(m_menu_file_reload_css); m_menu_file_sub.append(m_menu_file_clear_cache); + m_menu_file_sub.append(m_menu_file_dump_ready); m_menu_view.set_label("View"); m_menu_view.set_submenu(m_menu_view_sub); @@ -335,6 +337,10 @@ void MainWindow::SetupMenu() { Abaddon::Get().GetImageManager().ClearCache(); }); + m_menu_file_dump_ready.signal_toggled().connect([this]() { + Abaddon::Get().GetDiscordClient().SetDumpReady(m_menu_file_dump_ready.get_active()); + }); + m_menu_discord_add_recipient.signal_activate().connect([this] { m_signal_action_add_recipient.emit(GetChatActiveChannel()); }); diff --git a/src/windows/mainwindow.hpp b/src/windows/mainwindow.hpp index 78e0115..35ca7f1 100644 --- a/src/windows/mainwindow.hpp +++ b/src/windows/mainwindow.hpp @@ -72,6 +72,7 @@ private: Gtk::Menu m_menu_file_sub; Gtk::MenuItem m_menu_file_reload_css; Gtk::MenuItem m_menu_file_clear_cache; + Gtk::CheckMenuItem m_menu_file_dump_ready; Gtk::MenuItem m_menu_view; Gtk::Menu m_menu_view_sub; |