Пример #1
0
        private async Task <int> Execute(bool dryRun, string targetUsername, bool all, string file, bool log, bool unmute)
        {
            if (!CommandHeader("Unblock 🔁", dryRun))
            {
                return(-1);
            }

            var me = User.GetAuthenticatedUser();

            var accountsToUnblock = new List <IUser>();

            if (all)
            {
                using (var spinner = new Spinner("Loading accounts"))
                {
                    if (unmute)
                    {
                        accountsToUnblock = Account.GetMutedUsers(int.MaxValue).ToList();
                    }
                    else
                    {
                        accountsToUnblock = me.GetBlockedUsers().ToList();
                    }

                    spinner.Done();
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(targetUsername))
                {
                    var individual = User.GetUserFromScreenName(targetUsername);
                    accountsToUnblock.Add(individual !);
                }

                if (!string.IsNullOrEmpty(file) && File.Exists(file))
                {
                    accountsToUnblock.AddRange(
                        (await File.ReadAllLinesAsync(file))
                        .Where(line => !line.StartsWith("#", StringComparison.InvariantCultureIgnoreCase))
                        .Select(line => line.Split(',', 1)[0].Trim())
                        .Where(line => !line.Contains(' ', StringComparison.InvariantCultureIgnoreCase))
                        .Select(line => User.GetUserFromScreenName(line)));
                }
            }

            using (var logger = new ThreadedLogger("Unblock.log", log))
                using (var pbar = new ProgressBar(accountsToUnblock.Count))
                {
                    logger.LogMessage($"# Unblock started {DateTime.Now.ToLongDateString()} " +
                                      $"{DateTime.Now.ToLongTimeString()}");

                    var actions = accountsToUnblock
                                  .Select(target => ProcessUser(dryRun, unmute, target, pbar, logger))
                                  .ToArray();

                    Task.WaitAll(actions);
                }

            Writeln(Green, $"{(unmute ? "Unmuted" : "Unblocked")} a total of {accountsToUnblock.Count} people");

            return(0);
        }