Exemple #1
0
        public async Task <string> ProcessorAsync(OnChatCommandReceivedArgs e)
        {
            if (e.Command.ArgumentsAsList.Count < 1)
            {
                return(StandardMessages.FilterFormat);
            }

            User user = null;

            if (e.Command.ArgumentsAsList.Count >= 2)
            {
                try
                {
                    user = await _apiRetriever.GetUserByUsernameAsync(e.Command.ArgumentsAsList[1])
                           .ConfigureAwait(false);
                }
                catch (Exception exception)
                {
                    Log.Error(exception.Message, "Bad request {parameter}", e.Command.ArgumentsAsString);
                    return(String.Format(StandardMessages.ErrorMessages.InvalidName, e.Command.ArgumentsAsList[1]));
                }

                if (user == null)
                {
                    return(String.Format(StandardMessages.ErrorMessages.UserMissing, e.Command.ArgumentsAsList[1]));
                }
            }

            switch (e.Command.ArgumentsAsList[0])
            {
            case "get":
            {
                if (user != null)
                {
                    if (_filterManager.CheckIfUserIdFiltered(user.Id))
                    {
                        return($"/me {user.DisplayName} este filtrat!");
                    }
                    return($"/me {user.DisplayName} nu este filtrat!");
                }

                var filteredUsers = _filterManager.RetrieveFilteredUsers();
                if (filteredUsers.Count <= 0)
                {
                    return("/me Nici un User filtrat!");
                }
                var builder = new StringBuilder();
                builder.Append("Useri filtrati:");
                for (var i = 0; i < filteredUsers.Count; i++)
                {
                    builder.Append($" {filteredUsers[i].DisplayName},");
                }
                return($"/me {builder}");
            }

            case "add":
            {
                if (user == null)
                {
                    return(StandardMessages.FilterFormat);
                }
                if (await _filterManager.AddToFilterAsync(new UserBase(user.DisplayName, user.Id))
                    .ConfigureAwait(false))
                {
                    return($"/me {user.DisplayName} adaugat la Filtru!");
                }
                return($"/me {user.DisplayName} deja in Filtru!");
            }

            case "rem":
            case "remove":
            {
                if (user == null)
                {
                    return(StandardMessages.FilterFormat);
                }
                if (await _filterManager.RemoveFromFilterAsync(new UserBase(user.DisplayName, user.Id))
                    .ConfigureAwait(false))
                {
                    return($"/me {user.DisplayName} sters din Filtru!");
                }
                return($"/me {user.DisplayName} nu este in Filtru!");
            }

            default:
                return(StandardMessages.FilterFormat);
            }
        }