Fix issues with #984, remove extraneous whitespace (#1051)

- Removed unnecessary parameter in SocketVoiceServer

- Moved SocketVoiceServer into Entities/Voice

- Fixed a bug where trying to download the cached guild would throw

- Fixed a potential bug where Discord might not give us a port when
  connecting to voice
This commit is contained in:
Finite Reality
2018-05-04 11:42:54 +01:00
committed by Christopher F
parent 7cfed7ff67
commit bb4bb13846
2 changed files with 40 additions and 34 deletions

View File

@@ -1466,21 +1466,27 @@ 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, var isCached = guild != null;
async () => await ApiClient.GetGuildAsync(data.GuildId).ConfigureAwait(false) as IGuild); var cachedGuild = new Cacheable<IGuild, ulong>(guild, data.GuildId, isCached,
() => Task.FromResult(State.GetGuild(data.GuildId) as IGuild));
var voiceServer = new SocketVoiceServer(cacheable, data.GuildId, data.Endpoint, data.Token); var voiceServer = new SocketVoiceServer(cachedGuild, data.Endpoint, data.Token);
await TimedInvokeAsync(_voiceServerUpdatedEvent, nameof(UserVoiceStateUpdated), voiceServer).ConfigureAwait(false); await TimedInvokeAsync(_voiceServerUpdatedEvent, nameof(UserVoiceStateUpdated), voiceServer).ConfigureAwait(false);
if (guild != null) if (isCached)
{ {
string endpoint = data.Endpoint.Substring(0, data.Endpoint.LastIndexOf(':')); var endpoint = data.Endpoint;
//Only strip out the port if the endpoint contains it
var portBegin = endpoint.LastIndexOf(':');
if (portBegin > 0)
endpoint = endpoint.Substring(0, portBegin);
var _ = guild.FinishConnectAudio(endpoint, data.Token).ConfigureAwait(false); var _ = guild.FinishConnectAudio(endpoint, data.Token).ConfigureAwait(false);
} }
else else
{ {
await UnknownGuildAsync(type, data.GuildId).ConfigureAwait(false); await UnknownGuildAsync(type, data.GuildId).ConfigureAwait(false);
return;
} }
} }

View File

@@ -9,7 +9,7 @@ namespace Discord.WebSocket
public string Endpoint { get; private set; } public string Endpoint { get; private set; }
public string Token { get; private set; } public string Token { get; private set; }
internal SocketVoiceServer(Cacheable<IGuild, ulong> guild, ulong guildId, string endpoint, string token) internal SocketVoiceServer(Cacheable<IGuild, ulong> guild, string endpoint, string token)
{ {
Guild = guild; Guild = guild;
Endpoint = endpoint; Endpoint = endpoint;