Browse Source

Added RPC SpeakingStarted/Stopped events

tags/1.0-rc
RogueException 8 years ago
parent
commit
d36675cb32
4 changed files with 30 additions and 8 deletions
  1. +9
    -0
      src/Discord.Net.Rpc/API/DiscordRpcApiClient.cs
  2. +4
    -0
      src/Discord.Net.Rpc/API/Rpc/SpeakingEvent.cs
  3. +10
    -4
      src/Discord.Net.Rpc/DiscordRpcClient.Events.cs
  4. +7
    -4
      src/Discord.Net.Rpc/DiscordRpcClient.cs

+ 9
- 0
src/Discord.Net.Rpc/API/DiscordRpcApiClient.cs View File

@@ -335,6 +335,15 @@ namespace Discord.API
return await SendRpcAsync<SubscriptionResponse>("UNSUBSCRIBE", msg, evt: evt, options: options).ConfigureAwait(false); return await SendRpcAsync<SubscriptionResponse>("UNSUBSCRIBE", msg, evt: evt, options: options).ConfigureAwait(false);
} }


public async Task<SubscriptionResponse> SendGlobalSubscribeAsync(string evt, RequestOptions options = null)
{
options = RequestOptions.CreateOrClone(options);
var msg = new ChannelSubscriptionParams
{
};
return await SendRpcAsync<SubscriptionResponse>("SUBSCRIBE", msg, evt: evt, options: options).ConfigureAwait(false);
}

public async Task<SubscriptionResponse> SendGuildSubscribeAsync(string evt, ulong guildId, RequestOptions options = null) public async Task<SubscriptionResponse> SendGuildSubscribeAsync(string evt, ulong guildId, RequestOptions options = null)
{ {
options = RequestOptions.CreateOrClone(options); options = RequestOptions.CreateOrClone(options);


+ 4
- 0
src/Discord.Net.Rpc/API/Rpc/SpeakingEvent.cs View File

@@ -1,7 +1,11 @@
#pragma warning disable CS1591 #pragma warning disable CS1591
using Newtonsoft.Json;

namespace Discord.API.Rpc namespace Discord.API.Rpc
{ {
public class SpeakingEvent public class SpeakingEvent
{ {
[JsonProperty("user_id")]
public ulong UserId { get; set; }
} }
} }

+ 10
- 4
src/Discord.Net.Rpc/DiscordRpcClient.Events.cs View File

@@ -34,12 +34,18 @@ namespace Discord.Rpc
private readonly AsyncEvent<Func<Task>> _guildUpdatedEvent = new AsyncEvent<Func<Task>>(); private readonly AsyncEvent<Func<Task>> _guildUpdatedEvent = new AsyncEvent<Func<Task>>();


//Voice //Voice
public event Func<Task> VoiceStateUpdated
public event Func<ulong, Task> SpeakingStarted
{ {
add { _voiceStateUpdatedEvent.Add(value); }
remove { _voiceStateUpdatedEvent.Remove(value); }
add { _speakingStarted.Add(value); }
remove { _speakingStarted.Remove(value); }
} }
private readonly AsyncEvent<Func<Task>> _voiceStateUpdatedEvent = new AsyncEvent<Func<Task>>();
private readonly AsyncEvent<Func<ulong, Task>> _speakingStarted = new AsyncEvent<Func<ulong, Task>>();
public event Func<ulong, Task> SpeakingStopped
{
add { _speakingStopped.Add(value); }
remove { _speakingStopped.Remove(value); }
}
private readonly AsyncEvent<Func<ulong, Task>> _speakingStopped = new AsyncEvent<Func<ulong, Task>>();


//Messages //Messages
public event Func<RpcMessage, Task> MessageReceived public event Func<RpcMessage, Task> MessageReceived


+ 7
- 4
src/Discord.Net.Rpc/DiscordRpcClient.cs View File

@@ -331,7 +331,7 @@ namespace Discord.Rpc
break; break;


//Voice //Voice
case "VOICE_STATE_CREATE":
/*case "VOICE_STATE_CREATE":
{ {
await _rpcLogger.DebugAsync("Received Dispatch (VOICE_STATE_CREATE)").ConfigureAwait(false); await _rpcLogger.DebugAsync("Received Dispatch (VOICE_STATE_CREATE)").ConfigureAwait(false);


@@ -351,19 +351,22 @@ namespace Discord.Rpc


await _voiceStateUpdatedEvent.InvokeAsync().ConfigureAwait(false); await _voiceStateUpdatedEvent.InvokeAsync().ConfigureAwait(false);
} }
break;
break;*/


case "SPEAKING_START": case "SPEAKING_START":
{ {
await _rpcLogger.DebugAsync("Received Dispatch (SPEAKING_START)").ConfigureAwait(false); await _rpcLogger.DebugAsync("Received Dispatch (SPEAKING_START)").ConfigureAwait(false);
await _voiceStateUpdatedEvent.InvokeAsync().ConfigureAwait(false);
var data = (payload.Value as JToken).ToObject<SpeakingEvent>(_serializer);

await _speakingStarted.InvokeAsync(data.UserId).ConfigureAwait(false);
} }
break; break;
case "SPEAKING_STOP": case "SPEAKING_STOP":
{ {
await _rpcLogger.DebugAsync("Received Dispatch (SPEAKING_STOP)").ConfigureAwait(false); await _rpcLogger.DebugAsync("Received Dispatch (SPEAKING_STOP)").ConfigureAwait(false);
var data = (payload.Value as JToken).ToObject<SpeakingEvent>(_serializer);


await _voiceStateUpdatedEvent.InvokeAsync().ConfigureAwait(false);
await _speakingStopped.InvokeAsync(data.UserId).ConfigureAwait(false);
} }
break; break;




Loading…
Cancel
Save