diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-11-18 01:03:35 -0500 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-11-18 01:03:35 -0500 |
commit | 9c285a09e50ce9d4b786c9f28402e94a9f4fb418 (patch) | |
tree | 78701d71461b48e3f8083b45b1f420362950ef0a /discord | |
parent | 1f68da6b77c82f462472385a8e31a578c4c5caed (diff) | |
parent | 9d21df8e1bca9ccfa1bcfcde3bc8f35473866166 (diff) | |
download | abaddon-portaudio-9c285a09e50ce9d4b786c9f28402e94a9f4fb418.tar.gz abaddon-portaudio-9c285a09e50ce9d4b786c9f28402e94a9f4fb418.zip |
Merge branch 'master' of https://github.com/uowuo/abaddon into msys
Diffstat (limited to 'discord')
-rw-r--r-- | discord/discord.cpp | 23 | ||||
-rw-r--r-- | discord/guild.cpp | 3 |
2 files changed, 16 insertions, 10 deletions
diff --git a/discord/discord.cpp b/discord/discord.cpp index c494145..671c29d 100644 --- a/discord/discord.cpp +++ b/discord/discord.cpp @@ -1,5 +1,6 @@ #include "discord.hpp" #include <cassert> +#include <cinttypes> #include "../util.hpp" #include "../abaddon.hpp" @@ -707,19 +708,20 @@ void DiscordClient::ModifyRoleColor(Snowflake guild_id, Snowflake role_id, Gdk:: void DiscordClient::ModifyRolePosition(Snowflake guild_id, Snowflake role_id, int position, sigc::slot<void(DiscordError code)> callback) { const auto roles = GetGuild(guild_id)->FetchRoles(); - if (position > roles.size()) return; + if (static_cast<size_t>(position) > roles.size()) return; // gay and makes you send every role in between new and old position - size_t index_from = -1, index_to = -1; + constexpr auto IDX_MAX = ~size_t { 0 }; + size_t index_from = IDX_MAX, index_to = IDX_MAX; for (size_t i = 0; i < roles.size(); i++) { const auto &role = roles[i]; if (role.ID == role_id) index_from = i; else if (role.Position == position) index_to = i; - if (index_from != -1 && index_to != -1) break; + if (index_from != IDX_MAX && index_to != IDX_MAX) break; } - if (index_from == -1 || index_to == -1) return; + if (index_from == IDX_MAX || index_to == IDX_MAX) return; int dir; size_t range_from, range_to; @@ -1276,11 +1278,11 @@ void DiscordClient::HandleGatewayMessage(std::string str) { } } break; default: - printf("Unknown opcode %d\n", m.Opcode); + printf("Unknown opcode %d\n", static_cast<int>(m.Opcode)); break; } } catch (std::exception &e) { - fprintf(stderr, "error handling message (opcode %d): %s\n", m.Opcode, e.what()); + fprintf(stderr, "error handling message (opcode %d): %s\n", static_cast<int>(m.Opcode), e.what()); } } @@ -1320,7 +1322,7 @@ DiscordError DiscordClient::GetCodeFromResponse(const http::response_type &respo void DiscordClient::ProcessNewGuild(GuildData &guild) { if (guild.IsUnavailable) { - printf("guild (%lld) unavailable\n", static_cast<uint64_t>(guild.ID)); + printf("guild (%" PRIu64 ") unavailable\n", static_cast<uint64_t>(guild.ID)); return; } @@ -1375,7 +1377,7 @@ void DiscordClient::HandleGatewayReady(const GatewayMessage &msg) { m_store.SetUser(user.ID, user); if (data.MergedMembers.has_value()) { - for (int i = 0; i < data.MergedMembers->size(); i++) { + for (size_t i = 0; i < data.MergedMembers->size(); i++) { const auto guild_id = data.Guilds[i].ID; for (const auto &member : data.MergedMembers.value()[i]) { m_store.SetGuildMember(guild_id, *member.UserID, member); @@ -1762,6 +1764,9 @@ void DiscordClient::HandleGatewayThreadCreate(const GatewayMessage &msg) { ThreadCreateData data = msg.Data; m_store.SetChannel(data.Channel.ID, data.Channel); m_signal_thread_create.emit(data.Channel); + if (data.Channel.ThreadMember.has_value()) { + m_signal_added_to_thread.emit(data.Channel.ID); + } } void DiscordClient::HandleGatewayThreadDelete(const GatewayMessage &msg) { @@ -1975,7 +1980,7 @@ void DiscordClient::HandleGatewayGuildDelete(const GatewayMessage &msg) { bool unavailable = msg.Data.contains("unavilable") && msg.Data.at("unavailable").get<bool>(); if (unavailable) - printf("guild %llu became unavailable\n", static_cast<uint64_t>(id)); + printf("guild %" PRIu64 " became unavailable\n", static_cast<uint64_t>(id)); const auto guild = m_store.GetGuild(id); if (!guild.has_value()) { diff --git a/discord/guild.cpp b/discord/guild.cpp index 1c79a38..23a45ee 100644 --- a/discord/guild.cpp +++ b/discord/guild.cpp @@ -191,7 +191,8 @@ std::vector<Snowflake> GuildData::GetSortedChannels(Snowflake ignore) const { std::vector<RoleData> GuildData::FetchRoles() const { if (!Roles.has_value()) return {}; std::vector<RoleData> ret; - for (const auto thing : *Roles) + ret.reserve(Roles->size()); + for (const auto &thing : *Roles) ret.push_back(*Abaddon::Get().GetDiscordClient().GetRole(thing.ID)); std::sort(ret.begin(), ret.end(), [](const RoleData &a, const RoleData &b) -> bool { return a.Position > b.Position; |