Exemple #1
0
        private static void RateLimitCheck(object?sender, QueryBeforeExecuteEventArgs args)
        {
            var queryRateLimits = RateLimit.GetQueryRateLimit(args.QueryURL);

            if (queryRateLimits != null)
            {
                if (queryRateLimits.Remaining > 0)
                {
                    return;
                }

                using (var spinner = new Spinner("You have been rate limited by Twitter until " +
                                                 $"{queryRateLimits.ResetDateTime.ToLongTimeString()}. Please wait or Ctrl+C to quit"))
                {
                    Thread.Sleep((int)queryRateLimits.ResetDateTimeInMilliseconds);
                    spinner.Done();
                }
            }
        }
Exemple #2
0
        private static async Task <List <IUser> > GetTargets(string targetUsername)
        {
            using (var spinner = new Spinner("Loading your details"))
            {
                var result = new List <IUser>();
                var me     = User.GetAuthenticatedUser();

                spinner.Message = "Loading your friends";
                var friends = await me.GetFriendsAsync(int.MaxValue);

                spinner.Message = "Loading your target";
                var target = User.GetUserFromScreenName(targetUsername);
                result.Add(target);

                spinner.Message = "Loading your targets followers";
                var enermies = await target.GetFollowersAsync(int.MaxValue);

                var targetsForBlock = enermies.Where(enermy => !friends.Contains(enermy));
                result.AddRange(targetsForBlock);
                spinner.Done();
                return(result);
            }
        }
Exemple #3
0
        internal static async Task <List <(IUser, double)> > GetBotsOrDead(double minScore)
        {
            using (var spinner = new Spinner("Loading your details"))
            {
                var me = User.GetAuthenticatedUser();
                spinner.Message = "Loading your friends";
                var friends = await me.GetFriendIdsAsync(int.MaxValue);

                spinner.Message = "Loading your followers";
                var followers = await me.GetFollowersAsync(int.MaxValue);

                var scoringConfig = new ScoreConfig();

                spinner.Message = "Determining scores";
                var result = followers
                             .Where(_ => !friends.Contains(_.Id))
                             .Select(follower => (Follower: follower, Score: Score(follower, scoringConfig)))
                             .Where(_ => _.Score > minScore)
                             .OrderBy(_ => _.Follower.Name);

                spinner.Done();
                return(result.ToList());
            }
        }
Exemple #4
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);
        }