From d36675cb32d722a4e3bfb6bfe1ef9cce23d2ba0d Mon Sep 17 00:00:00 2001 From: RogueException Date: Fri, 7 Oct 2016 22:25:12 -0300 Subject: [PATCH] Added RPC SpeakingStarted/Stopped events --- src/Discord.Net.Rpc/API/DiscordRpcApiClient.cs | 9 +++++++++ src/Discord.Net.Rpc/API/Rpc/SpeakingEvent.cs | 4 ++++ src/Discord.Net.Rpc/DiscordRpcClient.Events.cs | 14 ++++++++++---- src/Discord.Net.Rpc/DiscordRpcClient.cs | 11 +++++++---- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/Discord.Net.Rpc/API/DiscordRpcApiClient.cs b/src/Discord.Net.Rpc/API/DiscordRpcApiClient.cs index e8789976e..1d0fab516 100644 --- a/src/Discord.Net.Rpc/API/DiscordRpcApiClient.cs +++ b/src/Discord.Net.Rpc/API/DiscordRpcApiClient.cs @@ -335,6 +335,15 @@ namespace Discord.API return await SendRpcAsync("UNSUBSCRIBE", msg, evt: evt, options: options).ConfigureAwait(false); } + public async Task SendGlobalSubscribeAsync(string evt, RequestOptions options = null) + { + options = RequestOptions.CreateOrClone(options); + var msg = new ChannelSubscriptionParams + { + }; + return await SendRpcAsync("SUBSCRIBE", msg, evt: evt, options: options).ConfigureAwait(false); + } + public async Task SendGuildSubscribeAsync(string evt, ulong guildId, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); diff --git a/src/Discord.Net.Rpc/API/Rpc/SpeakingEvent.cs b/src/Discord.Net.Rpc/API/Rpc/SpeakingEvent.cs index 828556818..4d8804d2f 100644 --- a/src/Discord.Net.Rpc/API/Rpc/SpeakingEvent.cs +++ b/src/Discord.Net.Rpc/API/Rpc/SpeakingEvent.cs @@ -1,7 +1,11 @@ #pragma warning disable CS1591 +using Newtonsoft.Json; + namespace Discord.API.Rpc { public class SpeakingEvent { + [JsonProperty("user_id")] + public ulong UserId { get; set; } } } diff --git a/src/Discord.Net.Rpc/DiscordRpcClient.Events.cs b/src/Discord.Net.Rpc/DiscordRpcClient.Events.cs index a746c180c..3688bdbda 100644 --- a/src/Discord.Net.Rpc/DiscordRpcClient.Events.cs +++ b/src/Discord.Net.Rpc/DiscordRpcClient.Events.cs @@ -34,12 +34,18 @@ namespace Discord.Rpc private readonly AsyncEvent> _guildUpdatedEvent = new AsyncEvent>(); //Voice - public event Func VoiceStateUpdated + public event Func SpeakingStarted { - add { _voiceStateUpdatedEvent.Add(value); } - remove { _voiceStateUpdatedEvent.Remove(value); } + add { _speakingStarted.Add(value); } + remove { _speakingStarted.Remove(value); } } - private readonly AsyncEvent> _voiceStateUpdatedEvent = new AsyncEvent>(); + private readonly AsyncEvent> _speakingStarted = new AsyncEvent>(); + public event Func SpeakingStopped + { + add { _speakingStopped.Add(value); } + remove { _speakingStopped.Remove(value); } + } + private readonly AsyncEvent> _speakingStopped = new AsyncEvent>(); //Messages public event Func MessageReceived diff --git a/src/Discord.Net.Rpc/DiscordRpcClient.cs b/src/Discord.Net.Rpc/DiscordRpcClient.cs index efbfb7126..331b7e786 100644 --- a/src/Discord.Net.Rpc/DiscordRpcClient.cs +++ b/src/Discord.Net.Rpc/DiscordRpcClient.cs @@ -331,7 +331,7 @@ namespace Discord.Rpc break; //Voice - case "VOICE_STATE_CREATE": + /*case "VOICE_STATE_CREATE": { await _rpcLogger.DebugAsync("Received Dispatch (VOICE_STATE_CREATE)").ConfigureAwait(false); @@ -351,19 +351,22 @@ namespace Discord.Rpc await _voiceStateUpdatedEvent.InvokeAsync().ConfigureAwait(false); } - break; + break;*/ case "SPEAKING_START": { await _rpcLogger.DebugAsync("Received Dispatch (SPEAKING_START)").ConfigureAwait(false); - await _voiceStateUpdatedEvent.InvokeAsync().ConfigureAwait(false); + var data = (payload.Value as JToken).ToObject(_serializer); + + await _speakingStarted.InvokeAsync(data.UserId).ConfigureAwait(false); } break; case "SPEAKING_STOP": { await _rpcLogger.DebugAsync("Received Dispatch (SPEAKING_STOP)").ConfigureAwait(false); + var data = (payload.Value as JToken).ToObject(_serializer); - await _voiceStateUpdatedEvent.InvokeAsync().ConfigureAwait(false); + await _speakingStopped.InvokeAsync(data.UserId).ConfigureAwait(false); } break;