public void OnModuleNWNXChat(NWPlayer sender)
        {
            if (!sender.IsPlayer && !sender.IsDM)
            {
                return;
            }
            string             text          = _nwnxChat.GetMessage();
            int                mode          = _nwnxChat.GetChannel();
            int                channel       = ConvertNWNXChatChannelIDToDatabaseID(mode);
            NWObject           recipient     = _nwnxChat.GetTarget();
            ChatChannelsDomain channelEntity = _db.ChatChannelsDomains.Single(x => x.ChatChannelID == channel);

            // Sender - should always have this data.
            string senderCDKey       = _.GetPCPublicCDKey(sender.Object);
            string senderAccountName = sender.Name;
            string senderPlayerID    = null;
            string senderDMName      = null;

            // DMs do not have PlayerIDs so store their name in another field.
            if (sender.IsDM)
            {
                senderDMName = "[DM: " + sender.Name + " (" + senderCDKey + ")]";
            }
            else
            {
                senderPlayerID = sender.GlobalID;
            }

            // Receiver - may or may not have the data.

            string receiverCDKey       = null;
            string receiverAccountName = null;
            string receiverPlayerID    = null;
            string receiverDMName      = null;

            if (recipient.IsValid)
            {
                receiverCDKey       = _.GetPCPublicCDKey(recipient.Object);
                receiverAccountName = recipient.Name;

                // DMs do not have PlayerIDs so store their name in another field.
                if (recipient.IsDM)
                {
                    receiverDMName = "[DM: " + recipient.Name + " (" + senderCDKey + ")]";
                }
                else
                {
                    receiverPlayerID = recipient.GlobalID;
                }
            }

            ChatLog entity = new ChatLog
            {
                Message             = text,
                SenderCDKey         = senderCDKey,
                SenderAccountName   = senderAccountName,
                SenderPlayerID      = senderPlayerID,
                SenderDMName        = senderDMName,
                ReceiverCDKey       = receiverCDKey,
                ReceiverAccountName = receiverAccountName,
                ReceiverPlayerID    = receiverPlayerID,
                ReceiverDMName      = receiverDMName,
                ChatChannelID       = channelEntity.ChatChannelID
            };

            _db.ChatLogs.Add(entity);
            _db.SaveChanges();
        }
        public void OnModuleNWNXChat(NWPlayer sender)
        {
            if (!sender.IsPlayer && !sender.IsDM)
            {
                return;
            }
            string text = _nwnxChat.GetMessage();

            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            int         mode          = _nwnxChat.GetChannel();
            int         channel       = ConvertNWNXChatChannelIDToDatabaseID(mode);
            NWObject    recipient     = _nwnxChat.GetTarget();
            ChatChannel channelEntity = _data.Single <ChatChannel>(x => x.ID == channel);

            // Sender - should always have this data.
            string senderCDKey       = _.GetPCPublicCDKey(sender.Object);
            string senderAccountName = sender.Name;
            Guid?  senderPlayerID    = null;
            string senderDMName      = null;

            // DMs do not have PlayerIDs so store their name in another field.
            if (sender.IsDM)
            {
                senderDMName = "[DM: " + sender.Name + " (" + senderCDKey + ")]";
            }
            else
            {
                senderPlayerID = sender.GlobalID;
            }

            // Receiver - may or may not have the data.

            string receiverCDKey       = null;
            string receiverAccountName = null;
            Guid?  receiverPlayerID    = null;
            string receiverDMName      = null;

            if (recipient.IsValid)
            {
                receiverCDKey       = _.GetPCPublicCDKey(recipient.Object);
                receiverAccountName = recipient.Name;

                // DMs do not have PlayerIDs so store their name in another field.
                if (recipient.IsDM)
                {
                    receiverDMName = "[DM: " + recipient.Name + " (" + senderCDKey + ")]";
                }
                else
                {
                    receiverPlayerID = recipient.GlobalID;
                }
            }

            ChatLog entity = new ChatLog
            {
                Message             = text,
                SenderCDKey         = senderCDKey,
                SenderAccountName   = senderAccountName,
                SenderPlayerID      = senderPlayerID,
                SenderDMName        = senderDMName,
                ReceiverCDKey       = receiverCDKey,
                ReceiverAccountName = receiverAccountName,
                ReceiverPlayerID    = receiverPlayerID,
                ReceiverDMName      = receiverDMName,
                ChatChannelID       = channelEntity.ID,
                DateSent            = DateTime.UtcNow
            };

            // Bypass the caching logic
            _data.DataQueue.Enqueue(new DatabaseAction(entity, DatabaseActionType.Insert));
        }