diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-06-24 14:31:50 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-06-24 14:31:50 -0400 |
commit | 989ec06838b2f8e5a90808eacb97aefe2890df6c (patch) | |
tree | 4827aa21c3c794c3b5ec23b2e2f4d989cd4cbebc | |
parent | 6e75c4a95dcf0e601aba324ab5ae5f34ebd1a00d (diff) | |
download | abaddon-portaudio-989ec06838b2f8e5a90808eacb97aefe2890df6c.tar.gz abaddon-portaudio-989ec06838b2f8e5a90808eacb97aefe2890df6c.zip |
change how client determines if verification is needed (#28)
-rw-r--r-- | abaddon.cpp | 5 | ||||
-rw-r--r-- | discord/discord.cpp | 12 | ||||
-rw-r--r-- | discord/discord.hpp | 1 | ||||
-rw-r--r-- | discord/member.cpp | 2 | ||||
-rw-r--r-- | discord/member.hpp | 3 | ||||
-rw-r--r-- | discord/store.cpp | 5 |
6 files changed, 23 insertions, 5 deletions
diff --git a/abaddon.cpp b/abaddon.cpp index 00126ea..eea2840 100644 --- a/abaddon.cpp +++ b/abaddon.cpp @@ -484,11 +484,10 @@ void Abaddon::ActionChannelOpened(Snowflake id) { m_main_window->UpdateChatWindowContents(); } - if (channel->Type != ChannelType::DM && channel->Type != ChannelType::GROUP_DM) { + if (channel->Type != ChannelType::DM && channel->Type != ChannelType::GROUP_DM && channel->GuildID.has_value()) { m_discord.SendLazyLoad(id); - const auto request = m_discord.GetGuildApplication(*channel->GuildID); - if (request.has_value() && request->ApplicationStatus == GuildApplicationStatus::STARTED) + if (m_discord.IsVerificationRequired(*channel->GuildID)) ShowGuildVerificationGateDialog(*channel->GuildID); } } diff --git a/discord/discord.cpp b/discord/discord.cpp index ef93360..3641cb5 100644 --- a/discord/discord.cpp +++ b/discord/discord.cpp @@ -872,6 +872,13 @@ void DiscordClient::FetchUserRelationships(Snowflake user_id, sigc::slot<void(st }); } +bool DiscordClient::IsVerificationRequired(Snowflake guild_id) { + const auto member = GetMember(GetUserData().ID, guild_id); + if (member.has_value() && member->IsPending.has_value()) + return *member->IsPending; + return false; +} + void DiscordClient::GetVerificationGateInfo(Snowflake guild_id, sigc::slot<void(std::optional<VerificationGateInfoObject>)> callback) { m_http.MakeGET("/guilds/" + std::to_string(guild_id) + "/member-verification", [this, callback](const http::response_type &response) { if (!CheckCode(response)) return; @@ -1184,6 +1191,11 @@ void DiscordClient::ProcessNewGuild(GuildData &guild) { } void DiscordClient::HandleGatewayReady(const GatewayMessage &msg) { + auto fp = std::fopen("ready.json", "w"); + auto cum = msg.Data.dump(4); + std::fwrite(cum.c_str(), 1, cum.size(), fp); + std::fclose(fp); + m_ready_received = true; ReadyEventData data = msg.Data; for (auto &g : data.Guilds) diff --git a/discord/discord.hpp b/discord/discord.hpp index 10da6e8..adfef93 100644 --- a/discord/discord.hpp +++ b/discord/discord.hpp @@ -174,6 +174,7 @@ public: void FetchPinned(Snowflake id, sigc::slot<void(std::vector<Message>, DiscordError code)> callback); + bool IsVerificationRequired(Snowflake guild_id); void GetVerificationGateInfo(Snowflake guild_id, sigc::slot<void(std::optional<VerificationGateInfoObject>)> callback); void AcceptVerificationGate(Snowflake guild_id, VerificationGateInfoObject info, sigc::slot<void(bool success)> callback); diff --git a/discord/member.cpp b/discord/member.cpp index c7d2e4a..70a5727 100644 --- a/discord/member.cpp +++ b/discord/member.cpp @@ -11,6 +11,7 @@ void from_json(const nlohmann::json &j, GuildMember &m) { JS_D("mute", m.IsMuted); JS_O("user_id", m.UserID); JS_ON("avatar", m.Avatar); + JS_O("pending", m.IsPending); } std::vector<RoleData> GuildMember::GetSortedRoles() const { @@ -35,4 +36,5 @@ void GuildMember::update_from_json(const nlohmann::json &j) { JS_RD("joined_at", JoinedAt); JS_RD("premium_since", PremiumSince); JS_RD("avatar", Avatar); + JS_RD("pending", IsPending); } diff --git a/discord/member.hpp b/discord/member.hpp index ae93524..e17da05 100644 --- a/discord/member.hpp +++ b/discord/member.hpp @@ -8,13 +8,14 @@ struct GuildMember { std::optional<UserData> User; // only reliable to access id. only opt in MESSAGE_* - std::string Nickname; // null + std::string Nickname; std::vector<Snowflake> Roles; std::string JoinedAt; std::optional<std::string> PremiumSince; // null bool IsDeafened; bool IsMuted; std::optional<Snowflake> UserID; // present in merged_members + std::optional<bool> IsPending; // this uses `pending` not `is_pending` // undocuemtned moment !!!1 std::optional<std::string> Avatar; diff --git a/discord/store.cpp b/discord/store.cpp index b282100..fc40108 100644 --- a/discord/store.cpp +++ b/discord/store.cpp @@ -211,6 +211,7 @@ void Store::SetGuildMember(Snowflake guild_id, Snowflake user_id, const GuildMem Bind(m_set_member_stmt, 7, data.IsDeafened); Bind(m_set_member_stmt, 8, data.IsMuted); Bind(m_set_member_stmt, 9, data.Avatar); + Bind(m_set_member_stmt, 10, data.IsPending); if (!RunInsert(m_set_member_stmt)) fprintf(stderr, "member insert failed: %s\n", sqlite3_errstr(m_db_err)); @@ -642,6 +643,7 @@ std::optional<GuildMember> Store::GetGuildMember(Snowflake guild_id, Snowflake u Get(m_get_member_stmt, 6, ret.IsDeafened); Get(m_get_member_stmt, 7, ret.IsMuted); Get(m_get_member_stmt, 8, ret.Avatar); + Get(m_get_member_stmt, 9, ret.IsPending); Reset(m_get_member_stmt); @@ -876,6 +878,7 @@ bool Store::CreateTables() { deaf BOOL NOT NULL, mute BOOL NOT NULL, avatar TEXT, + pending BOOL, PRIMARY KEY(user_id, guild_id) ) )"; @@ -1092,7 +1095,7 @@ bool Store::CreateStatements() { const char *set_member = R"( REPLACE INTO members VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, ? + ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) )"; |