summaryrefslogtreecommitdiff
path: root/discord
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-07-27 22:54:17 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2021-07-27 22:54:17 -0400
commit9d2d13a3898f05f9e8189f99087198726d476e1b (patch)
treea5e159e426f30920b136ba5137d76366dffe516b /discord
parent1936f9ab8ab8687e3200a0ea31937339f9264c9e (diff)
downloadabaddon-portaudio-9d2d13a3898f05f9e8189f99087198726d476e1b.tar.gz
abaddon-portaudio-9d2d13a3898f05f9e8189f99087198726d476e1b.zip
very rudimentary thread support
Diffstat (limited to 'discord')
-rw-r--r--discord/channel.cpp8
-rw-r--r--discord/channel.hpp17
-rw-r--r--discord/discord.cpp10
-rw-r--r--discord/guild.cpp1
-rw-r--r--discord/guild.hpp1
-rw-r--r--discord/store.cpp15
6 files changed, 46 insertions, 6 deletions
diff --git a/discord/channel.cpp b/discord/channel.cpp
index 9d90eb5..e5dfb06 100644
--- a/discord/channel.cpp
+++ b/discord/channel.cpp
@@ -1,6 +1,13 @@
#include "../abaddon.hpp"
#include "channel.hpp"
+void from_json(const nlohmann::json &j, ThreadMetadata &m) {
+ JS_D("archived", m.IsArchived);
+ JS_D("auto_archive_duration", m.AutoArchiveDuration);
+ JS_D("archive_timestamp", m.ArchiveTimestamp);
+ JS_O("locked", m.IsLocked);
+}
+
void from_json(const nlohmann::json &j, ChannelData &m) {
JS_D("id", m.ID);
JS_D("type", m.Type);
@@ -21,6 +28,7 @@ void from_json(const nlohmann::json &j, ChannelData &m) {
JS_O("application_id", m.ApplicationID);
JS_ON("parent_id", m.ParentID);
JS_ON("last_pin_timestamp", m.LastPinTimestamp);
+ JS_O("thread_metadata", m.ThreadMetadata);
}
void ChannelData::update_from_json(const nlohmann::json &j) {
diff --git a/discord/channel.hpp b/discord/channel.hpp
index 68597e6..d262ddf 100644
--- a/discord/channel.hpp
+++ b/discord/channel.hpp
@@ -15,9 +15,10 @@ enum class ChannelType : int {
GUILD_NEWS = 5,
GUILD_STORE = 6,
/* 7 and 8 were used for LFG */
- /* 9 and 10 were used for threads */
- PUBLIC_THREAD = 11,
- PRIVATE_THREAD = 12,
+ /* 9 was used for threads */
+ GUILD_NEWS_THREAD = 10,
+ GUILD_PUBLIC_THREAD = 11,
+ GUILD_PRIVATE_THREAD = 12,
GUILD_STAGE_VOICE = 13,
};
@@ -37,6 +38,15 @@ constexpr const char *GetStagePrivacyDisplayString(StagePrivacy e) {
}
}
+struct ThreadMetadata {
+ bool IsArchived;
+ int AutoArchiveDuration;
+ std::string ArchiveTimestamp;
+ std::optional<bool> IsLocked;
+
+ friend void from_json(const nlohmann::json &j, ThreadMetadata &m);
+};
+
struct ChannelData {
Snowflake ID;
ChannelType Type;
@@ -57,6 +67,7 @@ struct ChannelData {
std::optional<Snowflake> ApplicationID;
std::optional<Snowflake> ParentID; // null
std::optional<std::string> LastPinTimestamp; // null
+ std::optional<ThreadMetadata> ThreadMetadata;
friend void from_json(const nlohmann::json &j, ChannelData &m);
void update_from_json(const nlohmann::json &j);
diff --git a/discord/discord.cpp b/discord/discord.cpp
index 8dc1ef8..2c0c7d7 100644
--- a/discord/discord.cpp
+++ b/discord/discord.cpp
@@ -1209,7 +1209,7 @@ void DiscordClient::ProcessNewGuild(GuildData &guild) {
m_store.BeginTransaction();
m_store.SetGuild(guild.ID, guild);
- if (guild.Channels.has_value())
+ if (guild.Channels.has_value()) {
for (auto &c : *guild.Channels) {
c.GuildID = guild.ID;
m_store.SetChannel(c.ID, c);
@@ -1218,6 +1218,14 @@ void DiscordClient::ProcessNewGuild(GuildData &guild) {
m_store.SetPermissionOverwrite(c.ID, p.ID, p);
}
}
+ }
+
+ if (guild.Threads.has_value()) {
+ for (auto& c : *guild.Threads) {
+ c.GuildID = guild.ID;
+ m_store.SetChannel(c.ID, c);
+ }
+ }
for (auto &r : *guild.Roles)
m_store.SetRole(r.ID, r);
diff --git a/discord/guild.cpp b/discord/guild.cpp
index d387729..1c79a38 100644
--- a/discord/guild.cpp
+++ b/discord/guild.cpp
@@ -43,6 +43,7 @@ void from_json(const nlohmann::json &j, GuildData &m) {
// JS_O("voice_states", m.VoiceStates);
// JS_O("members", m.Members);
JS_O("channels", m.Channels);
+ JS_O("threads", m.Threads);
// JS_O("presences", m.Presences);
JS_ON("max_presences", m.MaxPresences);
JS_O("max_members", m.MaxMembers);
diff --git a/discord/guild.hpp b/discord/guild.hpp
index a57bc15..3c3828d 100644
--- a/discord/guild.hpp
+++ b/discord/guild.hpp
@@ -80,6 +80,7 @@ struct GuildData {
std::optional<int> MaxVideoChannelUsers;
std::optional<int> ApproximateMemberCount;
std::optional<int> ApproximatePresenceCount;
+ std::optional<std::vector<ChannelData>> Threads; // only with permissions to view, id only
// undocumented
// std::map<std::string, Unknown> GuildHashes;
diff --git a/discord/store.cpp b/discord/store.cpp
index 2439da5..3cac46e 100644
--- a/discord/store.cpp
+++ b/discord/store.cpp
@@ -194,6 +194,12 @@ void Store::SetGuild(Snowflake id, const GuildData &guild) {
Bind(m_set_guild_stmt, 37, guild.ApproximateMemberCount);
Bind(m_set_guild_stmt, 38, guild.ApproximatePresenceCount);
Bind(m_set_guild_stmt, 39, guild.IsLazy);
+ if (guild.Threads.has_value()) {
+ snowflakes.clear();
+ for (const auto &x : *guild.Threads) snowflakes.push_back(x.ID);
+ Bind(m_set_guild_stmt, 40, nlohmann::json(snowflakes).dump());
+ } else
+ Bind(m_set_guild_stmt, 40, "[]"s);
if (!RunInsert(m_set_guild_stmt))
fprintf(stderr, "guild insert failed: %s\n", sqlite3_errstr(m_db_err));
@@ -626,6 +632,10 @@ std::optional<GuildData> Store::GetGuild(Snowflake id) const {
Get(m_get_guild_stmt, 36, ret.ApproximateMemberCount);
Get(m_get_guild_stmt, 37, ret.ApproximatePresenceCount);
Get(m_get_guild_stmt, 38, ret.IsLazy);
+ Get(m_get_guild_stmt, 39, tmp);
+ ret.Threads.emplace();
+ for (const auto &id : nlohmann::json::parse(tmp).get<std::vector<Snowflake>>())
+ ret.Threads->emplace_back().ID = id;
Reset(m_get_guild_stmt);
@@ -934,7 +944,8 @@ bool Store::CreateTables() {
max_video_users INTEGER,
approx_members INTEGER,
approx_presences INTEGER,
- lazy BOOL
+ lazy BOOL,
+ threads TEXT NOT NULL /* json */
)
)";
@@ -1116,7 +1127,7 @@ bool Store::CreateStatements() {
const char *set_guild = R"(
REPLACE INTO guilds VALUES (
- ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
+ ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
)
)";