public async Task RunBots() { users = GetUsers(pathToUsers); SessionInfo sessionInfo = new SessionInfo(DateTime.Now); //Running bots using (HttpClient http = new HttpClient()) { foreach (User user in users) { LTCBot ltcBot = new LTCBot(user, http); await ltcBot.ConnectAsync(); await CheckAuthorization(ltcBot); //Check timeouts of bot if (!IsTimeoutsGood(user)) { continue; } BotStateInfo result = new BotStateInfo(); try { OnUserStarted?.Invoke(user); SubscribeOnBotEvents(ltcBot); result = await ltcBot.Start(); await TryToWithdraw(ltcBot, result); } catch (Exception e) { OnBotException?.Invoke(e); } SaveUsers(); OnUserCompleted?.Invoke(result); UpdateSessionInfo(sessionInfo, result); //Timeout before starting next bot if (users.Last() != user) { await Task.Delay(60000); } } } if (sessionInfo.CountOfUsers > 0) { sessionInfo.DurationInMinutes = (DateTime.Now - sessionInfo.Date).TotalMinutes; SaveSession(sessionInfo); } OnSessionCompleted?.Invoke(sessionInfo); }
private async Task CheckAuthorization(LTCBot ltcBot) { if (!ltcBot.IsAuthorized) { string passHash = await ltcBot.RequestCodeAsync(); OnAuthorizationNeeded?.Invoke(ltcBot.User); string code = InputMethod(); await ltcBot.MakeAuthAsync(code, passHash); } }
private async Task TryToWithdraw(LTCBot ltcBot, BotStateInfo result) { if (result.BalanceOfBot > 0.0004m) { try { await ltcBot.Withdraw(); OnWithdrawed?.Invoke(result.BalanceOfBot); withdrowedFromSession += result.BalanceOfBot; result.BalanceOfBot = 0; } catch (Exception e) { OnBotException?.Invoke(e); } } }
private void SubscribeOnBotEvents(LTCBot ltcBot) { ltcBot.OnCaptchaMeeted += OnCaptchaMeeted; ltcBot.OnSiteProcessed += OnSiteProcessed; ltcBot.OnBotFinished += LtcBot_OnBotFinished; }