Example #1
0
        private void HandleMessage(IMessage message)
        {
            if (message == null)
            {
                return;
            }
            switch (message.Type)
            {
            //We got a update, so we will update our current presence
            case MessageType.PresenceUpdate:
                PresenceMessage pm = message as PresenceMessage;
                if (pm != null)
                {
                    //We need to merge these presences together
                    if (_presence == null)
                    {
                        _presence = pm.Presence;
                    }
                    else if (pm.Presence == null)
                    {
                        _presence = null;
                    }
                    else
                    {
                        _presence.Merge(pm.Presence);
                    }

                    //Update the message
                    pm.Presence = _presence;
                }

                break;

            //Update our configuration
            case MessageType.Ready:
                ReadyMessage rm = message as ReadyMessage;
                if (rm != null)
                {
                    _configuration = rm.Configuration;
                    _user          = rm.User;

                    //Resend our presence and subscription
                    SynchronizeState();
                }
                break;

            //We got a message we dont know what to do with.
            default:
                break;
            }
        }
        private void HandleMessage(IMessage message)
        {
            //if (Disposed)
            //	throw new ObjectDisposedException("Discord IPC Client");

            if (message == null)
            {
                return;
            }
            switch (message.Type)
            {
            //We got a update, so we will update our current presence
            case MessageType.PresenceUpdate:
                var pm = message as PresenceMessage;
                if (pm != null)
                {
                    //We need to merge these presences together
                    if (_presence == null)
                    {
                        _presence = pm.Presence;
                    }
                    else if (pm.Presence == null)
                    {
                        _presence = null;
                    }
                    else
                    {
                        _presence.Merge(pm.Presence);
                    }

                    //Update the message
                    pm.Presence = _presence;
                }

                break;

            //Update our configuration
            case MessageType.Ready:
                var rm = message as ReadyMessage;
                if (rm != null)
                {
                    _configuration = rm.Configuration;
                    _user          = rm.User;

                    //Resend our presence and subscription
                    SynchronizeState();
                }
                break;

            //Update the request's CDN for the avatar helpers
            case MessageType.JoinRequest:
                if (Configuration != null)
                {
                    //Update the User object within the join request if the current Cdn
                    var jrm = message as JoinRequestMessage;
                    if (jrm != null)
                    {
                        jrm.User.SetConfiguration(Configuration);
                    }
                }
                break;

            case MessageType.Subscribe:
                var sub = message as SubscribeMessage;
                _subscription |= sub.Event;
                break;

            case MessageType.Unsubscribe:
                var unsub = message as UnsubscribeMessage;
                _subscription &= ~unsub.Event;
                break;

            //We got a message we dont know what to do with.
            default:
                break;
            }
        }