/// <summary> /// Sets the Rich Presence. /// </summary> /// <param name="presence">The Rich Presence to set on the current Discord user.</param> public void SetPresence(RichPresence presence) { DoStandardPrecheck(false); //Send the event if (!presence) { //Clear the presence if (!SkipIdenticalPresence || CurrentPresence != null) { connection.EnqueueCommand(new PresenceCommand() { PID = this.ProcessID, Presence = null }); } } else { //Send valid presence //Validate the presence with our settings if (presence.HasSecrets() && !HasRegisteredUriScheme) { throw new BadPresenceException("Cannot send a presence with secrets as this object has not registered a URI scheme. Please enable the uri scheme registration in the DiscordRpcClient constructor."); } if (presence.HasParty() && presence.Party.Max < presence.Party.Size) { throw new BadPresenceException("Presence maximum party size cannot be smaller than the current size."); } if (presence.HasSecrets() && !presence.HasParty()) { Logger.Warning("The presence has set the secrets but no buttons will show as there is no party available."); } //Send the presence, but only if we are not skipping if (!SkipIdenticalPresence || !presence.Matches(CurrentPresence)) { connection.EnqueueCommand(new PresenceCommand() { PID = this.ProcessID, Presence = presence.Clone() }); } } //Update our local store lock (_sync) { CurrentPresence = presence != null?presence.Clone() : null; } }
/// <summary> /// Sets the Rich Presences /// </summary> /// <param name="presence">The rich presence to send to discord</param> public void SetPresence(RichPresence presence) { if (Disposed) { throw new ObjectDisposedException("Discord IPC Client"); } if (connection == null) { throw new ObjectDisposedException("Connection", "Cannot initialize as the connection has been deinitialized"); } //Update our internal store of the presence _presence = presence; if (!_presence) { //Clear the presence connection.EnqueueCommand(new PresenceCommand() { PID = this.ProcessID, Presence = null }); } else { //Send the presence connection.EnqueueCommand(new PresenceCommand() { PID = this.ProcessID, Presence = presence.Clone() }); } }
/// <summary> /// Sets the Rich Presence. /// </summary> /// <param name="presence">The Rich Presence to set on the current Discord user.</param> public void SetPresence(RichPresence presence) { if (IsDisposed) { throw new ObjectDisposedException("Discord IPC Client"); } if (connection == null) { throw new ObjectDisposedException("Connection", "Cannot initialize as the connection has been deinitialized"); } if (!IsInitialized) { Logger.Warning("The client is not yet initialized, storing the presence as a state instead."); } //SEnd the event if (!presence) { //Clear the presence connection.EnqueueCommand(new PresenceCommand() { PID = ProcessID, Presence = null }); } else { //Send valid presence //Validate the presence with our settings if (presence.HasSecrets() && !HasRegisteredUriScheme) { throw new BadPresenceException("Cannot send a presence with secrets as this object has not registered a URI scheme. Please enable the uri scheme registration in the DiscordRpcClient constructor."); } if (presence.HasParty() && presence.Party.Max < presence.Party.Size) { throw new BadPresenceException("Presence maximum party size cannot be smaller than the current size."); } if (presence.HasSecrets() && !presence.HasParty()) { Logger.Warning("The presence has set the secrets but no buttons will show as there is no party available."); } //Send the presence connection.EnqueueCommand(new PresenceCommand() { PID = ProcessID, Presence = presence.Clone() }); } //Update our local store lock (_sync) { CurrentPresence = presence; } }
/// <summary> /// Sets the Rich Presences /// </summary> /// <param name="presence">The rich presence to send to discord</param> public void SetPresence(RichPresence presence) { if (Disposed) { throw new ObjectDisposedException("Discord IPC Client"); } if (connection == null) { throw new ObjectDisposedException("Connection", "Cannot initialize as the connection has been deinitialized"); } //Update our internal store of the presence _presence = presence; if (!_presence) { //Clear the presence connection.EnqueueCommand(new PresenceCommand() { PID = this.ProcessID, Presence = null }); } else { //Send valid presence //Validate the presence with our settings if (presence.HasSecrets()) { if (!HasRegisteredUriScheme) { throw new BadPresenceException("Cannot send a presence with secrets as this object has not registered a URI scheme!"); } if (!string.IsNullOrEmpty(presence.Secrets.JoinSecret) && !presence.HasParty()) { throw new BadPresenceException("Presences that include Join Secrets must also include a party!"); } } if (presence.HasParty() && presence.Party.Max < presence.Party.Size) { throw new BadPresenceException("Presence maximum party size cannot be smaller than the current size."); } //Send the presence connection.EnqueueCommand(new PresenceCommand() { PID = this.ProcessID, Presence = presence.Clone() }); } }
public void SetPresence(RichPresence presence) { if (this.Disposed) { throw new ObjectDisposedException("Discord IPC Client"); } if (this.connection == null) { throw new ObjectDisposedException("Connection", "Cannot initialize as the connection has been deinitialized"); } this._presence = presence; if (!(bool)this._presence) { this.connection.EnqueueCommand((ICommand) new PresenceCommand() { PID = this.ProcessID, Presence = (RichPresence)null }); } else { if (presence.HasSecrets() && !this.HasRegisteredUriScheme) { throw new BadPresenceException("Cannot send a presence with secrets as this object has not registered a URI scheme!"); } if (presence.HasParty() && presence.Party.Max < presence.Party.Size) { throw new BadPresenceException("Presence maximum party size cannot be smaller than the current size."); } this.connection.EnqueueCommand((ICommand) new PresenceCommand() { PID = this.ProcessID, Presence = presence.Clone() }); } }