| @@ -3,7 +3,7 @@ using System.Diagnostics; | |||||
| namespace Discord | namespace Discord | ||||
| { | { | ||||
| /// <summary> | /// <summary> | ||||
| /// Represents a author field of an <see cref="Embed" />. | |||||
| /// A author field of an <see cref="Embed" />. | |||||
| /// </summary> | /// </summary> | ||||
| [DebuggerDisplay("{DebuggerDisplay,nq}")] | [DebuggerDisplay("{DebuggerDisplay,nq}")] | ||||
| public struct EmbedAuthor | public struct EmbedAuthor | ||||
| @@ -3,7 +3,7 @@ using System.Diagnostics; | |||||
| namespace Discord | namespace Discord | ||||
| { | { | ||||
| /// <summary> | /// <summary> | ||||
| /// Represents a field for an <see cref="Embed" />. | |||||
| /// A field for an <see cref="Embed" />. | |||||
| /// </summary> | /// </summary> | ||||
| [DebuggerDisplay("{DebuggerDisplay,nq}")] | [DebuggerDisplay("{DebuggerDisplay,nq}")] | ||||
| public struct EmbedField | public struct EmbedField | ||||
| @@ -165,6 +165,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 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); } | ||||
| @@ -134,7 +134,7 @@ namespace Discord.WebSocket | |||||
| private int GetShardIdFor(ulong guildId) | private int GetShardIdFor(ulong guildId) | ||||
| => (int)((guildId >> 22) % (uint)_totalShards); | => (int)((guildId >> 22) % (uint)_totalShards); | ||||
| public int GetShardIdFor(IGuild guild) | public int GetShardIdFor(IGuild guild) | ||||
| => GetShardIdFor(guild.Id); | |||||
| => GetShardIdFor(guild?.Id ?? 0); | |||||
| private DiscordSocketClient GetShardFor(ulong guildId) | private DiscordSocketClient GetShardFor(ulong guildId) | ||||
| => GetShard(GetShardIdFor(guildId)); | => GetShard(GetShardIdFor(guildId)); | ||||
| public DiscordSocketClient GetShardFor(IGuild guild) | public DiscordSocketClient GetShardFor(IGuild guild) | ||||
| @@ -1479,6 +1479,12 @@ namespace Discord.WebSocket | |||||
| var data = (payload as JToken).ToObject<VoiceServerUpdateEvent>(_serializer); | var data = (payload as JToken).ToObject<VoiceServerUpdateEvent>(_serializer); | ||||
| var guild = State.GetGuild(data.GuildId); | var guild = State.GetGuild(data.GuildId); | ||||
| var cacheable = new Cacheable<IGuild, ulong>(guild, data.GuildId, guild != null, | |||||
| async () => await ApiClient.GetGuildAsync(data.GuildId).ConfigureAwait(false) as IGuild); | |||||
| var voiceServer = new SocketVoiceServer(cacheable, data.GuildId, data.Endpoint, data.Token); | |||||
| await TimedInvokeAsync(_voiceServerUpdatedEvent, nameof(UserVoiceStateUpdated), voiceServer).ConfigureAwait(false); | |||||
| if (guild != null) | if (guild != null) | ||||
| { | { | ||||
| string endpoint = data.Endpoint.Substring(0, data.Endpoint.LastIndexOf(':')); | string endpoint = data.Endpoint.Substring(0, data.Endpoint.LastIndexOf(':')); | ||||
| @@ -1489,6 +1495,7 @@ namespace Discord.WebSocket | |||||
| await UnknownGuildAsync(type, data.GuildId).ConfigureAwait(false); | await UnknownGuildAsync(type, data.GuildId).ConfigureAwait(false); | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| break; | break; | ||||
| @@ -0,0 +1,21 @@ | |||||
| using System.Diagnostics; | |||||
| namespace Discord.WebSocket | |||||
| { | |||||
| [DebuggerDisplay(@"{DebuggerDisplay,nq}")] | |||||
| public class SocketVoiceServer | |||||
| { | |||||
| public Cacheable<IGuild, ulong> Guild { get; private set; } | |||||
| public string Endpoint { get; private set; } | |||||
| public string Token { get; private set; } | |||||
| internal SocketVoiceServer(Cacheable<IGuild, ulong> guild, ulong guildId, string endpoint, string token) | |||||
| { | |||||
| Guild = guild; | |||||
| Endpoint = endpoint; | |||||
| Token = token; | |||||
| } | |||||
| private string DebuggerDisplay => $"SocketVoiceServer ({Guild.Id})"; | |||||
| } | |||||
| } | |||||