diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2022-04-05 22:01:53 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2022-04-05 22:01:53 -0400 |
commit | 49685c39895af67d7ffcc50fdc02150b6ee44f72 (patch) | |
tree | 5c5c262f95a30e58582a285b467d05954ff5f35c /src/discord | |
parent | 9767e1e7fdef9262211ec676b4f0d4c30ff10649 (diff) | |
download | abaddon-portaudio-49685c39895af67d7ffcc50fdc02150b6ee44f72.tar.gz abaddon-portaudio-49685c39895af67d7ffcc50fdc02150b6ee44f72.zip |
fix up a bunch of clang-tidy stuff
mostly changing references, which i hope doesnt break stuff with models (TreeRow, iterators) since they gave me some strange problems in the past
Diffstat (limited to 'src/discord')
-rw-r--r-- | src/discord/channel.cpp | 5 | ||||
-rw-r--r-- | src/discord/channel.hpp | 21 | ||||
-rw-r--r-- | src/discord/discord.cpp | 262 | ||||
-rw-r--r-- | src/discord/discord.hpp | 123 | ||||
-rw-r--r-- | src/discord/emoji.cpp | 2 | ||||
-rw-r--r-- | src/discord/guild.cpp | 55 | ||||
-rw-r--r-- | src/discord/guild.hpp | 3 | ||||
-rw-r--r-- | src/discord/httpclient.cpp | 32 | ||||
-rw-r--r-- | src/discord/httpclient.hpp | 12 | ||||
-rw-r--r-- | src/discord/json.hpp | 8 | ||||
-rw-r--r-- | src/discord/member.cpp | 2 | ||||
-rw-r--r-- | src/discord/member.hpp | 2 | ||||
-rw-r--r-- | src/discord/message.cpp | 4 | ||||
-rw-r--r-- | src/discord/message.hpp | 6 | ||||
-rw-r--r-- | src/discord/objects.cpp | 4 | ||||
-rw-r--r-- | src/discord/objects.hpp | 2 | ||||
-rw-r--r-- | src/discord/role.hpp | 4 | ||||
-rw-r--r-- | src/discord/snowflake.cpp | 5 | ||||
-rw-r--r-- | src/discord/snowflake.hpp | 4 | ||||
-rw-r--r-- | src/discord/sticker.cpp | 9 | ||||
-rw-r--r-- | src/discord/sticker.hpp | 4 | ||||
-rw-r--r-- | src/discord/store.cpp | 6 | ||||
-rw-r--r-- | src/discord/store.hpp | 6 | ||||
-rw-r--r-- | src/discord/user.cpp | 8 | ||||
-rw-r--r-- | src/discord/user.hpp | 30 | ||||
-rw-r--r-- | src/discord/websocket.cpp | 15 | ||||
-rw-r--r-- | src/discord/websocket.hpp | 3 |
27 files changed, 260 insertions, 377 deletions
diff --git a/src/discord/channel.cpp b/src/discord/channel.cpp index 9d47076..0770581 100644 --- a/src/discord/channel.cpp +++ b/src/discord/channel.cpp @@ -116,5 +116,8 @@ std::vector<UserData> ChannelData::GetDMRecipients() const { return ret; } - return std::vector<UserData>(); + return {}; +} +bool ChannelData::IsText() const noexcept { + return Type == ChannelType::GUILD_TEXT || Type == ChannelType::GUILD_NEWS; } diff --git a/src/discord/channel.hpp b/src/discord/channel.hpp index 89e43a0..8feeb92 100644 --- a/src/discord/channel.hpp +++ b/src/discord/channel.hpp @@ -94,14 +94,15 @@ struct ChannelData { friend void from_json(const nlohmann::json &j, ChannelData &m); void update_from_json(const nlohmann::json &j); - bool NSFW() const; - bool IsDM() const noexcept; - bool IsThread() const noexcept; - bool IsJoinedThread() const; - bool IsCategory() const noexcept; - bool HasIcon() const noexcept; - std::string GetIconURL() const; - std::vector<Snowflake> GetChildIDs() const; - std::optional<PermissionOverwrite> GetOverwrite(Snowflake id) const; - std::vector<UserData> GetDMRecipients() const; + [[nodiscard]] bool NSFW() const; + [[nodiscard]] bool IsDM() const noexcept; + [[nodiscard]] bool IsThread() const noexcept; + [[nodiscard]] bool IsJoinedThread() const; + [[nodiscard]] bool IsCategory() const noexcept; + [[nodiscard]] bool IsText() const noexcept; + [[nodiscard]] bool HasIcon() const noexcept; + [[nodiscard]] std::string GetIconURL() const; + [[nodiscard]] std::vector<Snowflake> GetChildIDs() const; + [[nodiscard]] std::optional<PermissionOverwrite> GetOverwrite(Snowflake id) const; + [[nodiscard]] std::vector<UserData> GetDMRecipients() const; }; diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index c11210d..7b9103e 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -1,8 +1,8 @@ #include "abaddon.hpp" #include "discord.hpp" #include "util.hpp" -#include <cassert> #include <cinttypes> +#include <utility> using namespace std::string_literals; @@ -68,10 +68,6 @@ bool DiscordClient::IsStoreValid() const { return m_store.IsValid(); } -const UserSettings &DiscordClient::GetUserSettings() const { - return m_user_settings; -} - std::unordered_set<Snowflake> DiscordClient::GetGuilds() const { return m_store.GetGuilds(); } @@ -87,7 +83,7 @@ std::vector<Snowflake> DiscordClient::GetUserSortedGuilds() const { auto guilds = GetGuilds(); for (const auto &entry : m_user_settings.GuildFolders) { // can contain guilds not a part of for (const auto &id : entry.GuildIDs) { - if (std::find(guilds.begin(), guilds.end(), id) != guilds.end()) + if (guilds.find(id) != guilds.end()) folder_order.push_back(id); } } @@ -115,19 +111,19 @@ std::vector<Message> DiscordClient::GetMessagesBefore(Snowflake channel_id, Snow return m_store.GetMessagesBefore(channel_id, message_id, limit); } -void DiscordClient::FetchInvite(std::string code, sigc::slot<void(std::optional<InviteData>)> callback) { - m_http.MakeGET("/invites/" + code + "?with_counts=true", [this, callback](http::response_type r) { +void DiscordClient::FetchInvite(const std::string &code, const sigc::slot<void(std::optional<InviteData>)> &callback) { + m_http.MakeGET("/invites/" + code + "?with_counts=true", [callback](http::response_type r) { if (!CheckCode(r)) { if (r.status_code == 404) callback(std::nullopt); return; - }; + } callback(nlohmann::json::parse(r.text).get<InviteData>()); }); } -void DiscordClient::FetchMessagesInChannel(Snowflake id, sigc::slot<void(const std::vector<Message> &)> cb) { +void DiscordClient::FetchMessagesInChannel(Snowflake id, const sigc::slot<void(const std::vector<Message> &)> &cb) { std::string path = "/channels/" + std::to_string(id) + "/messages?limit=50"; m_http.MakeGET(path, [this, id, cb](const http::response_type &r) { if (!CheckCode(r)) { @@ -164,9 +160,9 @@ void DiscordClient::FetchMessagesInChannel(Snowflake id, sigc::slot<void(const s }); } -void DiscordClient::FetchMessagesInChannelBefore(Snowflake channel_id, Snowflake before_id, sigc::slot<void(const std::vector<Message> &)> cb) { +void DiscordClient::FetchMessagesInChannelBefore(Snowflake channel_id, Snowflake before_id, const sigc::slot<void(const std::vector<Message> &)> &cb) { std::string path = "/channels/" + std::to_string(channel_id) + "/messages?limit=50&before=" + std::to_string(before_id); - m_http.MakeGET(path, [this, channel_id, cb](http::response_type r) { + m_http.MakeGET(path, [this, cb](http::response_type r) { if (!CheckCode(r)) return; std::vector<Message> msgs; @@ -210,10 +206,6 @@ std::optional<GuildMember> DiscordClient::GetMember(Snowflake user_id, Snowflake return m_store.GetGuildMember(guild_id, user_id); } -std::optional<BanData> DiscordClient::GetBan(Snowflake guild_id, Snowflake user_id) const { - return m_store.GetBan(guild_id, user_id); -} - std::optional<PermissionOverwrite> DiscordClient::GetPermissionOverwrite(Snowflake channel_id, Snowflake id) const { return m_store.GetPermissionOverwrite(channel_id, id); } @@ -243,14 +235,14 @@ std::optional<RoleData> DiscordClient::GetMemberHighestRole(Snowflake guild_id, const auto data = GetMember(user_id, guild_id); if (!data.has_value()) return std::nullopt; - if (data->Roles.size() == 0) return std::nullopt; + if (data->Roles.empty()) return std::nullopt; if (data->Roles.size() == 1) return GetRole(data->Roles[0]); std::vector<RoleData> roles; for (const auto id : data->Roles) roles.push_back(*GetRole(id)); - return *std::max_element(roles.begin(), roles.end(), [this](const auto &a, const auto &b) -> bool { + return *std::max_element(roles.begin(), roles.end(), [](const auto &a, const auto &b) -> bool { return a.Position < b.Position; }); } @@ -281,7 +273,7 @@ std::vector<ChannelData> DiscordClient::GetActiveThreads(Snowflake channel_id) c return m_store.GetActiveThreads(channel_id); } -void DiscordClient::GetArchivedPublicThreads(Snowflake channel_id, sigc::slot<void(DiscordError, const ArchivedThreadsResponseData &)> callback) { +void DiscordClient::GetArchivedPublicThreads(Snowflake channel_id, const sigc::slot<void(DiscordError, const ArchivedThreadsResponseData &)> &callback) { m_http.MakeGET("/channels/" + std::to_string(channel_id) + "/threads/archived/public", [this, callback](const http::response_type &r) { if (CheckCode(r)) { const auto data = nlohmann::json::parse(r.text).get<ArchivedThreadsResponseData>(); @@ -294,7 +286,7 @@ void DiscordClient::GetArchivedPublicThreads(Snowflake channel_id, sigc::slot<vo }); } -void DiscordClient::GetArchivedPrivateThreads(Snowflake channel_id, sigc::slot<void(DiscordError, const ArchivedThreadsResponseData &)> callback) { +void DiscordClient::GetArchivedPrivateThreads(Snowflake channel_id, const sigc::slot<void(DiscordError, const ArchivedThreadsResponseData &)> &callback) { m_http.MakeGET("/channels/" + std::to_string(channel_id) + "/users/@me/threads/archived/private", [this, callback](const http::response_type &r) { if (CheckCode(r)) { const auto data = nlohmann::json::parse(r.text).get<ArchivedThreadsResponseData>(); @@ -411,7 +403,7 @@ bool DiscordClient::CanManageMember(Snowflake guild_id, Snowflake actor, Snowfla return actor_highest->Position > target_highest->Position; } -void DiscordClient::ChatMessageCallback(std::string nonce, const http::response_type &response) { +void DiscordClient::ChatMessageCallback(const std::string &nonce, const http::response_type &response) { if (!CheckCode(response)) { if (response.status_code == http::TooManyRequests) { try { // not sure if this body is guaranteed @@ -481,7 +473,7 @@ void DiscordClient::DeleteMessage(Snowflake channel_id, Snowflake id) { void DiscordClient::EditMessage(Snowflake channel_id, Snowflake id, std::string content) { std::string path = "/channels/" + std::to_string(channel_id) + "/messages/" + std::to_string(id); MessageEditObject obj; - obj.Content = content; + obj.Content = std::move(content); nlohmann::json j = obj; m_http.MakePATCH(path, j.dump(), [](auto) {}); } @@ -516,7 +508,7 @@ void DiscordClient::SendThreadLazyLoad(Snowflake id) { m_websocket.Send(msg); } -void DiscordClient::JoinGuild(std::string code) { +void DiscordClient::JoinGuild(const std::string &code) { m_http.MakePOST("/invites/" + code, "{}", [](auto) {}); } @@ -554,14 +546,10 @@ void DiscordClient::UpdateStatus(PresenceStatus status, bool is_afk, const Activ m_signal_presence_update.emit(GetUserData(), status); } -void DiscordClient::CreateDM(Snowflake user_id) { - CreateDM(user_id, [](...) {}); -} - -void DiscordClient::CreateDM(Snowflake user_id, sigc::slot<void(DiscordError code, Snowflake channel_id)> callback) { +void DiscordClient::CreateDM(Snowflake user_id, const sigc::slot<void(DiscordError code, Snowflake channel_id)> &callback) { CreateDMObject obj; obj.Recipients.push_back(user_id); - m_http.MakePOST("/users/@me/channels", nlohmann::json(obj).dump(), [this, callback](const http::response &response) { + m_http.MakePOST("/users/@me/channels", nlohmann::json(obj).dump(), [callback](const http::response &response) { if (!CheckCode(response)) { callback(DiscordError::NONE, Snowflake::Invalid); return; @@ -572,7 +560,7 @@ void DiscordClient::CreateDM(Snowflake user_id, sigc::slot<void(DiscordError cod } void DiscordClient::CloseDM(Snowflake channel_id) { - m_http.MakeDELETE("/channels/" + std::to_string(channel_id), [this](const http::response &response) { + m_http.MakeDELETE("/channels/" + std::to_string(channel_id), [](const http::response &response) { CheckCode(response); }); } @@ -617,14 +605,10 @@ void DiscordClient::RemoveReaction(Snowflake id, Glib::ustring param) { m_http.MakeDELETE("/channels/" + std::to_string(channel_id) + "/messages/" + std::to_string(id) + "/reactions/" + param + "/@me", [](auto) {}); } -void DiscordClient::SetGuildName(Snowflake id, const Glib::ustring &name) { - SetGuildName(id, name, [](auto) {}); -} - -void DiscordClient::SetGuildName(Snowflake id, const Glib::ustring &name, sigc::slot<void(DiscordError code)> callback) { +void DiscordClient::SetGuildName(Snowflake id, const Glib::ustring &name, const sigc::slot<void(DiscordError code)> &callback) { ModifyGuildObject obj; obj.Name = name; - m_http.MakePATCH("/guilds/" + std::to_string(id), nlohmann::json(obj).dump(), [this, callback](const http::response_type &r) { + m_http.MakePATCH("/guilds/" + std::to_string(id), nlohmann::json(obj).dump(), [callback](const http::response_type &r) { if (CheckCode(r)) callback(DiscordError::NONE); else @@ -632,14 +616,10 @@ void DiscordClient::SetGuildName(Snowflake id, const Glib::ustring &name, sigc:: }); } -void DiscordClient::SetGuildIcon(Snowflake id, const std::string &data) { - SetGuildIcon(id, data, [](auto) {}); -} - -void DiscordClient::SetGuildIcon(Snowflake id, const std::string &data, sigc::slot<void(DiscordError code)> callback) { +void DiscordClient::SetGuildIcon(Snowflake id, const std::string &data, const sigc::slot<void(DiscordError code)> &callback) { ModifyGuildObject obj; obj.IconData = data; - m_http.MakePATCH("/guilds/" + std::to_string(id), nlohmann::json(obj).dump(), [this, callback](const http::response_type &r) { + m_http.MakePATCH("/guilds/" + std::to_string(id), nlohmann::json(obj).dump(), [callback](const http::response_type &r) { if (CheckCode(r)) callback(DiscordError::NONE); else @@ -647,12 +627,8 @@ void DiscordClient::SetGuildIcon(Snowflake id, const std::string &data, sigc::sl }); } -void DiscordClient::UnbanUser(Snowflake guild_id, Snowflake user_id) { - UnbanUser(guild_id, user_id, [](const auto) {}); -} - -void DiscordClient::UnbanUser(Snowflake guild_id, Snowflake user_id, sigc::slot<void(DiscordError code)> callback) { - m_http.MakeDELETE("/guilds/" + std::to_string(guild_id) + "/bans/" + std::to_string(user_id), [this, callback](const http::response_type &response) { +void DiscordClient::UnbanUser(Snowflake guild_id, Snowflake user_id, const sigc::slot<void(DiscordError code)> &callback) { + m_http.MakeDELETE("/guilds/" + std::to_string(guild_id) + "/bans/" + std::to_string(user_id), [callback](const http::response_type &response) { if (CheckCode(response, 204)) callback(DiscordError::NONE); else @@ -660,12 +636,8 @@ void DiscordClient::UnbanUser(Snowflake guild_id, Snowflake user_id, sigc::slot< }); } -void DiscordClient::DeleteInvite(const std::string &code) { - DeleteInvite(code, [](const auto) {}); -} - -void DiscordClient::DeleteInvite(const std::string &code, sigc::slot<void(DiscordError code)> callback) { - m_http.MakeDELETE("/invites/" + code, [this, callback](const http::response_type &response) { +void DiscordClient::DeleteInvite(const std::string &code, const sigc::slot<void(DiscordError code)> &callback) { + m_http.MakeDELETE("/invites/" + code, [callback](const http::response_type &response) { if (CheckCode(response)) callback(DiscordError::NONE); else @@ -674,21 +646,21 @@ void DiscordClient::DeleteInvite(const std::string &code, sigc::slot<void(Discor } void DiscordClient::AddGroupDMRecipient(Snowflake channel_id, Snowflake user_id) { - m_http.MakePUT("/channels/" + std::to_string(channel_id) + "/recipients/" + std::to_string(user_id), "", [this](const http::response_type &response) { + m_http.MakePUT("/channels/" + std::to_string(channel_id) + "/recipients/" + std::to_string(user_id), "", [](const http::response_type &response) { CheckCode(response); }); } void DiscordClient::RemoveGroupDMRecipient(Snowflake channel_id, Snowflake user_id) { - m_http.MakeDELETE("/channels/" + std::to_string(channel_id) + "/recipients/" + std::to_string(user_id), [this](const http::response_type &response) { + m_http.MakeDELETE("/channels/" + std::to_string(channel_id) + "/recipients/" + std::to_string(user_id), [](const http::response_type &response) { CheckCode(response); }); } -void DiscordClient::ModifyRolePermissions(Snowflake guild_id, Snowflake role_id, Permission permissions, sigc::slot<void(DiscordError code)> callback) { +void DiscordClient::ModifyRolePermissions(Snowflake guild_id, Snowflake role_id, Permission permissions, const sigc::slot<void(DiscordError code)> &callback) { ModifyGuildRoleObject obj; obj.Permissions = permissions; - m_http.MakePATCH("/guilds/" + std::to_string(guild_id) + "/roles/" + std::to_string(role_id), nlohmann::json(obj).dump(), [this, callback](const http::response_type &response) { + m_http.MakePATCH("/guilds/" + std::to_string(guild_id) + "/roles/" + std::to_string(role_id), nlohmann::json(obj).dump(), [callback](const http::response_type &response) { if (CheckCode(response)) callback(DiscordError::NONE); else @@ -696,10 +668,10 @@ void DiscordClient::ModifyRolePermissions(Snowflake guild_id, Snowflake role_id, }); } -void DiscordClient::ModifyRoleName(Snowflake guild_id, Snowflake role_id, const Glib::ustring &name, sigc::slot<void(DiscordError code)> callback) { +void DiscordClient::ModifyRoleName(Snowflake guild_id, Snowflake role_id, const Glib::ustring &name, const sigc::slot<void(DiscordError code)> &callback) { ModifyGuildRoleObject obj; obj.Name = name; - m_http.MakePATCH("/guilds/" + std::to_string(guild_id) + "/roles/" + std::to_string(role_id), nlohmann::json(obj).dump(), [this, callback](const http::response_type &response) { + m_http.MakePATCH("/guilds/" + std::to_string(guild_id) + "/roles/" + std::to_string(role_id), nlohmann::json(obj).dump(), [callback](const http::response_type &response) { if (CheckCode(response)) callback(DiscordError::NONE); else @@ -707,10 +679,10 @@ void DiscordClient::ModifyRoleName(Snowflake guild_id, Snowflake role_id, const }); } -void DiscordClient::ModifyRoleColor(Snowflake guild_id, Snowflake role_id, uint32_t color, sigc::slot<void(DiscordError code)> callback) { +void DiscordClient::ModifyRoleColor(Snowflake guild_id, Snowflake role_id, uint32_t color, const sigc::slot<void(DiscordError code)> &callback) { ModifyGuildRoleObject obj; obj.Color = color; - m_http.MakePATCH("/guilds/" + std::to_string(guild_id) + "/roles/" + std::to_string(role_id), nlohmann::json(obj).dump(), [this, callback](const http::response_type &response) { + m_http.MakePATCH("/guilds/" + std::to_string(guild_id) + "/roles/" + std::to_string(role_id), nlohmann::json(obj).dump(), [callback](const http::response_type &response) { if (CheckCode(response)) callback(DiscordError::NONE); else @@ -718,7 +690,7 @@ void DiscordClient::ModifyRoleColor(Snowflake guild_id, Snowflake role_id, uint3 }); } -void DiscordClient::ModifyRoleColor(Snowflake guild_id, Snowflake role_id, Gdk::RGBA color, sigc::slot<void(DiscordError code)> callback) { +void DiscordClient::ModifyRoleColor(Snowflake guild_id, Snowflake role_id, const Gdk::RGBA &color, const sigc::slot<void(DiscordError code)> &callback) { uint32_t int_color = 0; int_color |= static_cast<uint32_t>(color.get_blue() * 255.0) << 0; int_color |= static_cast<uint32_t>(color.get_green() * 255.0) << 8; @@ -726,7 +698,7 @@ void DiscordClient::ModifyRoleColor(Snowflake guild_id, Snowflake role_id, Gdk:: ModifyRoleColor(guild_id, role_id, int_color, callback); } -void DiscordClient::ModifyRolePosition(Snowflake guild_id, Snowflake role_id, int position, sigc::slot<void(DiscordError code)> callback) { +void DiscordClient::ModifyRolePosition(Snowflake guild_id, Snowflake role_id, int position, const sigc::slot<void(DiscordError code)> &callback) { const auto guild = GetGuild(guild_id); if (!guild.has_value() || !guild->Roles.has_value()) return; const auto &roles = *guild->Roles; @@ -763,7 +735,7 @@ void DiscordClient::ModifyRolePosition(Snowflake guild_id, Snowflake role_id, in for (size_t i = range_from; i < range_to; i++) obj.Positions.push_back({ roles[i].ID, roles[i].Position + dir }); - m_http.MakePATCH("/guilds/" + std::to_string(guild_id) + "/roles", nlohmann::json(obj).dump(), [this, callback](const http::response_type &response) { + m_http.MakePATCH("/guilds/" + std::to_string(guild_id) + "/roles", nlohmann::json(obj).dump(), [callback](const http::response_type &response) { if (CheckCode(response)) callback(DiscordError::NONE); else @@ -771,11 +743,11 @@ void DiscordClient::ModifyRolePosition(Snowflake guild_id, Snowflake role_id, in }); } -void DiscordClient::ModifyEmojiName(Snowflake guild_id, Snowflake emoji_id, const Glib::ustring &name, sigc::slot<void(DiscordError code)> callback) { +void DiscordClient::ModifyEmojiName(Snowflake guild_id, Snowflake emoji_id, const Glib::ustring &name, const sigc::slot<void(DiscordError code)> &callback) { ModifyGuildEmojiObject obj; obj.Name = name; - m_http.MakePATCH("/guilds/" + std::to_string(guild_id) + "/emojis/" + std::to_string(emoji_id), nlohmann::json(obj).dump(), [this, callback](const http::response_type &response) { + m_http.MakePATCH("/guilds/" + std::to_string(guild_id) + "/emojis/" + std::to_string(emoji_id), nlohmann::json(obj).dump(), [callback](const http::response_type &response) { if (CheckCode(response)) callback(DiscordError::NONE); else @@ -783,8 +755,8 @@ void DiscordClient::ModifyEmojiName(Snowflake guild_id, Snowflake emoji_id, cons }); } -void DiscordClient::DeleteEmoji(Snowflake guild_id, Snowflake emoji_id, sigc::slot<void(DiscordError code)> callback) { - m_http.MakeDELETE("/guilds/" + std::to_string(guild_id) + "/emojis/" + std::to_string(emoji_id), [this, callback](const http::response_type &response) { +void DiscordClient::DeleteEmoji(Snowflake guild_id, Snowflake emoji_id, const sigc::slot<void(DiscordError code)> &callback) { + m_http.MakeDELETE("/guilds/" + std::to_string(guild_id) + "/emojis/" + std::to_string(emoji_id), [callback](const http::response_type &response) { if (CheckCode(response, 204)) callback(DiscordError::NONE); else @@ -792,14 +764,8 @@ void DiscordClient::DeleteEmoji(Snowflake guild_id, Snowflake emoji_id, sigc::sl }); } -std::optional<GuildApplicationData> DiscordClient::GetGuildApplication(Snowflake guild_id) const { - const auto it = m_guild_join_requests.find(guild_id); - if (it == m_guild_join_requests.end()) return std::nullopt; - return it->second; -} - -void DiscordClient::RemoveRelationship(Snowflake id, sigc::slot<void(DiscordError Code)> callback) { - m_http.MakeDELETE("/users/@me/relationships/" + std::to_string(id), [this, callback](const http::response_type &response) { +void DiscordClient::RemoveRelationship(Snowflake id, const sigc::slot<void(DiscordError Code)> &callback) { + m_http.MakeDELETE("/users/@me/relationships/" + std::to_string(id), [callback](const http::response_type &response) { if (CheckCode(response)) callback(DiscordError::NONE); else @@ -807,11 +773,11 @@ void DiscordClient::RemoveRelationship(Snowflake id, sigc::slot<void(DiscordErro }); } -void DiscordClient::SendFriendRequest(const Glib::ustring &username, int discriminator, sigc::slot<void(DiscordError code)> callback) { +void DiscordClient::SendFriendRequest(const Glib::ustring &username, int discriminator, const sigc::slot<void(DiscordError code)> &callback) { FriendRequestObject obj; obj.Username = username; obj.Discriminator = discriminator; - m_http.MakePOST("/users/@me/relationships", nlohmann::json(obj).dump(), [this, callback](const http::response_type &response) { + m_http.MakePOST("/users/@me/relationships", nlohmann::json(obj).dump(), [callback](const http::response_type &response) { if (CheckCode(response, 204)) callback(DiscordError::NONE); else @@ -819,8 +785,8 @@ void DiscordClient::SendFriendRequest(const Glib::ustring &username, int discrim }); } -void DiscordClient::PutRelationship(Snowflake id, sigc::slot<void(DiscordError code)> callback) { - m_http.MakePUT("/users/@me/relationships/" + std::to_string(id), "{}", [this, callback](const http::response_type &response) { +void DiscordClient::PutRelationship(Snowflake id, const sigc::slot<void(DiscordError code)> &callback) { + m_http.MakePUT("/users/@me/relationships/" + std::to_string(id), "{}", [callback](const http::response_type &response) { if (CheckCode(response, 204)) callback(DiscordError::NONE); else @@ -828,8 +794,8 @@ void DiscordClient::PutRelationship(Snowflake id, sigc::slot<void(DiscordError c }); } -void DiscordClient::Pin(Snowflake channel_id, Snowflake message_id, sigc::slot<void(DiscordError code)> callback) { - m_http.MakePUT("/channels/" + std::to_string(channel_id) + "/pins/" + std::to_string(message_id), "", [this, callback](const http::response_type &response) { +void DiscordClient::Pin(Snowflake channel_id, Snowflake message_id, const sigc::slot<void(DiscordError code)> &callback) { + m_http.MakePUT("/channels/" + std::to_string(channel_id) + "/pins/" + std::to_string(message_id), "", [callback](const http::response_type &response) { if (CheckCode(response, 204)) callback(DiscordError::NONE); else @@ -837,8 +803,8 @@ void DiscordClient::Pin(Snowflake channel_id, Snowflake message_id, sigc::slot<v }); } -void DiscordClient::Unpin(Snowflake channel_id, Snowflake message_id, sigc::slot<void(DiscordError code)> callback) { - m_http.MakeDELETE("/channels/" + std::to_string(channel_id) + "/pins/" + std::to_string(message_id), [this, callback](const http::response_type &response) { +void DiscordClient::Unpin(Snowflake channel_id, Snowflake message_id, const sigc::slot<void(DiscordError code)> &callback) { + m_http.MakeDELETE("/channels/" + std::to_string(channel_id) + "/pins/" + std::to_string(message_id), [callback](const http::response_type &response) { if (CheckCode(response, 204)) callback(DiscordError::NONE); else @@ -848,8 +814,8 @@ void DiscordClient::Unpin(Snowflake channel_id, Snowflake message_id, sigc::slot // i dont know if the location parameter is necessary at all but discord's thread implementation is extremely strange // so its here just in case -void DiscordClient::LeaveThread(Snowflake channel_id, const std::string &location, sigc::slot<void(DiscordError code)> callback) { - m_http.MakeDELETE("/channels/" + std::to_string(channel_id) + "/thread-members/@me?location=" + location, [this, callback](const http::response_type &response) { +void DiscordClient::LeaveThread(Snowflake channel_id, const std::string &location, const sigc::slot<void(DiscordError code)> &callback) { + m_http.MakeDELETE("/channels/" + std::to_string(channel_id) + "/thread-members/@me?location=" + location, [callback](const http::response_type &response) { if (CheckCode(response, 204)) callback(DiscordError::NONE); else @@ -857,11 +823,11 @@ void DiscordClient::LeaveThread(Snowflake channel_id, const std::string &locatio }); } -void DiscordClient::ArchiveThread(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback) { +void DiscordClient::ArchiveThread(Snowflake channel_id, const sigc::slot<void(DiscordError code)> &callback) { ModifyChannelObject obj; obj.Archived = true; obj.Locked = true; - m_http.MakePATCH("/channels/" + std::to_string(channel_id), nlohmann::json(obj).dump(), [this, callback](const http::response_type &response) { + m_http.MakePATCH("/channels/" + std::to_string(channel_id), nlohmann::json(obj).dump(), [callback](const http::response_type &response) { if (CheckCode(response)) callback(DiscordError::NONE); else @@ -869,11 +835,11 @@ void DiscordClient::ArchiveThread(Snowflake channel_id, sigc::slot<void(DiscordE }); } -void DiscordClient::UnArchiveThread(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback) { +void DiscordClient::UnArchiveThread(Snowflake channel_id, const sigc::slot<void(DiscordError code)> &callback) { ModifyChannelObject obj; obj.Archived = false; obj.Locked = false; - m_http.MakePATCH("/channels/" + std::to_string(channel_id), nlohmann::json(obj).dump(), [this, callback](const http::response_type &response) { + m_http.MakePATCH("/channels/" + std::to_string(channel_id), nlohmann::json(obj).dump(), [callback](const http::response_type &response) { if (CheckCode(response)) callback(DiscordError::NONE); else @@ -881,11 +847,11 @@ void DiscordClient::UnArchiveThread(Snowflake channel_id, sigc::slot<void(Discor }); } -void DiscordClient::MarkChannelAsRead(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback) { +void DiscordClient::MarkChannelAsRead(Snowflake channel_id, const sigc::slot<void(DiscordError code)> &callback) { if (m_unread.find(channel_id) == m_unread.end()) return; const auto iter = m_last_message_id.find(channel_id); if (iter == m_last_message_id.end()) return; - m_http.MakePOST("/channels/" + std::to_string(channel_id) + "/messages/" + std::to_string(iter->second) + "/ack", "{\"token\":null}", [this, callback](const http::response_type &response) { + m_http.MakePOST("/channels/" + std::to_string(channel_id) + "/messages/" + std::to_string(iter->second) + "/ack", "{\"token\":null}", [callback](const http::response_type &response) { if (CheckCode(response)) callback(DiscordError::NONE); else @@ -893,7 +859,7 @@ void DiscordClient::MarkChannelAsRead(Snowflake channel_id, sigc::slot<void(Disc }); } -void DiscordClient::MarkGuildAsRead(Snowflake guild_id, sigc::slot<void(DiscordError code)> callback) { +void DiscordClient::MarkGuildAsRead(Snowflake guild_id, const sigc::slot<void(DiscordError code)> &callback) { AckBulkData data; const auto channels = GetChannelsInGuild(guild_id); for (const auto &[unread, mention_count] : m_unread) { @@ -908,7 +874,7 @@ void DiscordClient::MarkGuildAsRead(Snowflake guild_id, sigc::slot<void(DiscordE if (data.ReadStates.empty()) return; - m_http.MakePOST("/read-states/ack-bulk", nlohmann::json(data).dump(), [this, callback](const http::response_type &response) { + m_http.MakePOST("/read-states/ack-bulk", nlohmann::json(data).dump(), [callback](const http::response_type &response) { if (CheckCode(response)) callback(DiscordError::NONE); else @@ -916,14 +882,14 @@ void DiscordClient::MarkGuildAsRead(Snowflake guild_id, sigc::slot<void(DiscordE }); } -void DiscordClient::MuteChannel(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback) { +void DiscordClient::MuteChannel(Snowflake channel_id, const sigc::slot<void(DiscordError code)> &callback) { const auto channel = GetChannel(channel_id); if (!channel.has_value()) return; const auto guild_id_path = channel->GuildID.has_value() ? std::to_string(*channel->GuildID) : "@me"s; nlohmann::json j; j["channel_overrides"][std::to_string(channel_id)]["mute_config"] = MuteConfigData { std::nullopt, -1 }; j["channel_overrides"][std::to_string(channel_id)]["muted"] = true; - m_http.MakePATCH("/users/@me/guilds/" + guild_id_path + "/settings", j.dump(), [this, callback](const http::response_type &response) { + m_http.MakePATCH("/users/@me/guilds/" + guild_id_path + "/settings", j.dump(), [callback](const http::response_type &response) { if (CheckCode(response)) callback(DiscordError::NONE); else @@ -931,13 +897,13 @@ void DiscordClient::MuteChannel(Snowflake channel_id, sigc::slot<void(DiscordErr }); } -void DiscordClient::UnmuteChannel(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback) { +void DiscordClient::UnmuteChannel(Snowflake channel_id, const sigc::slot<void(DiscordError code)> &callback) { const auto channel = GetChannel(channel_id); if (!channel.has_value()) return; const auto guild_id_path = channel->GuildID.has_value() ? std::to_string(*channel->GuildID) : "@me"s; nlohmann::json j; j["channel_overrides"][std::to_string(channel_id)]["muted"] = false; - m_http.MakePATCH("/users/@me/guilds/" + guild_id_path + "/settings", j.dump(), [this, callback](const http::response_type &response) { + m_http.MakePATCH("/users/@me/guilds/" + guild_id_path + "/settings", j.dump(), [callback](const http::response_type &response) { if (CheckCode(response)) callback(DiscordError::NONE); else @@ -945,7 +911,7 @@ void DiscordClient::UnmuteChannel(Snowflake channel_id, sigc::slot<void(DiscordE }); } -void DiscordClient::MarkAllAsRead(sigc::slot<void(DiscordError code)> callback) { +void DiscordClient::MarkAllAsRead(const sigc::slot<void(DiscordError code)> &callback) { AckBulkData data; for (const auto &[unread, mention_count] : m_unread) { const auto iter = m_last_message_id.find(unread); @@ -957,7 +923,7 @@ void DiscordClient::MarkAllAsRead(sigc::slot<void(DiscordError code)> callback) if (data.ReadStates.empty()) return; - m_http.MakePOST("/read-states/ack-bulk", nlohmann::json(data).dump(), [this, callback](const http::response_type &response) { + m_http.MakePOST("/read-states/ack-bulk", nlohmann::json(data).dump(), [callback](const http::response_type &response) { if (CheckCode(response)) callback(DiscordError::NONE); else @@ -965,8 +931,8 @@ void DiscordClient::MarkAllAsRead(sigc::slot<void(DiscordError code)> callback) }); } -void DiscordClient::MuteGuild(Snowflake id, sigc::slot<void(DiscordError code)> callback) { - m_http.MakePATCH("/users/@me/guilds/" + std::to_string(id) + "/settings", R"({"muted":true})", [this, callback](const http::response_type &response) { +void DiscordClient::MuteGuild(Snowflake id, const sigc::slot<void(DiscordError code)> &callback) { + m_http.MakePATCH("/users/@me/guilds/" + std::to_string(id) + "/settings", R"({"muted":true})", [callback](const http::response_type &response) { if (CheckCode(response)) callback(DiscordError::NONE); else @@ -974,8 +940,8 @@ void DiscordClient::MuteGuild(Snowflake id, sigc::slot<void(DiscordError code)> }); } -void DiscordClient::UnmuteGuild(Snowflake id, sigc::slot<void(DiscordError code)> callback) { - m_http.MakePATCH("/users/@me/guilds/" + std::to_string(id) + "/settings", R"({"muted":false})", [this, callback](const http::response_type &response) { +void DiscordClient::UnmuteGuild(Snowflake id, const sigc::slot<void(DiscordError code)> &callback) { + m_http.MakePATCH("/users/@me/guilds/" + std::to_string(id) + "/settings", R"({"muted":false})", [callback](const http::response_type &response) { if (CheckCode(response)) callback(DiscordError::NONE); else @@ -983,8 +949,8 @@ void DiscordClient::UnmuteGuild(Snowflake id, sigc::slot<void(DiscordError code) }); } -void DiscordClient::MuteThread(Snowflake id, sigc::slot<void(DiscordError code)> callback) { - m_http.MakePATCH("/channels/" + std::to_string(id) + "/thread-members/@me/settings", R"({"muted":true})", [this, callback](const http::response_type &response) { +void DiscordClient::MuteThread(Snowflake id, const sigc::slot<void(DiscordError code)> &callback) { + m_http.MakePATCH("/channels/" + std::to_string(id) + "/thread-members/@me/settings", R"({"muted":true})", [callback](const http::response_type &response) { if (CheckCode(response)) callback(DiscordError::NONE); else @@ -992,8 +958,8 @@ void DiscordClient::MuteThread(Snowflake id, sigc::slot<void(DiscordError code)> }); } -void DiscordClient::UnmuteThread(Snowflake id, sigc::slot<void(DiscordError code)> callback) { - m_http.MakePATCH("/channels/" + std::to_string(id) + "/thread-members/@me/settings", R"({"muted":false})", [this, callback](const http::response_type &response) { +void DiscordClient::UnmuteThread(Snowflake id, const sigc::slot<void(DiscordError code)> &callback) { + m_http.MakePATCH("/channels/" + std::to_string(id) + "/thread-members/@me/settings", R"({"muted":false})", [callback](const http::response_type &response) { if (CheckCode(response)) callback(DiscordError::NONE); else @@ -1001,7 +967,7 @@ void DiscordClient::UnmuteThread(Snowflake id, sigc::slot<void(DiscordError code }); } -void DiscordClient::FetchPinned(Snowflake id, sigc::slot<void(std::vector<Message>, DiscordError code)> callback) { +void DiscordClient::FetchPinned(Snowflake id, const sigc::slot<void(std::vector<Message>, DiscordError code)> &callback) { // return from db if we know the pins have already been requested if (m_channels_pinned_requested.find(id) != m_channels_pinned_requested.end()) { callback(m_store.GetPinnedMessages(id), DiscordError::NONE); @@ -1019,7 +985,7 @@ void DiscordClient::FetchPinned(Snowflake id, sigc::slot<void(std::vector<Messag std::sort(data.begin(), data.end(), [](const Message &a, const Message &b) { return a.ID < b.ID; }); for (auto &msg : data) StoreMessageData(msg); - callback(std::move(data), DiscordError::NONE); + callback(data, DiscordError::NONE); }); } @@ -1040,7 +1006,7 @@ std::vector<BanData> DiscordClient::GetBansInGuild(Snowflake guild_id) { return m_store.GetBans(guild_id); } -void DiscordClient::FetchGuildBan(Snowflake guild_id, Snowflake user_id, sigc::slot<void(BanData)> callback) { +void DiscordClient::FetchGuildBan(Snowflake guild_id, Snowflake user_id, const sigc::slot<void(BanData)> &callback) { m_http.MakeGET("/guilds/" + std::to_string(guild_id) + "/bans/" + std::to_string(user_id), [this, callback, guild_id](const http::response_type &response) { if (!CheckCode(response)) return; auto ban = nlohmann::json::parse(response.text).get<BanData>(); @@ -1050,7 +1016,7 @@ void DiscordClient::FetchGuildBan(Snowflake guild_id, Snowflake user_id, sigc::s }); } -void DiscordClient::FetchGuildBans(Snowflake guild_id, sigc::slot<void(std::vector<BanData>)> callback) { +void DiscordClient::FetchGuildBans(Snowflake guild_id, const sigc::slot<void(std::vector<BanData>)> &callback) { m_http.MakeGET("/guilds/" + std::to_string(guild_id) + "/bans", [this, callback, guild_id](const http::response_type &response) { if (!CheckCode(response)) return; auto bans = nlohmann::json::parse(response.text).get<std::vector<BanData>>(); @@ -1064,8 +1030,8 @@ void DiscordClient::FetchGuildBans(Snowflake guild_id, sigc::slot<void(std::vect }); } -void DiscordClient::FetchGuildInvites(Snowflake guild_id, sigc::slot<void(std::vector<InviteData>)> callback) { - m_http.MakeGET("/guilds/" + std::to_string(guild_id) + "/invites", [this, callback, guild_id](const http::response_type &response) { +void DiscordClient::FetchGuildInvites(Snowflake guild_id, const sigc::slot<void(std::vector<InviteData>)> &callback) { + m_http.MakeGET("/guilds/" + std::to_string(guild_id) + "/invites", [this, callback](const http::response_type &response) { // store? if (!CheckCode(response)) return; auto invites = nlohmann::json::parse(response.text).get<std::vector<InviteData>>(); @@ -1080,7 +1046,7 @@ void DiscordClient::FetchGuildInvites(Snowflake guild_id, sigc::slot<void(std::v }); } -void DiscordClient::FetchAuditLog(Snowflake guild_id, sigc::slot<void(AuditLogData)> callback) { +void DiscordClient::FetchAuditLog(Snowflake guild_id, const sigc::slot<void(AuditLogData)> &callback) { m_http.MakeGET("/guilds/" + std::to_string(guild_id) + "/audit-logs", [this, callback](const http::response &response) { if (!CheckCode(response)) return; auto data = nlohmann::json::parse(response.text).get<AuditLogData>(); @@ -1094,7 +1060,7 @@ void DiscordClient::FetchAuditLog(Snowflake guild_id, sigc::slot<void(AuditLogDa }); } -void DiscordClient::FetchGuildEmojis(Snowflake guild_id, sigc::slot<void(std::vector<EmojiData>)> callback) { +void DiscordClient::FetchGuildEmojis(Snowflake guild_id, const sigc::slot<void(std::vector<EmojiData>)> &callback) { m_http.MakeGET("/guilds/" + std::to_string(guild_id) + "/emojis", [this, callback](const http::response_type &response) { if (!CheckCode(response)) return; auto emojis = nlohmann::json::parse(response.text).get<std::vector<EmojiData>>(); @@ -1102,19 +1068,19 @@ void DiscordClient::FetchGuildEmojis(Snowflake guild_id, sigc::slot<void(std::ve for (const auto &emoji : emojis) m_store.SetEmoji(emoji.ID, emoji); m_store.EndTransaction(); - callback(std::move(emojis)); + callback(emojis); }); } -void DiscordClient::FetchUserProfile(Snowflake user_id, sigc::slot<void(UserProfileData)> callback) { - m_http.MakeGET("/users/" + std::to_string(user_id) + "/profile", [this, callback](const http::response_type &response) { +void DiscordClient::FetchUserProfile(Snowflake user_id, const sigc::slot<void(UserProfileData)> &callback) { + m_http.MakeGET("/users/" + std::to_string(user_id) + "/profile", [callback](const http::response_type &response) { if (!CheckCode(response)) return; callback(nlohmann::json::parse(response.text).get<UserProfileData>()); }); } -void DiscordClient::FetchUserNote(Snowflake user_id, sigc::slot<void(std::string note)> callback) { - m_http.MakeGET("/users/@me/notes/" + std::to_string(user_id), [this, callback](const http::response_type &response) { +void DiscordClient::FetchUserNote(Snowflake user_id, const sigc::slot<void(std::string note)> &callback) { + m_http.MakeGET("/users/@me/notes/" + std::to_string(user_id), [callback](const http::response_type &response) { if (response.status_code == 404) return; if (!CheckCode(response)) return; const auto note = nlohmann::json::parse(response.text).get<UserNoteObject>().Note; @@ -1123,14 +1089,10 @@ void DiscordClient::FetchUserNote(Snowflake user_id, sigc::slot<void(std::string }); } -void DiscordClient::SetUserNote(Snowflake user_id, std::string note) { - SetUserNote(user_id, note, [](auto) {}); -} - -void DiscordClient::SetUserNote(Snowflake user_id, std::string note, sigc::slot<void(DiscordError code)> callback) { +void DiscordClient::SetUserNote(Snowflake user_id, std::string note, const sigc::slot<void(DiscordError code)> &callback) { UserSetNoteObject obj; - obj.Note = note; - m_http.MakePUT("/users/@me/notes/" + std::to_string(user_id), nlohmann::json(obj).dump(), [this, callback](const http::response_type &response) { + obj.Note = std::move(note); + m_http.MakePUT("/users/@me/notes/" + std::to_string(user_id), nlohmann::json(obj).dump(), [callback](const http::response_type &response) { if (CheckCode(response, 204)) callback(DiscordError::NONE); else @@ -1138,7 +1100,7 @@ void DiscordClient::SetUserNote(Snowflake user_id, std::string note, sigc::slot< }); } -void DiscordClient::FetchUserRelationships(Snowflake user_id, sigc::slot<void(std::vector<UserData>)> callback) { +void DiscordClient::FetchUserRelationships(Snowflake user_id, const sigc::slot<void(std::vector<UserData>)> &callback) { m_http.MakeGET("/users/" + std::to_string(user_id) + "/relationships", [this, callback](const http::response_type &response) { if (!CheckCode(response)) return; RelationshipsData data = nlohmann::json::parse(response.text); @@ -1148,26 +1110,26 @@ void DiscordClient::FetchUserRelationships(Snowflake user_id, sigc::slot<void(st }); } -bool DiscordClient::IsVerificationRequired(Snowflake guild_id) { +bool DiscordClient::IsVerificationRequired(Snowflake guild_id) const { 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) { +void DiscordClient::GetVerificationGateInfo(Snowflake guild_id, const sigc::slot<void(std::optional<VerificationGateInfoObject>)> &callback) { + m_http.MakeGET("/guilds/" + std::to_string(guild_id) + "/member-verification", [callback](const http::response_type &response) { if (!CheckCode(response)) return; if (response.status_code == 204) callback(std::nullopt); callback(nlohmann::json::parse(response.text).get<VerificationGateInfoObject>()); }); } -void DiscordClient::AcceptVerificationGate(Snowflake guild_id, VerificationGateInfoObject info, sigc::slot<void(DiscordError code)> callback) { +void DiscordClient::AcceptVerificationGate(Snowflake guild_id, VerificationGateInfoObject info, const sigc::slot<void(DiscordError code)> &callback) { if (info.VerificationFields.has_value()) for (auto &field : *info.VerificationFields) field.Response = true; - m_http.MakePUT("/guilds/" + std::to_string(guild_id) + "/requests/@me", nlohmann::json(info).dump(), [this, callback](const http::response_type &response) { + m_http.MakePUT("/guilds/" + std::to_string(guild_id) + "/requests/@me", nlohmann::json(info).dump(), [callback](const http::response_type &response) { if (CheckCode(response)) callback(DiscordError::NONE); else @@ -1175,14 +1137,14 @@ void DiscordClient::AcceptVerificationGate(Snowflake guild_id, VerificationGateI }); } -void DiscordClient::UpdateToken(std::string token) { +void DiscordClient::UpdateToken(const std::string &token) { if (!IsStarted()) { m_token = token; m_http.SetAuth(token); } } -void DiscordClient::SetUserAgent(std::string agent) { +void DiscordClient::SetUserAgent(const std::string &agent) { m_http.SetUserAgent(agent); m_websocket.SetUserAgent(agent); } @@ -1483,7 +1445,7 @@ void DiscordClient::HandleGatewayHello(const GatewayMessage &msg) { HelloMessageData d = msg.Data; m_heartbeat_msec = d.HeartbeatInterval; m_heartbeat_waiter.revive(); - m_heartbeat_thread = std::thread(std::bind(&DiscordClient::HeartbeatThread, this)); + m_heartbeat_thread = std::thread([this] { HeartbeatThread(); }); m_signal_connected.emit(); // socket is connected before this but emitting here should b fine m_reconnecting = false; // maybe should go elsewhere? if (m_wants_resume) { @@ -1736,7 +1698,7 @@ void DiscordClient::HandleGatewayGuildRoleCreate(const GatewayMessage &msg) { void DiscordClient::HandleGatewayGuildRoleDelete(const GatewayMessage &msg) { GuildRoleDeleteObject data = msg.Data; auto guild = *m_store.GetGuild(data.GuildID); - const auto pred = [this, id = data.RoleID](const RoleData &role) -> bool { + const auto pred = [id = data.RoleID](const RoleData &role) -> bool { return role.ID == id; }; guild.Roles->erase(std::remove_if(guild.Roles->begin(), guild.Roles->end(), pred), guild.Roles->end()); @@ -1826,12 +1788,12 @@ void DiscordClient::HandleGatewayInviteCreate(const GatewayMessage &msg) { invite.CreatedAt = std::move(data.CreatedAt); invite.Channel = *m_store.GetChannel(data.ChannelID); invite.Inviter = std::move(data.Inviter); - invite.IsTemporary = std::move(data.IsTemporary); - invite.MaxAge = std::move(data.MaxAge); - invite.MaxUses = std::move(data.MaxUses); + invite.IsTemporary = data.IsTemporary; + invite.MaxAge = data.MaxAge; + invite.MaxUses = data.MaxUses; invite.TargetUser = std::move(data.TargetUser); - invite.TargetUserType = std::move(data.TargetUserType); - invite.Uses = std::move(data.Uses); + invite.TargetUserType = data.TargetUserType; + invite.Uses = data.Uses; if (data.GuildID.has_value()) invite.Guild = m_store.GetGuild(*data.GuildID); m_signal_invite_create.emit(invite); @@ -1893,7 +1855,7 @@ void DiscordClient::HandleGatewayRelationshipAdd(const GatewayMessage &msg) { RelationshipAddData data = msg.Data; m_store.SetUser(data.ID, data.User); m_user_relationships[data.ID] = data.Type; - m_signal_relationship_add.emit(std::move(data)); + m_signal_relationship_add.emit(data); } // remarkably this doesnt actually mean a thread was created @@ -2168,7 +2130,7 @@ void DiscordClient::HandleGatewayGuildMemberListUpdate(const GatewayMessage &msg has_sync = true; for (const auto &item : *op.Items) { if (item->Type == "member") { - auto member = static_cast<const GuildMemberListUpdateMessage::MemberItem *>(item.get()); + auto member = dynamic_cast<const GuildMemberListUpdateMessage::MemberItem *>(item.get()); m_store.SetUser(member->User.ID, member->User); AddUserToGuild(member->User.ID, data.GuildID); m_store.SetGuildMember(data.GuildID, member->User.ID, member->GetAsMemberData()); @@ -2187,7 +2149,7 @@ void DiscordClient::HandleGatewayGuildMemberListUpdate(const GatewayMessage &msg } } else if (op.Op == "UPDATE") { if (op.OpItem.has_value() && op.OpItem.value()->Type == "member") { - const auto &m = static_cast<const GuildMemberListUpdateMessage::MemberItem *>(op.OpItem.value().get())->GetAsMemberData(); + const auto &m = dynamic_cast<const GuildMemberListUpdateMessage::MemberItem *>(op.OpItem.value().get())->GetAsMemberData(); m_store.SetGuildMember(data.GuildID, m.User->ID, m); m_signal_guild_member_update.emit(data.GuildID, m.User->ID); // cheeky } @@ -2472,12 +2434,6 @@ void DiscordClient::HandleReadyGuildSettings(const ReadyEventData &data) { } } -void DiscordClient::HandleUserGuildSettingsUpdateForDMs(const UserGuildSettingsUpdateData &data) { - const auto channels = GetPrivateChannels(); - std::set<Snowflake> now_muted_channels; - const auto now = Snowflake::FromNow(); -} - void DiscordClient::LoadEventMap() { m_event_map["READY"] = GatewayEvent::READY; m_event_map["MESSAGE_CREATE"] = GatewayEvent::MESSAGE_CREATE; diff --git a/src/discord/discord.hpp b/src/discord/discord.hpp index 6add18f..7b0a00e 100644 --- a/src/discord/discord.hpp +++ b/src/discord/discord.hpp @@ -55,7 +55,6 @@ public: std::unordered_set<Snowflake> GetGuilds() const; const UserData &GetUserData() const; - const UserSettings &GetUserSettings() const; std::vector<Snowflake> GetUserSortedGuilds() const; std::vector<Message> GetMessagesForChannel(Snowflake id, size_t limit = 50) const; std::vector<Message> GetMessagesBefore(Snowflake channel_id, Snowflake message_id, size_t limit = 50) const; @@ -63,8 +62,8 @@ public: EPremiumType GetSelfPremiumType() const; - void FetchMessagesInChannel(Snowflake id, sigc::slot<void(const std::vector<Message> &)> cb); - void FetchMessagesInChannelBefore(Snowflake channel_id, Snowflake before_id, sigc::slot<void(const std::vector<Message> &)> cb); + void FetchMessagesInChannel(Snowflake id, const sigc::slot<void(const std::vector<Message> &)> &cb); + void FetchMessagesInChannelBefore(Snowflake channel_id, Snowflake before_id, const sigc::slot<void(const std::vector<Message> &)> &cb); std::optional<Message> GetMessage(Snowflake id) const; std::optional<ChannelData> GetChannel(Snowflake id) const; std::optional<EmojiData> GetEmoji(Snowflake id) const; @@ -73,15 +72,14 @@ public: std::optional<RoleData> GetRole(Snowflake id) const; std::optional<GuildData> GetGuild(Snowflake id) const; std::optional<GuildMember> GetMember(Snowflake user_id, Snowflake guild_id) const; - std::optional<BanData> GetBan(Snowflake guild_id, Snowflake user_id) const; Snowflake GetMemberHoistedRole(Snowflake guild_id, Snowflake user_id, bool with_color = false) const; std::optional<RoleData> GetMemberHighestRole(Snowflake guild_id, Snowflake user_id) const; std::set<Snowflake> GetUsersInGuild(Snowflake id) const; std::set<Snowflake> GetChannelsInGuild(Snowflake id) const; std::vector<Snowflake> GetUsersInThread(Snowflake id) const; std::vector<ChannelData> GetActiveThreads(Snowflake channel_id) const; - void GetArchivedPublicThreads(Snowflake channel_id, sigc::slot<void(DiscordError, const ArchivedThreadsResponseData &)> callback); - void GetArchivedPrivateThreads(Snowflake channel_id, sigc::slot<void(DiscordError, const ArchivedThreadsResponseData &)> callback); + void GetArchivedPublicThreads(Snowflake channel_id, const sigc::slot<void(DiscordError, const ArchivedThreadsResponseData &)> &callback); + void GetArchivedPrivateThreads(Snowflake channel_id, const sigc::slot<void(DiscordError, const ArchivedThreadsResponseData &)> &callback); std::vector<Snowflake> GetChildChannelIDs(Snowflake parent_id) const; // get ids of given list of members for who we do not have the member data @@ -104,7 +102,7 @@ public: Permission ComputeOverwrites(Permission base, Snowflake member_id, Snowflake channel_id) const; bool CanManageMember(Snowflake guild_id, Snowflake actor, Snowflake target) const; // kick, ban, edit nickname (cant think of a better name) - void ChatMessageCallback(std::string nonce, const http::response_type &response); + void ChatMessageCallback(const std::string &nonce, const http::response_type &response); void SendChatMessage(const std::string &content, Snowflake channel); void SendChatMessage(const std::string &content, Snowflake channel, Snowflake referenced_message); @@ -112,53 +110,47 @@ public: void EditMessage(Snowflake channel_id, Snowflake id, std::string content); void SendLazyLoad(Snowflake id); void SendThreadLazyLoad(Snowflake id); - void JoinGuild(std::string code); + void JoinGuild(const std::string &code); void LeaveGuild(Snowflake id); void KickUser(Snowflake user_id, Snowflake guild_id); void BanUser(Snowflake user_id, Snowflake guild_id); // todo: reason, delete messages void UpdateStatus(PresenceStatus status, bool is_afk); void UpdateStatus(PresenceStatus status, bool is_afk, const ActivityData &obj); - void CreateDM(Snowflake user_id); - void CreateDM(Snowflake user_id, sigc::slot<void(DiscordError code, Snowflake channel_id)> callback); + void CreateDM(Snowflake user_id, const sigc::slot<void(DiscordError code, Snowflake channel_id)> &callback); void CloseDM(Snowflake channel_id); std::optional<Snowflake> FindDM(Snowflake user_id); // wont find group dms void AddReaction(Snowflake id, Glib::ustring param); void RemoveReaction(Snowflake id, Glib::ustring param); - void SetGuildName(Snowflake id, const Glib::ustring &name); - void SetGuildName(Snowflake id, const Glib::ustring &name, sigc::slot<void(DiscordError code)> callback); - void SetGuildIcon(Snowflake id, const std::string &data); - void SetGuildIcon(Snowflake id, const std::string &data, sigc::slot<void(DiscordError code)> callback); - void UnbanUser(Snowflake guild_id, Snowflake user_id); - void UnbanUser(Snowflake guild_id, Snowflake user_id, sigc::slot<void(DiscordError code)> callback); - void DeleteInvite(const std::string &code); - void DeleteInvite(const std::string &code, sigc::slot<void(DiscordError code)> callback); + void SetGuildName(Snowflake id, const Glib::ustring &name, const sigc::slot<void(DiscordError code)> &callback); + void SetGuildIcon(Snowflake id, const std::string &data, const sigc::slot<void(DiscordError code)> &callback); + void UnbanUser(Snowflake guild_id, Snowflake user_id, const sigc::slot<void(DiscordError code)> &callback); + void DeleteInvite(const std::string &code, const sigc::slot<void(DiscordError code)> &callback); void AddGroupDMRecipient(Snowflake channel_id, Snowflake user_id); void RemoveGroupDMRecipient(Snowflake channel_id, Snowflake user_id); - void ModifyRolePermissions(Snowflake guild_id, Snowflake role_id, Permission permissions, sigc::slot<void(DiscordError code)> callback); - void ModifyRoleName(Snowflake guild_id, Snowflake role_id, const Glib::ustring &name, sigc::slot<void(DiscordError code)> callback); - void ModifyRoleColor(Snowflake guild_id, Snowflake role_id, uint32_t color, sigc::slot<void(DiscordError code)> callback); - void ModifyRoleColor(Snowflake guild_id, Snowflake role_id, Gdk::RGBA color, sigc::slot<void(DiscordError code)> callback); - void ModifyRolePosition(Snowflake guild_id, Snowflake role_id, int position, sigc::slot<void(DiscordError code)> callback); - void ModifyEmojiName(Snowflake guild_id, Snowflake emoji_id, const Glib::ustring &name, sigc::slot<void(DiscordError code)> callback); - void DeleteEmoji(Snowflake guild_id, Snowflake emoji_id, sigc::slot<void(DiscordError code)> callback); - std::optional<GuildApplicationData> GetGuildApplication(Snowflake guild_id) const; - void RemoveRelationship(Snowflake id, sigc::slot<void(DiscordError code)> callback); - void SendFriendRequest(const Glib::ustring &username, int discriminator, sigc::slot<void(DiscordError code)> callback); - void PutRelationship(Snowflake id, sigc::slot<void(DiscordError code)> callback); // send fr by id, accept incoming - void Pin(Snowflake channel_id, Snowflake message_id, sigc::slot<void(DiscordError code)> callback); - void Unpin(Snowflake channel_id, Snowflake message_id, sigc::slot<void(DiscordError code)> callback); - void LeaveThread(Snowflake channel_id, const std::string &location, sigc::slot<void(DiscordError code)> callback); - void ArchiveThread(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback); - void UnArchiveThread(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback); - void MarkChannelAsRead(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback); - void MarkGuildAsRead(Snowflake guild_id, sigc::slot<void(DiscordError code)> callback); - void MuteChannel(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback); - void UnmuteChannel(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback); - void MarkAllAsRead(sigc::slot<void(DiscordError code)> callback); - void MuteGuild(Snowflake id, sigc::slot<void(DiscordError code)> callback); - void UnmuteGuild(Snowflake id, sigc::slot<void(DiscordError code)> callback); - void MuteThread(Snowflake id, sigc::slot<void(DiscordError code)> callback); - void UnmuteThread(Snowflake id, sigc::slot<void(DiscordError code)> callback); + void ModifyRolePermissions(Snowflake guild_id, Snowflake role_id, Permission permissions, const sigc::slot<void(DiscordError code)> &callback); + void ModifyRoleName(Snowflake guild_id, Snowflake role_id, const Glib::ustring &name, const sigc::slot<void(DiscordError code)> &callback); + void ModifyRoleColor(Snowflake guild_id, Snowflake role_id, uint32_t color, const sigc::slot<void(DiscordError code)> &callback); + void ModifyRoleColor(Snowflake guild_id, Snowflake role_id, const Gdk::RGBA &color, const sigc::slot<void(DiscordError code)> &callback); + void ModifyRolePosition(Snowflake guild_id, Snowflake role_id, int position, const sigc::slot<void(DiscordError code)> &callback); + void ModifyEmojiName(Snowflake guild_id, Snowflake emoji_id, const Glib::ustring &name, const sigc::slot<void(DiscordError code)> &callback); + void DeleteEmoji(Snowflake guild_id, Snowflake emoji_id, const sigc::slot<void(DiscordError code)> &callback); + void RemoveRelationship(Snowflake id, const sigc::slot<void(DiscordError code)> &callback); + void SendFriendRequest(const Glib::ustring &username, int discriminator, const sigc::slot<void(DiscordError code)> &callback); + void PutRelationship(Snowflake id, const sigc::slot<void(DiscordError code)> &callback); // send fr by id, accept incoming + void Pin(Snowflake channel_id, Snowflake message_id, const sigc::slot<void(DiscordError code)> &callback); + void Unpin(Snowflake channel_id, Snowflake message_id, const sigc::slot<void(DiscordError code)> &callback); + void LeaveThread(Snowflake channel_id, const std::string &location, const sigc::slot<void(DiscordError code)> &callback); + void ArchiveThread(Snowflake channel_id, const sigc::slot<void(DiscordError code)> &callback); + void UnArchiveThread(Snowflake channel_id, const sigc::slot<void(DiscordError code)> &callback); + void MarkChannelAsRead(Snowflake channel_id, const sigc::slot<void(DiscordError code)> &callback); + void MarkGuildAsRead(Snowflake guild_id, const sigc::slot<void(DiscordError code)> &callback); + void MuteChannel(Snowflake channel_id, const sigc::slot<void(DiscordError code)> &callback); + void UnmuteChannel(Snowflake channel_id, const sigc::slot<void(DiscordError code)> &callback); + void MarkAllAsRead(const sigc::slot<void(DiscordError code)> &callback); + void MuteGuild(Snowflake id, const sigc::slot<void(DiscordError code)> &callback); + void UnmuteGuild(Snowflake id, const sigc::slot<void(DiscordError code)> &callback); + void MuteThread(Snowflake id, const sigc::slot<void(DiscordError code)> &callback); + void UnmuteThread(Snowflake id, const sigc::slot<void(DiscordError code)> &callback); bool CanModifyRole(Snowflake guild_id, Snowflake role_id) const; bool CanModifyRole(Snowflake guild_id, Snowflake role_id, Snowflake user_id) const; @@ -177,7 +169,7 @@ public: // real client doesn't seem to use the single role endpoints so neither do we template<typename Iter> - auto SetMemberRoles(Snowflake guild_id, Snowflake user_id, Iter begin, Iter end, sigc::slot<void(DiscordError code)> callback) { + auto SetMemberRoles(Snowflake guild_id, Snowflake user_id, Iter begin, Iter end, const sigc::slot<void(DiscordError code)> &callback) { ModifyGuildMemberObject obj; obj.Roles = { begin, end }; m_http.MakePATCH("/guilds/" + std::to_string(guild_id) + "/members/" + std::to_string(user_id), nlohmann::json(obj).dump(), [this, callback](const http::response_type &response) { @@ -190,30 +182,29 @@ public: // FetchGuildBans fetches all bans+reasons via api, this func fetches stored bans (so usually just GUILD_BAN_ADD data) std::vector<BanData> GetBansInGuild(Snowflake guild_id); - void FetchGuildBan(Snowflake guild_id, Snowflake user_id, sigc::slot<void(BanData)> callback); - void FetchGuildBans(Snowflake guild_id, sigc::slot<void(std::vector<BanData>)> callback); + void FetchGuildBan(Snowflake guild_id, Snowflake user_id, const sigc::slot<void(BanData)> &callback); + void FetchGuildBans(Snowflake guild_id, const sigc::slot<void(std::vector<BanData>)> &callback); - void FetchInvite(std::string code, sigc::slot<void(std::optional<InviteData>)> callback); - void FetchGuildInvites(Snowflake guild_id, sigc::slot<void(std::vector<InviteData>)> callback); + void FetchInvite(const std::string &code, const sigc::slot<void(std::optional<InviteData>)> &callback); + void FetchGuildInvites(Snowflake guild_id, const sigc::slot<void(std::vector<InviteData>)> &callback); - void FetchAuditLog(Snowflake guild_id, sigc::slot<void(AuditLogData)> callback); + void FetchAuditLog(Snowflake guild_id, const sigc::slot<void(AuditLogData)> &callback); - void FetchGuildEmojis(Snowflake guild_id, sigc::slot<void(std::vector<EmojiData>)> callback); + void FetchGuildEmojis(Snowflake guild_id, const sigc::slot<void(std::vector<EmojiData>)> &callback); - void FetchUserProfile(Snowflake user_id, sigc::slot<void(UserProfileData)> callback); - void FetchUserNote(Snowflake user_id, sigc::slot<void(std::string note)> callback); - void SetUserNote(Snowflake user_id, std::string note); - void SetUserNote(Snowflake user_id, std::string note, sigc::slot<void(DiscordError code)> callback); - void FetchUserRelationships(Snowflake user_id, sigc::slot<void(std::vector<UserData>)> callback); + void FetchUserProfile(Snowflake user_id, const sigc::slot<void(UserProfileData)> &callback); + void FetchUserNote(Snowflake user_id, const sigc::slot<void(std::string note)> &callback); + void SetUserNote(Snowflake user_id, std::string note, const sigc::slot<void(DiscordError code)> &callback); + void FetchUserRelationships(Snowflake user_id, const sigc::slot<void(std::vector<UserData>)> &callback); - void FetchPinned(Snowflake id, sigc::slot<void(std::vector<Message>, DiscordError code)> callback); + void FetchPinned(Snowflake id, const 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(DiscordError code)> callback); + bool IsVerificationRequired(Snowflake guild_id) const; + void GetVerificationGateInfo(Snowflake guild_id, const sigc::slot<void(std::optional<VerificationGateInfoObject>)> &callback); + void AcceptVerificationGate(Snowflake guild_id, VerificationGateInfoObject info, const sigc::slot<void(DiscordError code)> &callback); - void UpdateToken(std::string token); - void SetUserAgent(std::string agent); + void UpdateToken(const std::string &token); + void SetUserAgent(const std::string &agent); bool IsChannelMuted(Snowflake id) const noexcept; bool IsGuildMuted(Snowflake id) const noexcept; @@ -233,8 +224,8 @@ private: std::vector<uint8_t> m_decompress_buf; z_stream m_zstream; - std::string GetAPIURL(); - std::string GetGatewayURL(); + static std::string GetAPIURL(); + static std::string GetGatewayURL(); static DiscordError GetCodeFromResponse(const http::response_type &response); @@ -296,16 +287,14 @@ private: void HandleSocketOpen(); void HandleSocketClose(uint16_t code); - bool CheckCode(const http::response_type &r); - bool CheckCode(const http::response_type &r, int expected); + static bool CheckCode(const http::response_type &r); + static bool CheckCode(const http::response_type &r, int expected); void StoreMessageData(Message &msg); void HandleReadyReadState(const ReadyEventData &data); void HandleReadyGuildSettings(const ReadyEventData &data); - void HandleUserGuildSettingsUpdateForDMs(const UserGuildSettingsUpdateData &data); - std::string m_token; void AddUserToGuild(Snowflake user_id, Snowflake guild_id); diff --git a/src/discord/emoji.cpp b/src/discord/emoji.cpp index 1a97eb8..a21b9bd 100644 --- a/src/discord/emoji.cpp +++ b/src/discord/emoji.cpp @@ -16,7 +16,7 @@ void to_json(nlohmann::json &j, const EmojiData &m) { j["id"] = m.ID; else j["id"] = nullptr; - if (m.Name != "") + if (!m.Name.empty()) j["name"] = m.Name; else j["name"] = nullptr; diff --git a/src/discord/guild.cpp b/src/discord/guild.cpp index 966bd44..3995293 100644 --- a/src/discord/guild.cpp +++ b/src/discord/guild.cpp @@ -77,7 +77,7 @@ void GuildData::update_from_json(const nlohmann::json &j) { JS_RD("owner_id", OwnerID); std::string tmp; JS_RD("permissions", tmp); - if (tmp != "") + if (!tmp.empty()) Permissions = std::stoull(tmp); JS_RD("region", VoiceRegion); JS_RD("afk_channel_id", AFKChannelID); @@ -128,66 +128,17 @@ bool GuildData::HasFeature(const std::string &search_feature) { } bool GuildData::HasIcon() const { - return Icon != ""; + return !Icon.empty(); } bool GuildData::HasAnimatedIcon() const { return HasIcon() && Icon[0] == 'a' && Icon[1] == '_'; } -std::string GuildData::GetIconURL(std::string ext, std::string size) const { +std::string GuildData::GetIconURL(const std::string &ext, const std::string &size) const { return "https://cdn.discordapp.com/icons/" + std::to_string(ID) + "/" + Icon + "." + ext + "?size=" + size; } -std::vector<Snowflake> GuildData::GetSortedChannels(Snowflake ignore) const { - std::vector<Snowflake> ret; - - const auto &discord = Abaddon::Get().GetDiscordClient(); - auto channels = discord.GetChannelsInGuild(ID); - - std::unordered_map<Snowflake, std::vector<ChannelData>> category_to_channels; - std::map<int, std::vector<ChannelData>> position_to_categories; - std::map<int, std::vector<ChannelData>> orphan_channels; - for (const auto &channel_id : channels) { - const auto data = discord.GetChannel(channel_id); - if (!data->ParentID.has_value() && (data->Type == ChannelType::GUILD_TEXT || data->Type == ChannelType::GUILD_NEWS)) - orphan_channels[*data->Position].push_back(*data); - else if (data->ParentID.has_value() && (data->Type == ChannelType::GUILD_TEXT || data->Type == ChannelType::GUILD_NEWS)) - category_to_channels[*data->ParentID].push_back(*data); - else if (data->Type == ChannelType::GUILD_CATEGORY) - position_to_categories[*data->Position].push_back(*data); - } - - for (auto &[pos, channels] : orphan_channels) { - std::sort(channels.begin(), channels.end(), [&](const ChannelData &a, const ChannelData &b) -> bool { - return a.ID < b.ID; - }); - for (const auto &chan : channels) - ret.push_back(chan.ID); - } - - for (auto &[pos, categories] : position_to_categories) { - std::sort(categories.begin(), categories.end(), [&](const ChannelData &a, const ChannelData &b) -> bool { - return a.ID < b.ID; - }); - for (const auto &category : categories) { - ret.push_back(category.ID); - if (ignore == category.ID) continue; // stupid hack to save me some time - auto it = category_to_channels.find(category.ID); - if (it == category_to_channels.end()) continue; - auto &channels = it->second; - std::sort(channels.begin(), channels.end(), [&](const ChannelData &a, const ChannelData &b) -> bool { - return a.Position < b.Position; - }); - for (auto &channel : channels) { - ret.push_back(channel.ID); - } - } - } - - return ret; -} - void from_json(const nlohmann::json &j, GuildApplicationData &m) { JS_D("user_id", m.UserID); JS_D("guild_id", m.GuildID); diff --git a/src/discord/guild.hpp b/src/discord/guild.hpp index 51b5a01..3370fa8 100644 --- a/src/discord/guild.hpp +++ b/src/discord/guild.hpp @@ -94,6 +94,5 @@ struct GuildData { bool HasFeature(const std::string &feature); bool HasIcon() const; bool HasAnimatedIcon() const; - std::string GetIconURL(std::string ext = "png", std::string size = "32") const; - std::vector<Snowflake> GetSortedChannels(Snowflake ignore = Snowflake::Invalid) const; + std::string GetIconURL(const std::string &ext = "png", const std::string &size = "32") const; }; diff --git a/src/discord/httpclient.cpp b/src/discord/httpclient.cpp index 05474df..f5b640c 100644 --- a/src/discord/httpclient.cpp +++ b/src/discord/httpclient.cpp @@ -1,5 +1,7 @@ #include "httpclient.hpp" +#include <utility> + //#define USE_LOCAL_PROXY HTTPClient::HTTPClient() { m_dispatcher.connect(sigc::mem_fun(*this, &HTTPClient::RunCallbacks)); @@ -10,19 +12,19 @@ void HTTPClient::SetBase(const std::string &url) { } void HTTPClient::SetUserAgent(std::string agent) { - m_agent = agent; + m_agent = std::move(agent); } void HTTPClient::SetAuth(std::string auth) { - m_authorization = auth; + m_authorization = std::move(auth); } -void HTTPClient::MakeDELETE(const std::string &path, std::function<void(http::response_type r)> cb) { +void HTTPClient::MakeDELETE(const std::string &path, const std::function<void(http::response_type r)> &cb) { printf("DELETE %s\n", path.c_str()); m_futures.push_back(std::async(std::launch::async, [this, path, cb] { http::request req(http::REQUEST_DELETE, m_api_base + path); req.set_header("Authorization", m_authorization); - req.set_user_agent(m_agent != "" ? m_agent : "Abaddon"); + req.set_user_agent(!m_agent.empty() ? m_agent : "Abaddon"); #ifdef USE_LOCAL_PROXY req.set_proxy("http://127.0.0.1:8888"); req.set_verify_ssl(false); @@ -34,13 +36,13 @@ void HTTPClient::MakeDELETE(const std::string &path, std::function<void(http::re })); } -void HTTPClient::MakePATCH(const std::string &path, const std::string &payload, std::function<void(http::response_type r)> cb) { +void HTTPClient::MakePATCH(const std::string &path, const std::string &payload, const std::function<void(http::response_type r)> &cb) { printf("PATCH %s\n", path.c_str()); m_futures.push_back(std::async(std::launch::async, [this, path, cb, payload] { http::request req(http::REQUEST_PATCH, m_api_base + path); req.set_header("Authorization", m_authorization); req.set_header("Content-Type", "application/json"); - req.set_user_agent(m_agent != "" ? m_agent : "Abaddon"); + req.set_user_agent(!m_agent.empty() ? m_agent : "Abaddon"); req.set_body(payload); #ifdef USE_LOCAL_PROXY req.set_proxy("http://127.0.0.1:8888"); @@ -53,13 +55,13 @@ void HTTPClient::MakePATCH(const std::string &path, const std::string &payload, })); } -void HTTPClient::MakePOST(const std::string &path, const std::string &payload, std::function<void(http::response_type r)> cb) { +void HTTPClient::MakePOST(const std::string &path, const std::string &payload, const std::function<void(http::response_type r)> &cb) { printf("POST %s\n", path.c_str()); m_futures.push_back(std::async(std::launch::async, [this, path, cb, payload] { http::request req(http::REQUEST_POST, m_api_base + path); req.set_header("Authorization", m_authorization); req.set_header("Content-Type", "application/json"); - req.set_user_agent(m_agent != "" ? m_agent : "Abaddon"); + req.set_user_agent(!m_agent.empty() ? m_agent : "Abaddon"); req.set_body(payload); #ifdef USE_LOCAL_PROXY req.set_proxy("http://127.0.0.1:8888"); @@ -72,14 +74,14 @@ void HTTPClient::MakePOST(const std::string &path, const std::string &payload, s })); } -void HTTPClient::MakePUT(const std::string &path, const std::string &payload, std::function<void(http::response_type r)> cb) { +void HTTPClient::MakePUT(const std::string &path, const std::string &payload, const std::function<void(http::response_type r)> &cb) { printf("PUT %s\n", path.c_str()); m_futures.push_back(std::async(std::launch::async, [this, path, cb, payload] { http::request req(http::REQUEST_PUT, m_api_base + path); req.set_header("Authorization", m_authorization); - if (payload != "") + if (!payload.empty()) req.set_header("Content-Type", "application/json"); - req.set_user_agent(m_agent != "" ? m_agent : "Abaddon"); + req.set_user_agent(!m_agent.empty() ? m_agent : "Abaddon"); req.set_body(payload); #ifdef USE_LOCAL_PROXY req.set_proxy("http://127.0.0.1:8888"); @@ -92,13 +94,13 @@ void HTTPClient::MakePUT(const std::string &path, const std::string &payload, st })); } -void HTTPClient::MakeGET(const std::string &path, std::function<void(http::response_type r)> cb) { +void HTTPClient::MakeGET(const std::string &path, const std::function<void(http::response_type r)> &cb) { printf("GET %s\n", path.c_str()); m_futures.push_back(std::async(std::launch::async, [this, path, cb] { http::request req(http::REQUEST_GET, m_api_base + path); req.set_header("Authorization", m_authorization); req.set_header("Content-Type", "application/json"); - req.set_user_agent(m_agent != "" ? m_agent : "Abaddon"); + req.set_user_agent(!m_agent.empty() ? m_agent : "Abaddon"); #ifdef USE_LOCAL_PROXY req.set_proxy("http://127.0.0.1:8888"); req.set_verify_ssl(false); @@ -126,11 +128,11 @@ void HTTPClient::RunCallbacks() { m_mutex.unlock(); } -void HTTPClient::OnResponse(const http::response_type &r, std::function<void(http::response_type r)> cb) { +void HTTPClient::OnResponse(const http::response_type &r, const std::function<void(http::response_type r)> &cb) { CleanupFutures(); try { m_mutex.lock(); - m_queue.push([this, r, cb] { cb(r); }); + m_queue.push([r, cb] { cb(r); }); m_dispatcher.emit(); m_mutex.unlock(); } catch (const std::exception &e) { diff --git a/src/discord/httpclient.hpp b/src/discord/httpclient.hpp index da8be37..47b8a4d 100644 --- a/src/discord/httpclient.hpp +++ b/src/discord/httpclient.hpp @@ -17,14 +17,14 @@ public: void SetUserAgent(std::string agent); void SetAuth(std::string auth); - void MakeDELETE(const std::string &path, std::function<void(http::response_type r)> cb); - void MakeGET(const std::string &path, std::function<void(http::response_type r)> cb); - void MakePATCH(const std::string &path, const std::string &payload, std::function<void(http::response_type r)> cb); - void MakePOST(const std::string &path, const std::string &payload, std::function<void(http::response_type r)> cb); - void MakePUT(const std::string &path, const std::string &payload, std::function<void(http::response_type r)> cb); + void MakeDELETE(const std::string &path, const std::function<void(http::response_type r)> &cb); + void MakeGET(const std::string &path, const std::function<void(http::response_type r)> &cb); + void MakePATCH(const std::string &path, const std::string &payload, const std::function<void(http::response_type r)> &cb); + void MakePOST(const std::string &path, const std::string &payload, const std::function<void(http::response_type r)> &cb); + void MakePUT(const std::string &path, const std::string &payload, const std::function<void(http::response_type r)> &cb); private: - void OnResponse(const http::response_type &r, std::function<void(http::response_type r)> cb); + void OnResponse(const http::response_type &r, const std::function<void(http::response_type r)> &cb); void CleanupFutures(); mutable std::mutex m_mutex; diff --git a/src/discord/json.hpp b/src/discord/json.hpp index 837080b..3c6968d 100644 --- a/src/discord/json.hpp +++ b/src/discord/json.hpp @@ -141,8 +141,8 @@ inline void json_update_optional_nullable_default(const ::nlohmann::json &j, con } while (0) // set a json value from a std::optional only if it has a value -#define JS_IF(k, v) \ - do { \ - if (v.has_value()) \ - j[k] = *v; \ +#define JS_IF(k, v) \ + do { \ + if ((v).has_value()) \ + j[k] = *(v); \ } while (0) diff --git a/src/discord/member.cpp b/src/discord/member.cpp index 29c4fae..e424491 100644 --- a/src/discord/member.cpp +++ b/src/discord/member.cpp @@ -19,7 +19,7 @@ std::vector<RoleData> GuildMember::GetSortedRoles() const { for (const auto role_id : Roles) { const auto role = Abaddon::Get().GetDiscordClient().GetRole(role_id); if (!role.has_value()) continue; - roles.push_back(std::move(*role)); + roles.push_back(*role); } std::sort(roles.begin(), roles.end(), [](const RoleData &a, const RoleData &b) { diff --git a/src/discord/member.hpp b/src/discord/member.hpp index e17da05..e5d49f4 100644 --- a/src/discord/member.hpp +++ b/src/discord/member.hpp @@ -20,7 +20,7 @@ struct GuildMember { // undocuemtned moment !!!1 std::optional<std::string> Avatar; - std::vector<RoleData> GetSortedRoles() const; + [[nodiscard]] std::vector<RoleData> GetSortedRoles() const; void update_from_json(const nlohmann::json &j); friend void from_json(const nlohmann::json &j, GuildMember &m); diff --git a/src/discord/message.cpp b/src/discord/message.cpp index 93d57c2..fb8a0ad 100644 --- a/src/discord/message.cpp +++ b/src/discord/message.cpp @@ -176,7 +176,7 @@ void to_json(nlohmann::json &j, const MessageApplicationData &m) { j["id"] = m.ID; JS_IF("cover_image", m.CoverImage); j["description"] = m.Description; - if (m.Icon == "") + if (m.Icon.empty()) j["icon"] = nullptr; else j["icon"] = m.Icon; @@ -230,7 +230,7 @@ void Message::from_json_edited(const nlohmann::json &j) { JS_O("content", Content); JS_O("timestamp", Timestamp); JS_ON("edited_timestamp", EditedTimestamp); - if (EditedTimestamp.size() > 0) + if (!EditedTimestamp.empty()) SetEdited(); JS_O("tts", IsTTS); JS_O("mention_everyone", DoesMentionEveryone); diff --git a/src/discord/message.hpp b/src/discord/message.hpp index 244b572..4e332b6 100644 --- a/src/discord/message.hpp +++ b/src/discord/message.hpp @@ -209,10 +209,10 @@ struct Message { void SetDeleted(); void SetEdited(); - bool IsDeleted() const; - bool IsEdited() const; + [[nodiscard]] bool IsDeleted() const; + [[nodiscard]] bool IsEdited() const; - bool DoesMention(Snowflake id) const noexcept; + [[nodiscard]] bool DoesMention(Snowflake id) const noexcept; private: bool m_deleted = false; diff --git a/src/discord/objects.cpp b/src/discord/objects.cpp index 3c9f770..6deaca0 100644 --- a/src/discord/objects.cpp +++ b/src/discord/objects.cpp @@ -251,7 +251,7 @@ void to_json(nlohmann::json &j, const IdentifyProperties &m) { j["referring_domain_current"] = m.ReferringDomainCurrent; j["release_channel"] = m.ReleaseChannel; j["client_build_number"] = m.ClientBuildNumber; - if (m.ClientEventSource == "") + if (m.ClientEventSource.empty()) j["client_event_source"] = nullptr; else j["client_event_source"] = m.ClientEventSource; @@ -290,7 +290,7 @@ void to_json(nlohmann::json &j, const CreateMessageObject &m) { } void to_json(nlohmann::json &j, const MessageEditObject &m) { - if (m.Content.size() > 0) + if (!m.Content.empty()) j["content"] = m.Content; // todo EmbedData to_json diff --git a/src/discord/objects.hpp b/src/discord/objects.hpp index 27542cc..db5fd76 100644 --- a/src/discord/objects.hpp +++ b/src/discord/objects.hpp @@ -197,7 +197,7 @@ struct GuildMemberListUpdateMessage { std::string HoistedRole; // null bool IsDefeaned; - GuildMember GetAsMemberData() const; + [[nodiscard]] GuildMember GetAsMemberData() const; friend void from_json(const nlohmann::json &j, MemberItem &m); diff --git a/src/discord/role.hpp b/src/discord/role.hpp index a526f4e..8df3a04 100644 --- a/src/discord/role.hpp +++ b/src/discord/role.hpp @@ -16,8 +16,8 @@ struct RoleData { bool IsManaged; bool IsMentionable; - bool HasColor() const noexcept; - Glib::ustring GetEscapedName() const; + [[nodiscard]] bool HasColor() const noexcept; + [[nodiscard]] Glib::ustring GetEscapedName() const; friend void from_json(const nlohmann::json &j, RoleData &m); }; diff --git a/src/discord/snowflake.cpp b/src/discord/snowflake.cpp index 3624c01..856e2f7 100644 --- a/src/discord/snowflake.cpp +++ b/src/discord/snowflake.cpp @@ -2,7 +2,6 @@ #include "util.hpp" #include <chrono> #include <ctime> -#include <glibmm.h> #include <iomanip> constexpr static uint64_t DiscordEpochSeconds = 1420070400; @@ -26,7 +25,7 @@ Snowflake::Snowflake(const Glib::ustring &str) { m_num = std::strtoull(str.c_str(), nullptr, 10); else m_num = Invalid; -}; +} Snowflake Snowflake::FromNow() { using namespace std::chrono; @@ -57,7 +56,7 @@ bool Snowflake::IsValid() const { Glib::ustring Snowflake::GetLocalTimestamp() const { const time_t secs_since_epoch = (m_num / SecondsInterval) + DiscordEpochSeconds; const std::tm tm = *localtime(&secs_since_epoch); - std::array<char, 256> tmp; + std::array<char, 256> tmp {}; std::strftime(tmp.data(), sizeof(tmp), "%X %x", &tm); return tmp.data(); } diff --git a/src/discord/snowflake.hpp b/src/discord/snowflake.hpp index e83317a..a5c0e6c 100644 --- a/src/discord/snowflake.hpp +++ b/src/discord/snowflake.hpp @@ -12,8 +12,8 @@ struct Snowflake { static Snowflake FromNow(); // not thread safe static Snowflake FromISO8601(std::string_view ts); - bool IsValid() const; - Glib::ustring GetLocalTimestamp() const; + [[nodiscard]] bool IsValid() const; + [[nodiscard]] Glib::ustring GetLocalTimestamp() const; bool operator==(const Snowflake &s) const noexcept { return m_num == s.m_num; diff --git a/src/discord/sticker.cpp b/src/discord/sticker.cpp index b92d031..0b163fc 100644 --- a/src/discord/sticker.cpp +++ b/src/discord/sticker.cpp @@ -22,15 +22,6 @@ void from_json(const nlohmann::json &j, StickerData &m) { JS_D("format_type", m.FormatType); } -std::string StickerData::GetURL() const { - if (!AssetHash.has_value()) return ""; - if (FormatType == StickerFormatType::PNG || FormatType == StickerFormatType::APNG) - return "https://media.discordapp.net/stickers/" + std::to_string(ID) + "/" + *AssetHash + ".png?size=256"; - else if (FormatType == StickerFormatType::LOTTIE) - return "https://media.discordapp.net/stickers/" + std::to_string(ID) + "/" + *AssetHash + ".json"; - return ""; -} - void to_json(nlohmann::json &j, const StickerItem &m) { j["id"] = m.ID; j["name"] = m.Name; diff --git a/src/discord/sticker.hpp b/src/discord/sticker.hpp index d23fe7b..77d4d83 100644 --- a/src/discord/sticker.hpp +++ b/src/discord/sticker.hpp @@ -24,8 +24,6 @@ struct StickerData { friend void to_json(nlohmann::json &j, const StickerData &m); friend void from_json(const nlohmann::json &j, StickerData &m); - - std::string GetURL() const; }; struct StickerItem { @@ -36,5 +34,5 @@ struct StickerItem { friend void to_json(nlohmann::json &j, const StickerItem &m); friend void from_json(const nlohmann::json &j, StickerItem &m); - std::string GetURL() const; + [[nodiscard]] std::string GetURL() const; }; diff --git a/src/discord/store.cpp b/src/discord/store.cpp index ede6364..71fdfcc 100644 --- a/src/discord/store.cpp +++ b/src/discord/store.cpp @@ -1001,7 +1001,7 @@ std::optional<RoleData> Store::GetRole(Snowflake id) const { return role; } -RoleData Store::GetRoleBound(std::unique_ptr<Statement> &s) const { +RoleData Store::GetRoleBound(std::unique_ptr<Statement> &s) { RoleData r; s->Get(0, r.ID); @@ -2249,11 +2249,11 @@ int Store::Statement::Bind(int index, Snowflake id) { int Store::Statement::Bind(int index, const char *str, size_t len) { if (len == -1) len = strlen(str); - return m_db->SetError(sqlite3_bind_blob(m_stmt, index, str, len, SQLITE_TRANSIENT)); + return m_db->SetError(sqlite3_bind_blob(m_stmt, index, str, static_cast<int>(len), SQLITE_TRANSIENT)); } int Store::Statement::Bind(int index, const std::string &str) { - return m_db->SetError(sqlite3_bind_blob(m_stmt, index, str.c_str(), str.size(), SQLITE_TRANSIENT)); + return m_db->SetError(sqlite3_bind_blob(m_stmt, index, str.c_str(), static_cast<int>(str.size()), SQLITE_TRANSIENT)); } int Store::Statement::Bind(int index) { diff --git a/src/discord/store.hpp b/src/discord/store.hpp index a1e5f81..4cf5e14 100644 --- a/src/discord/store.hpp +++ b/src/discord/store.hpp @@ -101,7 +101,7 @@ private: ~Statement(); Statement &operator=(Statement &other) = delete; - bool OK() const; + [[nodiscard]] bool OK() const; int Bind(int index, Snowflake id); int Bind(int index, const char *str, size_t len = -1); @@ -224,7 +224,7 @@ private: *first++ = id.get<T>(); } - bool IsNull(int index) const; + [[nodiscard]] bool IsNull(int index) const; int Step(); bool Insert(); bool FetchOne(); @@ -238,7 +238,7 @@ private: }; Message GetMessageBound(std::unique_ptr<Statement> &stmt) const; - RoleData GetRoleBound(std::unique_ptr<Statement> &stmt) const; + static RoleData GetRoleBound(std::unique_ptr<Statement> &stmt); void SetMessageInteractionPair(Snowflake message_id, const MessageInteractionData &interaction); diff --git a/src/discord/user.cpp b/src/discord/user.cpp index c2e6069..4393992 100644 --- a/src/discord/user.cpp +++ b/src/discord/user.cpp @@ -29,7 +29,7 @@ bool UserData::HasAnimatedAvatar(const std::optional<Snowflake> &guild_id) const return HasAnimatedAvatar(); } -std::string UserData::GetAvatarURL(Snowflake guild_id, std::string ext, std::string size) const { +std::string UserData::GetAvatarURL(Snowflake guild_id, const std::string &ext, std::string size) const { const auto member = Abaddon::Get().GetDiscordClient().GetMember(ID, guild_id); if (member.has_value() && member->Avatar.has_value()) { if (ext == "gif" && !(member->Avatar.value()[0] == 'a' && member->Avatar.value()[1] == '_')) @@ -43,14 +43,14 @@ std::string UserData::GetAvatarURL(Snowflake guild_id, std::string ext, std::str } } -std::string UserData::GetAvatarURL(const std::optional<Snowflake> &guild_id, std::string ext, std::string size) const { +std::string UserData::GetAvatarURL(const std::optional<Snowflake> &guild_id, const std::string &ext, std::string size) const { if (guild_id.has_value()) return GetAvatarURL(*guild_id, ext, size); else return GetAvatarURL(ext, size); } -std::string UserData::GetAvatarURL(std::string ext, std::string size) const { +std::string UserData::GetAvatarURL(const std::string &ext, std::string size) const { if (HasAvatar()) return "https://cdn.discordapp.com/avatars/" + std::to_string(ID) + "/" + Avatar + "." + ext + "?size=" + size; else @@ -107,7 +107,7 @@ void to_json(nlohmann::json &j, const UserData &m) { j["id"] = m.ID; j["username"] = m.Username; j["discriminator"] = m.Discriminator; - if (m.Avatar == "") + if (m.Avatar.empty()) j["avatar"] = nullptr; else j["avatar"] = m.Avatar; diff --git a/src/discord/user.hpp b/src/discord/user.hpp index c058ea1..083f5c4 100644 --- a/src/discord/user.hpp +++ b/src/discord/user.hpp @@ -60,22 +60,22 @@ struct UserData { friend void to_json(nlohmann::json &j, const UserData &m); void update_from_json(const nlohmann::json &j); - bool IsDeleted() const; - bool HasAvatar() const; - bool HasAnimatedAvatar() const noexcept; - bool HasAnimatedAvatar(Snowflake guild_id) const; - bool HasAnimatedAvatar(const std::optional<Snowflake> &guild_id) const; - std::string GetAvatarURL(Snowflake guild_id, std::string ext = "png", std::string size = "32") const; - std::string GetAvatarURL(const std::optional<Snowflake> &guild_id, std::string ext = "png", std::string size = "32") const; - std::string GetAvatarURL(std::string ext = "png", std::string size = "32") const; - std::string GetDefaultAvatarURL() const; - Snowflake GetHoistedRole(Snowflake guild_id, bool with_color = false) const; - std::string GetMention() const; - std::string GetEscapedName() const; - std::string GetEscapedBoldName() const; - std::string GetEscapedString() const; + [[nodiscard]] bool IsDeleted() const; + [[nodiscard]] bool HasAvatar() const; + [[nodiscard]] bool HasAnimatedAvatar() const noexcept; + [[nodiscard]] bool HasAnimatedAvatar(Snowflake guild_id) const; + [[nodiscard]] bool HasAnimatedAvatar(const std::optional<Snowflake> &guild_id) const; + [[nodiscard]] std::string GetAvatarURL(Snowflake guild_id, const std::string &ext = "png", std::string size = "32") const; + [[nodiscard]] std::string GetAvatarURL(const std::optional<Snowflake> &guild_id, const std::string &ext = "png", std::string size = "32") const; + [[nodiscard]] std::string GetAvatarURL(const std::string &ext = "png", std::string size = "32") const; + [[nodiscard]] std::string GetDefaultAvatarURL() const; + [[nodiscard]] Snowflake GetHoistedRole(Snowflake guild_id, bool with_color = false) const; + [[nodiscard]] std::string GetMention() const; + [[nodiscard]] std::string GetEscapedName() const; + [[nodiscard]] std::string GetEscapedBoldName() const; + [[nodiscard]] std::string GetEscapedString() const; template<bool with_at> - inline std::string GetEscapedBoldString() const { + [[nodiscard]] inline std::string GetEscapedBoldString() const { if constexpr (with_at) return "<b>@" + Glib::Markup::escape_text(Username) + "</b>#" + Discriminator; else diff --git a/src/discord/websocket.cpp b/src/discord/websocket.cpp index c7e43e9..46a4b90 100644 --- a/src/discord/websocket.cpp +++ b/src/discord/websocket.cpp @@ -1,18 +1,18 @@ #include "websocket.hpp" -#include <functional> +#include <utility> -Websocket::Websocket() {} +Websocket::Websocket() = default; -void Websocket::StartConnection(std::string url) { +void Websocket::StartConnection(const std::string &url) { m_websocket.disableAutomaticReconnection(); m_websocket.setUrl(url); - m_websocket.setOnMessageCallback(std::bind(&Websocket::OnMessage, this, std::placeholders::_1)); + m_websocket.setOnMessageCallback([this](auto &&msg) { OnMessage(std::forward<decltype(msg)>(msg)); }); m_websocket.setExtraHeaders(ix::WebSocketHttpHeaders { { "User-Agent", m_agent } }); // idk if this actually works m_websocket.start(); } void Websocket::SetUserAgent(std::string agent) { - m_agent = agent; + m_agent = std::move(agent); } bool Websocket::GetPrintMessages() const noexcept { @@ -31,11 +31,6 @@ void Websocket::Stop(uint16_t code) { m_websocket.stop(code); } -bool Websocket::IsOpen() const { - auto state = m_websocket.getReadyState(); - return state == ix::ReadyState::Open; -} - void Websocket::Send(const std::string &str) { if (m_print_messages) printf("sending %s\n", str.c_str()); diff --git a/src/discord/websocket.hpp b/src/discord/websocket.hpp index 26cd5d4..ca7dcc6 100644 --- a/src/discord/websocket.hpp +++ b/src/discord/websocket.hpp @@ -9,7 +9,7 @@ class Websocket { public: Websocket(); - void StartConnection(std::string url); + void StartConnection(const std::string &url); void SetUserAgent(std::string agent); @@ -20,7 +20,6 @@ public: void Send(const nlohmann::json &j); void Stop(); void Stop(uint16_t code); - bool IsOpen() const; private: void OnMessage(const ix::WebSocketMessagePtr &msg); |