Ejemplo n.º 1
0
        // Users


        private async Task ProcessMessageAsync(ChatResponse msg)
        {
            await Task.Delay(0);

            try
            {
                switch (msg.Command)
                {
                case "PING":
                    await ApiClient.SendPingAsync(null).ConfigureAwait(false);

                    break;

                case "JOIN":
                    await _joinedChannelEvent.InvokeAsync(msg.Parameters.First().Substring(1)).ConfigureAwait(false);

                    break;

                case "PART":
                    await _leftChannelEvent.InvokeAsync(msg.Parameters.First().Substring(1)).ConfigureAwait(false);

                    break;

                case "PRIVMSG":
                {
                    var model  = MessageReceivedEvent.Create(msg);
                    var entity = ChatMessage.Create(this, model);
                    await _messageReceivedEvent.InvokeAsync(entity).ConfigureAwait(false);

                    ApiClient.CacheClient.AddMessage(entity);
                }
                break;

                case "MODE":      // missing
                    break;

                case "NOTICE":      // missing
                    break;

                case "CLEARCHAT":
                    break;

                case "USERSTATE":
                {
                    var model  = UserStateEvent.Create(msg);
                    var entity = ChatSelfUser.Create(this, model);
                    ApiClient.CacheClient.AddUser(entity);
                }
                break;

                case "RECONNECT":      // missing
                    break;

                case "ROOMSTATE":
                    break;

                case "USERNOTICE":
                    break;

                case "HOSTTARGET":      // missing
                    break;

                case "GLOBALUSERSTATE":      // missing
                    break;

                default:
                    await _chatLogger.WarningAsync($"Unknown command {msg.Command}").ConfigureAwait(false);

                    break;
                }
            }
            catch (Exception ex)
            {
                await _chatLogger.ErrorAsync($"Error handling {msg.Command}", ex).ConfigureAwait(false);
            }
        }