change how client determines if verification is needed (#28)

This commit is contained in:
ouwou
2021-06-24 14:31:50 -04:00
parent 6e75c4a95d
commit 989ec06838
6 changed files with 23 additions and 5 deletions

View File

@@ -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);
}
}

View File

@@ -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)

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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 (
?, ?, ?, ?, ?, ?, ?, ?, ?
?, ?, ?, ?, ?, ?, ?, ?, ?, ?
)
)";