예제 #1
0
        /// <summary>
        /// Receive message from the server to send to GTHX for processing
        /// </summary>
        /// <param name="channel">Channel the message was received on</param>
        /// <param name="fromUser">Nickname of the user the message was from</param>
        /// <param name="message">Text of the message</param>
        public void ReceiveMessage(string channel, string fromUser, string message)
        {
            var newMessage = new GthxMessageProducedEventArgs(channel, fromUser, message);
            var success    = _queue.Post(newMessage);

            if (!success)
            {
                _logger.LogError("Failed to process message");
            }
        }
예제 #2
0
        public void ReceiveAction(string channel, string fromUser, string action)
        {
            var newMessage = new GthxMessageProducedEventArgs(channel, fromUser, action, GthxMessageType.Action);
            var success    = _queue.Post(newMessage);

            if (!success)
            {
                _logger.LogError("Failed to process action");
            }
        }
예제 #3
0
        /// <summary>
        /// Handle messages coming in from the IRC server
        /// </summary>
        /// <param name="sender">unused</param>
        /// <param name="e">Information about the incoming message</param>
        private void HandleIncomingMessage(object?sender, GthxMessageProducedEventArgs e)
        {
            _logger.LogDebug("Gthx: Incoming {Type}: {Message}", e.Type, e.Message);
            if (e.Message.Any(c => c > 127))
            {
                var sb = new StringBuilder();
                sb.Append("Non-ASCII characters: ");
                int i = 0;
                foreach (var c in e.Message)
                {
                    if (c > 127)
                    {
                        string hex = ((int)c).ToString("X4");
                        sb.Append($"{i}: 0x{hex} ");
                    }
                    i++;
                }

                _logger.LogDebug(sb.ToString());
            }

            try
            {
                if (e.Type == GthxMessageType.Message)
                {
                    HandleReceivedMessage(e.Channel, e.FromUser, e.Message);
                }
                else
                {
                    HandleReceivedAction(e.Channel, e.FromUser, e.Message);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failure while processing '{message}' from {user} in {channel}", e.Message, e.FromUser, e.Channel);
            }
        }