summaryrefslogtreecommitdiff
path: root/discord
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2020-08-29 01:14:20 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2020-08-29 01:14:20 -0400
commit713ed0f9271bfd9249809940cf214d600adaecab (patch)
treef6493059fea382df2301823805e0a7fc1a393589 /discord
parent299ecc71d980904ad7ffaf6d44254da71f948666 (diff)
downloadabaddon-portaudio-713ed0f9271bfd9249809940cf214d600adaecab.tar.gz
abaddon-portaudio-713ed0f9271bfd9249809940cf214d600adaecab.zip
add dm's
Diffstat (limited to 'discord')
-rw-r--r--discord/discord.cpp29
-rw-r--r--discord/discord.hpp6
-rw-r--r--discord/objects.cpp1
-rw-r--r--discord/objects.hpp18
4 files changed, 48 insertions, 6 deletions
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<Snowflake> DiscordClient::GetPrivateChannels() const {
+ auto ret = std::set<Snowflake>();
+
+ 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) {
diff --git a/discord/discord.hpp b/discord/discord.hpp
index 7c6e942..10ea95a 100644
--- a/discord/discord.hpp
+++ b/discord/discord.hpp
@@ -57,6 +57,7 @@ public:
void Stop();
bool IsStarted() const;
+ using Channels_t = std::unordered_map<Snowflake, ChannelData>;
using Guilds_t = std::unordered_map<Snowflake, GuildData>;
using Messages_t = std::unordered_map<Snowflake, MessageData>;
@@ -64,11 +65,13 @@ public:
const UserSettingsData &GetUserSettings() const;
std::vector<std::pair<Snowflake, GuildData>> GetUserSortedGuilds() const;
std::unordered_set<const MessageData *> GetMessagesForChannel(Snowflake id) const;
+ std::set<Snowflake> GetPrivateChannels() const;
void UpdateSettingsGuildPositions(const std::vector<Snowflake> &pos);
void FetchMessagesInChannel(Snowflake id, std::function<void(const std::vector<MessageData> &)> cb);
void FetchMessagesInChannelBefore(Snowflake channel_id, Snowflake before_id, std::function<void(const std::vector<MessageData> &)> cb);
const MessageData *GetMessage(Snowflake id) const;
+ const ChannelData *GetChannel(Snowflake id) const;
void SendChatMessage(std::string content, Snowflake channel);
@@ -103,6 +106,9 @@ private:
Messages_t m_messages;
std::unordered_map<Snowflake, std::unordered_set<const MessageData *>> m_chan_to_message_map;
+ void StoreChannel(Snowflake id, const ChannelData &c);
+ Channels_t m_channels;
+
UserSettingsData m_user_settings;
Websocket m_websocket;
diff --git a/discord/objects.cpp b/discord/objects.cpp
index 6858485..6350518 100644
--- a/discord/objects.cpp
+++ b/discord/objects.cpp
@@ -169,6 +169,7 @@ void from_json(const nlohmann::json &j, ReadyEventData &m) {
JS_D("analytics_token", m.AnalyticsToken);
JS_D("friend_suggestion_count", m.FriendSuggestionCount);
JS_D("user_settings", m.UserSettings);
+ JS_D("private_channels", m.PrivateChannels);
}
void from_json(const nlohmann::json &j, UserSettingsData &m) {
diff --git a/discord/objects.hpp b/discord/objects.hpp
index 5abafb1..db7927e 100644
--- a/discord/objects.hpp
+++ b/discord/objects.hpp
@@ -361,12 +361,20 @@ struct MessageData {
friend void from_json(const nlohmann::json &j, MessageData &m);
};
+struct MessageDeleteData {
+ Snowflake ID; //
+ Snowflake ChannelID; //
+ Snowflake GuildID; // opt
+
+ friend void from_json(const nlohmann::json &j, MessageDeleteData &m);
+};
+
struct ReadyEventData {
- int GatewayVersion; //
- UserData User; //
- std::vector<GuildData> Guilds; //
- std::string SessionID; //
- // std::vector<ChannelData?/PrivateChannelData?> PrivateChannels;
+ int GatewayVersion; //
+ UserData User; //
+ std::vector<GuildData> Guilds; //
+ std::string SessionID; //
+ std::vector<ChannelData> PrivateChannels; //
// undocumented
std::string AnalyticsToken; // opt