summaryrefslogtreecommitdiff
path: root/src/discord
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2024-06-26 04:26:32 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2024-06-26 04:26:32 -0400
commitaf9f9ad803fab8e293e7d783f6e84fae6c5f21cb (patch)
tree3e170ff7cbb565cffc431925a0fceb96f7ee69ae /src/discord
parent837e25a0cf28f3a132e6e675bb0e6d376f3d83f9 (diff)
downloadabaddon-portaudio-af9f9ad803fab8e293e7d783f6e84fae6c5f21cb.tar.gz
abaddon-portaudio-af9f9ad803fab8e293e7d783f6e84fae6c5f21cb.zip
request to speak button
Diffstat (limited to 'src/discord')
-rw-r--r--src/discord/discord.cpp26
-rw-r--r--src/discord/discord.hpp3
-rw-r--r--src/discord/objects.cpp12
-rw-r--r--src/discord/objects.hpp8
4 files changed, 49 insertions, 0 deletions
diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp
index 8f88a91..2ee8493 100644
--- a/src/discord/discord.cpp
+++ b/src/discord/discord.cpp
@@ -1301,6 +1301,32 @@ bool DiscordClient::IsUserSpeaker(Snowflake user_id) const {
return state.has_value() && state->second.IsSpeaker();
}
+bool DiscordClient::HasUserRequestedToSpeak(Snowflake user_id) const {
+ const auto state = GetVoiceState(user_id);
+ return state.has_value() && state->second.RequestToSpeakTimestamp.has_value() && util::FlagSet(state->second.Flags, VoiceStateFlags::Suppressed);
+}
+
+void DiscordClient::RequestToSpeak(Snowflake channel_id, bool want, const sigc::slot<void(DiscordError code)> &callback) {
+ if (want && !HasSelfChannelPermission(channel_id, Permission::REQUEST_TO_SPEAK)) return;
+ const auto channel = GetChannel(channel_id);
+ if (!channel.has_value() || !channel->GuildID.has_value()) return;
+
+ ModifyCurrentUserVoiceStateObject d;
+ d.ChannelID = channel_id;
+ if (want) {
+ d.RequestToSpeakTimestamp = Glib::DateTime::create_now_utc().format_iso8601();
+ } else {
+ d.RequestToSpeakTimestamp = "";
+ }
+ m_http.MakePATCH("/guilds/" + std::to_string(*channel->GuildID) + "/voice-states/@me", nlohmann::json(d).dump(), [callback](const http::response_type &response) {
+ if (CheckCode(response, 204)) {
+ callback(DiscordError::NONE);
+ } else {
+ callback(GetCodeFromResponse(response));
+ }
+ });
+}
+
DiscordVoiceClient &DiscordClient::GetVoiceClient() {
return m_voice;
}
diff --git a/src/discord/discord.hpp b/src/discord/discord.hpp
index ab051aa..55bd308 100644
--- a/src/discord/discord.hpp
+++ b/src/discord/discord.hpp
@@ -203,6 +203,9 @@ public:
[[nodiscard]] Snowflake GetVoiceChannelID() const noexcept;
[[nodiscard]] std::optional<uint32_t> GetSSRCOfUser(Snowflake id) const;
[[nodiscard]] bool IsUserSpeaker(Snowflake user_id) const;
+ [[nodiscard]] bool HasUserRequestedToSpeak(Snowflake user_id) const;
+
+ void RequestToSpeak(Snowflake channel_id, bool want, const sigc::slot<void(DiscordError code)> &callback);
DiscordVoiceClient &GetVoiceClient();
diff --git a/src/discord/objects.cpp b/src/discord/objects.cpp
index 1c5dd39..e6b7675 100644
--- a/src/discord/objects.cpp
+++ b/src/discord/objects.cpp
@@ -699,6 +699,18 @@ void from_json(const nlohmann::json &j, CallCreateData &m) {
JS_D("channel_id", m.ChannelID);
JS_ON("voice_states", m.VoiceStates);
}
+
+void to_json(nlohmann::json &j, const ModifyCurrentUserVoiceStateObject &m) {
+ JS_IF("channel_id", m.ChannelID);
+ JS_IF("suppress", m.Suppress);
+ if (m.RequestToSpeakTimestamp.has_value()) {
+ if (m.RequestToSpeakTimestamp->empty()) {
+ j["request_to_speak_timestamp"] = nullptr;
+ } else {
+ j["request_to_speak_timestamp"] = *m.RequestToSpeakTimestamp;
+ }
+ }
+}
#endif
void from_json(const nlohmann::json &j, VoiceState &m) {
diff --git a/src/discord/objects.hpp b/src/discord/objects.hpp
index e026311..44afe8d 100644
--- a/src/discord/objects.hpp
+++ b/src/discord/objects.hpp
@@ -957,4 +957,12 @@ struct CallCreateData {
friend void from_json(const nlohmann::json &j, CallCreateData &m);
};
+
+struct ModifyCurrentUserVoiceStateObject {
+ std::optional<Snowflake> ChannelID;
+ std::optional<bool> Suppress;
+ std::optional<std::string> RequestToSpeakTimestamp;
+
+ friend void to_json(nlohmann::json &j, const ModifyCurrentUserVoiceStateObject &m);
+};
#endif