From 713ed0f9271bfd9249809940cf214d600adaecab Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 29 Aug 2020 01:14:20 -0400 Subject: add dm's --- discord/discord.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'discord/discord.cpp') diff --git a/discord/discord.cpp b/discord/discord.cpp index 69d95e8..57327dc 100644 --- a/discord/discord.cpp +++ b/discord/discord.cpp @@ -145,6 +145,10 @@ const MessageData *DiscordClient::GetMessage(Snowflake id) const { return &m_messages.at(id); } +const ChannelData *DiscordClient::GetChannel(Snowflake id) const { + return &m_channels.at(id); +} + void DiscordClient::SendChatMessage(std::string content, Snowflake channel) { // @([^@#]{1,32})#(\\d{4}) CreateMessageObject obj; @@ -260,9 +264,17 @@ void DiscordClient::HandleGatewayReady(const GatewayMessage &msg) { for (const auto &g : data.Guilds) { if (g.IsUnavailable) printf("guild (%lld) unavailable\n", g.ID); - else + else { StoreGuild(g.ID, g); + for (const auto &c : g.Channels) + StoreChannel(c.ID, c); + } } + + for (const auto &dm : data.PrivateChannels) { + StoreChannel(dm.ID, dm); + } + m_abaddon->DiscordNotifyReady(); m_user_settings = data.UserSettings; } @@ -291,6 +303,21 @@ void DiscordClient::StoreMessage(Snowflake id, const MessageData &m) { m_chan_to_message_map[m.ChannelID].insert(&m_messages[id]); } +void DiscordClient::StoreChannel(Snowflake id, const ChannelData &c) { + m_channels[id] = c; +} + +std::set DiscordClient::GetPrivateChannels() const { + auto ret = std::set(); + + for (const auto &[id, chan] : m_channels) { + if (chan.Type == ChannelType::DM || chan.Type == ChannelType::GROUP_DM) + ret.insert(id); + } + + return ret; +} + void DiscordClient::HeartbeatThread() { while (m_client_connected) { if (!m_heartbeat_acked) { -- cgit v1.2.3