Added RPC SpeakingStarted/Stopped events
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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); }
|
add { _speakingStarted.Add(value); }
|
||||||
remove { _voiceStateUpdatedEvent.Remove(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
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user