summaryrefslogtreecommitdiff
path: root/src/discord/discord.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/discord/discord.cpp')
-rw-r--r--src/discord/discord.cpp37
1 files changed, 26 insertions, 11 deletions
diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp
index 45e8919..6913ccf 100644
--- a/src/discord/discord.cpp
+++ b/src/discord/discord.cpp
@@ -1,6 +1,4 @@
-#include "abaddon.hpp"
#include "discord.hpp"
-#include "util.hpp"
#include <spdlog/spdlog.h>
#include <cinttypes>
#include <utility>
@@ -354,12 +352,10 @@ bool DiscordClient::HasChannelPermission(Snowflake user_id, Snowflake channel_id
}
Permission DiscordClient::ComputePermissions(Snowflake member_id, Snowflake guild_id) const {
- const auto member = GetMember(member_id, guild_id);
- const auto guild = GetGuild(guild_id);
- if (!member.has_value() || !guild.has_value())
- return Permission::NONE;
+ const auto member_roles = m_store.GetMemberRoles(guild_id, member_id);
+ const auto guild_owner = m_store.GetGuildOwner(guild_id);
- if (guild->OwnerID == member_id)
+ if (guild_owner == member_id)
return Permission::ALL;
const auto everyone = GetRole(guild_id);
@@ -367,7 +363,7 @@ Permission DiscordClient::ComputePermissions(Snowflake member_id, Snowflake guil
return Permission::NONE;
Permission perms = everyone->Permissions;
- for (const auto role_id : member->Roles) {
+ for (const auto role_id : member_roles) {
const auto role = GetRole(role_id);
if (role.has_value())
perms |= role->Permissions;
@@ -384,8 +380,8 @@ Permission DiscordClient::ComputeOverwrites(Permission base, Snowflake member_id
return Permission::ALL;
const auto channel = GetChannel(channel_id);
- const auto member = GetMember(member_id, *channel->GuildID);
- if (!member.has_value() || !channel.has_value())
+ const auto member_roles = m_store.GetMemberRoles(*channel->GuildID, member_id);
+ if (!channel.has_value())
return Permission::NONE;
Permission perms = base;
@@ -397,7 +393,7 @@ Permission DiscordClient::ComputeOverwrites(Permission base, Snowflake member_id
Permission allow = Permission::NONE;
Permission deny = Permission::NONE;
- for (const auto role_id : member->Roles) {
+ for (const auto role_id : member_roles) {
const auto overwrite = GetPermissionOverwrite(channel_id, role_id);
if (overwrite.has_value()) {
allow |= overwrite->Allow;
@@ -1280,6 +1276,10 @@ void DiscordClient::SetUserAgent(const std::string &agent) {
m_websocket.SetUserAgent(agent);
}
+void DiscordClient::SetDumpReady(bool dump) {
+ m_dump_ready = dump;
+}
+
bool DiscordClient::IsChannelMuted(Snowflake id) const noexcept {
return m_muted_channels.find(id) != m_muted_channels.end();
}
@@ -1650,6 +1650,17 @@ void DiscordClient::ProcessNewGuild(GuildData &guild) {
void DiscordClient::HandleGatewayReady(const GatewayMessage &msg) {
m_ready_received = true;
+
+ if (m_dump_ready) {
+ const auto name = "./payload_ready-" + Glib::DateTime::create_now_utc().format("%Y-%m-%d_%H-%M-%S") + ".json";
+ auto *fp = std::fopen(name.c_str(), "wb");
+ if (fp != nullptr) {
+ const auto contents = msg.Data.dump(4);
+ std::fwrite(contents.data(), contents.size(), 1, fp);
+ std::fclose(fp);
+ }
+ }
+
ReadyEventData data = msg.Data;
for (auto &g : data.Guilds)
ProcessNewGuild(g);
@@ -2428,6 +2439,10 @@ std::set<Snowflake> DiscordClient::GetPrivateChannels() const {
return {};
}
+const UserSettings &DiscordClient::GetUserSettings() const {
+ return m_user_settings;
+}
+
EPremiumType DiscordClient::GetSelfPremiumType() const {
const auto &data = GetUserData();
if (data.PremiumType.has_value())