public async Task MakeAllFollowingsFollowersFollowRequestAsync(int top = 1000, IFilter <UserInfo> filter = null) { List <UserInfo> currentUserFollowingList = await instaService.GetCurrentUserFollowings(); List <UserInfo> requestList = new List <UserInfo>(); RandomGenerator random = new RandomGenerator(currentUserFollowingList.Count); for (int i = 0; i < currentUserFollowingList.Count; i++) { int index = random.Different(); var following = currentUserFollowingList[index]; logger.Write($"Random UserName : {following.UserName}, Index Order {i}"); List <UserInfo> userInfoList = await instaService.GetUserFollowers(following.UserName, 10); filter = filter ?? FollowerFilter.DefaultFilter(); var filtered = filter.Apply(userInfoList); filtered.RemoveAll(u => currentUserFollowingList.Exists(c => c.Id == u.Id)); if (filtered != null && filtered.Count > 0) { requestList.AddRange(filtered); } if (requestList.Count >= top) { requestList = requestList.Take(top).ToList(); break; } } int requestIndex = 0; try { for (requestIndex = 0; requestIndex < requestList.Count; requestIndex++) { logger.Write($"Requested UserName : {requestList[requestIndex].UserName}, Remaining User {requestList.Count - requestIndex - 1}"); await Retry.DoAsync(() => instaService.FollowUserAsync(requestList[requestIndex].Id), TimeSpan.FromSeconds(3)); } } catch (Exception ex) { logger.Write(ex.ToString()); } finally { if (requestIndex > 0) { FileUtils.WriteAllToRequestedFile(requestList.Take(requestIndex).ToList()); } } }
public async Task MakeFollowRequestAsync(string userName, IFilter <UserInfo> filter = null) { Random rnd = new Random(); List <UserInfo> userInfoList = await instaService.GetUserFollowers(userName, 20); filter = filter ?? FollowerFilter.DefaultFilter(); var filtered = filter.Apply(userInfoList); for (int i = 0; i < filtered.Count; i++) { instaService.FollowUserAsync(filtered[i].Id); await Task.Delay(rnd.Next(ApiConstans.DELAY_TIME_MIN, ApiConstans.DELAY_TIME_MAX)); logger.Write($"Requested UserName : {filtered[i].UserName}, Remaining User {filtered.Count - i - 1}"); } FileUtils.WriteAllToRequestedFile(filtered); }