Browse Source

Expose VoiceServerUpdate events

pull/984/head
Devoxin 8 years ago
parent
commit
7cce63a0a3
3 changed files with 32 additions and 1 deletions
  1. +9
    -1
      src/Discord.Net.WebSocket/BaseSocketClient.Events.cs
  2. +4
    -0
      src/Discord.Net.WebSocket/DiscordSocketClient.cs
  3. +19
    -0
      src/Discord.Net.WebSocket/Entities/Guilds/SocketVoiceServer.cs

+ 9
- 1
src/Discord.Net.WebSocket/BaseSocketClient.Events.cs View File

@@ -1,4 +1,5 @@
using System;
using Discord.WebSocket.Entities.Guilds;
using System;
using System.Threading.Tasks; using System.Threading.Tasks;


namespace Discord.WebSocket namespace Discord.WebSocket
@@ -165,6 +166,13 @@ namespace Discord.WebSocket
remove { _userVoiceStateUpdatedEvent.Remove(value); } remove { _userVoiceStateUpdatedEvent.Remove(value); }
} }
internal readonly AsyncEvent<Func<SocketUser, SocketVoiceState, SocketVoiceState, Task>> _userVoiceStateUpdatedEvent = new AsyncEvent<Func<SocketUser, SocketVoiceState, SocketVoiceState, Task>>(); internal readonly AsyncEvent<Func<SocketUser, SocketVoiceState, SocketVoiceState, Task>> _userVoiceStateUpdatedEvent = new AsyncEvent<Func<SocketUser, SocketVoiceState, SocketVoiceState, Task>>();
/// <summary> Fired when the bot connects/disconnects to a Discord voice server. </summary>
public event Func<SocketVoiceServer, Task> VoiceServerUpdated
{
add { _voiceServerUpdatedEvent.Add(value); }
remove { _voiceServerUpdatedEvent.Remove(value); }
}
internal readonly AsyncEvent<Func<SocketVoiceServer, Task>> _voiceServerUpdatedEvent = new AsyncEvent<Func<SocketVoiceServer, Task>>();
/// <summary> Fired when the connected account is updated. </summary> /// <summary> Fired when the connected account is updated. </summary>
public event Func<SocketSelfUser, SocketSelfUser, Task> CurrentUserUpdated { public event Func<SocketSelfUser, SocketSelfUser, Task> CurrentUserUpdated {
add { _selfUpdatedEvent.Add(value); } add { _selfUpdatedEvent.Add(value); }


+ 4
- 0
src/Discord.Net.WebSocket/DiscordSocketClient.cs View File

@@ -5,6 +5,7 @@ using Discord.Net.Converters;
using Discord.Net.Udp; using Discord.Net.Udp;
using Discord.Net.WebSockets; using Discord.Net.WebSockets;
using Discord.Rest; using Discord.Rest;
using Discord.WebSocket.Entities.Guilds;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
@@ -1474,6 +1475,9 @@ namespace Discord.WebSocket
await UnknownGuildAsync(type, data.GuildId).ConfigureAwait(false); await UnknownGuildAsync(type, data.GuildId).ConfigureAwait(false);
return; return;
} }

SocketVoiceServer VoiceServer = new SocketVoiceServer(data.GuildId, data.Endpoint, data.Token);
await TimedInvokeAsync(_voiceServerUpdatedEvent, nameof(UserVoiceStateUpdated), VoiceServer).ConfigureAwait(false);
} }
break; break;




+ 19
- 0
src/Discord.Net.WebSocket/Entities/Guilds/SocketVoiceServer.cs View File

@@ -0,0 +1,19 @@
using System.Diagnostics;

namespace Discord.WebSocket.Entities.Guilds
{
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class SocketVoiceServer
{
public ulong GuildId { get; private set; }
public string Endpoint { get; private set; }
public string Token { get; private set; }

internal SocketVoiceServer(ulong GuildId, string Endpoint, string Token)
{
this.GuildId = GuildId;
this.Endpoint = Endpoint;
this.Token = Token;
}
}
}

Loading…
Cancel
Save