/// <summary>
        /// Merges the passed presence with this one, taking into account the image key to image id annoyance.
        /// </summary>
        /// <param name="presence"></param>
        internal void Merge(RichPresence presence)
        {
            this._state     = presence._state;
            this._details   = presence._details;
            this.Party      = presence.Party;
            this.Timestamps = presence.Timestamps;
            this.Secrets    = presence.Secrets;

            //If they have assets, we should merge them
            if (presence.HasAssets())
            {
                //Make sure we actually have assets too
                if (!this.HasAssets())
                {
                    //We dont, so we will just use theirs
                    this.Assets = presence.Assets;
                }
                else
                {
                    //We do, so we better merge them!
                    this.Assets.Merge(presence.Assets);
                }
            }
            else
            {
                //They dont have assets, so we will just set ours to null
                this.Assets = null;
            }
        }
Beispiel #2
0
    /// <summary>
    /// Creats a new Presence object, copying values of the Rich Presence
    /// </summary>
    /// <param name="presence">The rich presence, often received by discord.</param>
    public DiscordPresence(DiscordRPC.RichPresence presence)
    {
        this.state   = presence.State;
        this.details = presence.Details;

        this.party   = presence.HasParty() ? new DiscordParty(presence.Party) : new DiscordParty();
        this.secrets = presence.HasSecrets() ? new DiscordSecrets(presence.Secrets) : new DiscordSecrets();

        if (presence.HasAssets())
        {
            this.smallAsset = new DiscordAsset()
            {
                image   = presence.Assets.SmallImageKey,
                tooltip = presence.Assets.SmallImageText
            };

            this.largeAsset = new DiscordAsset()
            {
                image   = presence.Assets.LargeImageKey,
                tooltip = presence.Assets.LargeImageText
            };
        }
        else
        {
            this.smallAsset = new DiscordAsset();
            this.largeAsset = new DiscordAsset();
        }

        if (presence.HasTimestamps())
        {
            this.startTime = presence.Timestamps.Start.HasValue ? new DiscordTimestamp(presence.Timestamps.Start.Value) : new DiscordTimestamp(0);
            this.endTime   = presence.Timestamps.End.HasValue ? new DiscordTimestamp(presence.Timestamps.End.Value) : new DiscordTimestamp(0);
        }
    }
    /// <summary>
    /// Creats a new Presence object, copying values of the Rich Presence
    /// </summary>
    /// <param name="presence">The rich presence, often received by discord.</param>
    public DiscordPresence(DiscordRPC.RichPresence presence)
    {
        if (presence != null)
        {
            this.state   = presence.State;
            this.details = presence.Details;

            this.party   = presence.HasParty() ? new DiscordParty(presence.Party) : new DiscordParty();
            this.secrets = presence.HasSecrets() ? new DiscordSecrets(presence.Secrets) : new DiscordSecrets();

            if (presence.HasAssets())
            {
                this.smallAsset = new DiscordAsset()
                {
                    image     = presence.Assets.SmallImageKey,
                    tooltip   = presence.Assets.SmallImageText,
                    snowflake = presence.Assets.SmallImageID.GetValueOrDefault(0)
                };


                this.largeAsset = new DiscordAsset()
                {
                    image     = presence.Assets.LargeImageKey,
                    tooltip   = presence.Assets.LargeImageText,
                    snowflake = presence.Assets.LargeImageID.GetValueOrDefault(0)
                };
            }
            else
            {
                this.smallAsset = new DiscordAsset();
                this.largeAsset = new DiscordAsset();
            }

            if (presence.HasTimestamps())
            {
                //This could probably be made simpler
                this.startTime = presence.Timestamps.Start.HasValue ? new DiscordTimestamp((long)presence.Timestamps.StartUnixMilliseconds.Value) : DiscordTimestamp.Invalid;
                this.endTime   = presence.Timestamps.End.HasValue ? new DiscordTimestamp((long)presence.Timestamps.EndUnixMilliseconds.Value) : DiscordTimestamp.Invalid;
            }
        }
        else
        {
            this.state      = "";
            this.details    = "";
            this.party      = new DiscordParty();
            this.secrets    = new DiscordSecrets();
            this.smallAsset = new DiscordAsset();
            this.largeAsset = new DiscordAsset();
            this.startTime  = DiscordTimestamp.Invalid;
            this.endTime    = DiscordTimestamp.Invalid;
        }
    }
 internal void Merge(RichPresence presence)
 {
     this._state     = presence._state;
     this._details   = presence._details;
     this.Party      = presence.Party;
     this.Timestamps = presence.Timestamps;
     this.Secrets    = presence.Secrets;
     if (presence.HasAssets())
     {
         if (!this.HasAssets())
         {
             this.Assets = presence.Assets;
         }
         else
         {
             this.Assets.Merge(presence.Assets);
         }
     }
     else
     {
         this.Assets = (Assets)null;
     }
 }