Browse Source

Throw a preemptive exception when sending presence data before connect

This prevents a later, less detailed nullref, when attempting to set the CurrentUser's presence data.

This also removes a redundant CurrentUser assignment in the SetGameAsync method, since this will be set later on in the SendStatusAsync method.
tags/1.0.0-rc2
Christopher F 8 years ago
parent
commit
f759f942f8
1 changed files with 2 additions and 1 deletions
  1. +2
    -1
      src/Discord.Net.WebSocket/DiscordSocketClient.cs

+ 2
- 1
src/Discord.Net.WebSocket/DiscordSocketClient.cs View File

@@ -355,11 +355,12 @@ namespace Discord.WebSocket
Game = new Game(name, streamUrl, streamType);
else
Game = null;
CurrentUser.Presence = new SocketPresence(Status, Game);
await SendStatusAsync().ConfigureAwait(false);
}
private async Task SendStatusAsync()
{
if (ConnectionState != ConnectionState.Connected)
throw new InvalidOperationException("Presence data cannot be sent while the client is disconnected.");
var game = Game;
var status = Status;
var statusSince = _statusSince;


Loading…
Cancel
Save