private async void OnAuthenticate(object obj) { await Task.Run(async() => { IsAuthorisation = false; IsSetCode = false; _telegramLogic = new TelegramLogic(NumberPhone); _path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sessions"); var tmpfiles = Directory.GetFiles(_path, "*", SearchOption.AllDirectories).ToList(); foreach (var item in tmpfiles) { _files.Add(Path.GetFileName(item)); } foreach (var item in _files) { if (item.Equals(NumberPhone + ".dat")) { await _telegramLogic.LogInAsync(); LoginResult = "Вы вошли успешно!!! "; return; } } await _telegramLogic.GetCodeAuthenticateAsync(); LoginResult = "Ждите код для подтверждения"; IsSetCode = true; }); }
public ShakalBot(string token) { Token = token; Api = new Api(token); Logic = new TelegramLogic <ShakalSession>(); }
public async void OnLoginCommandExecute(object obj) { await Task.Run(async() => { Regex regex = new Regex(@"^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$"); if (regex.IsMatch(PhoneNumber)) { IsLoggEnabled = false; TeleStatus = "Загрузка..."; TelegramContext = new TelegramLogic(PhoneNumber); string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sessions"); var tmpfiles = Directory.GetFiles(path, "*", SearchOption.AllDirectories).ToList(); foreach (var item in tmpfiles) { FileSessionStore.Add(Path.GetFileName(item)); } foreach (var item in FileSessionStore) { if (item.Equals(PhoneNumber + ".dat")) { await TelegramContext.LogInAsync(); TLChannelFulls = await TelegramContext.GetFullInfoCannelsAsync(); foreach (var channel in TLChannelFulls) { ChannelsNames.Add(channel.About); } MySelectedItem = ChannelsNames?[0]; IsProgramStarted = true; IsStartEnabled = true; IsCanChangeNumber = false; TeleStatus = "Вы вошли успешно!!! "; TelegramContext.LogOut(); return; } } try { await TelegramContext.GetCodeAuthenticateAsync(); TeleStatus = "Ждите код для подтверждения"; IsSetCode = true; } catch (Exception ex) { TeleStatus = ex.Message; File.Delete(PhoneNumber + ".dat"); IsLoggEnabled = true; } } else { TeleStatus = "Некорректный номер!\nПопробуйте: +1234..."; } }); }
public async void OnStartCommandExecute(object obj) { IsStartEnabled = false; IsStopEnabled = true; TeleStatus = "Рассылка запущена!"; await Task.Run(async() => { while (IsStopEnabled) { foreach (var item in DataGridQueries) { if (item.Status == "Ожидание...") { if (item.DateTimeSending <= DateTime.Now) { TelegramContext = new TelegramLogic(PhoneNumber); await TelegramContext.LogInAsync(); bool result = false; string exception = null; try { result = await TelegramContext.SendMessage(new TelegramLibrary.Models.SendingQueryModel() { PhotoPath = item?.PhotoPath, SendingChannel = item.SendingChannel, SendingText = item?.SendingText }); } catch (Exception ex) { exception = ex.StackTrace; } if (result) { item.Status = "Успешно!"; SuccessfullyRequested++; WaitingRequest--; DataWorker.AddInfoToDB(PhoneNumber, item.SendingChannel, String.IsNullOrEmpty(item?.PhotoPath), item?.SendingText, item.DateTimeSending, true, exception); } else { item.Status = "Не отправлено!"; BadRequested++; WaitingRequest--; DataWorker.AddInfoToDB(PhoneNumber, item.SendingChannel, String.IsNullOrEmpty(item?.PhotoPath), item?.SendingText, item.DateTimeSending, false, exception); } TelegramContext.LogOut(); } } } Thread.Sleep(15000); } }); }
public void Execute() { Logger.SelectedLevel = LogLevel.Error; Logger.Warning("Source code and binary files of this bot are absolutely free and open-source!"); Logger.Warning("If you've paid for it. Request a chargeback immediately!"); Logger.Warning("You only need pay for a key to access to Hash Service"); if (GlobalVars.Debug.VerboseMode) { Logger.SelectedLevel = LogLevel.Debug; Logger.ColoredConsoleWrite(ConsoleColor.Red, $"LogLevel set to {Logger.SelectedLevel}. Many logs will be generated."); } #region Log Logger Logger.Info($"Starting Execute on login server: {BotSettings.AuthType}"); if (BotSettings.LogPokemons) { Logger.Info("You enabled Pokemonlogging. It will be saved to \"\\Logs\\PokeLog.txt\""); } if (BotSettings.LogTransfer) { Logger.Info("You enabled manual transfer logging. It will be saved to \"\\Logs\\TransferLog.txt\""); } if (BotSettings.LogEvolve) { Logger.Info("You enabled Evolution Logging. It will be saved to \"\\Logs\\EvolutionLog.txt\""); } #endregion #region Set Counters and Location Setout.sessionStart = DateTime.UtcNow; Logger.Info("Setting Pokemon Catch Count: to 0 for this session"); Setout.pokemonCatchCount = 0; Logger.Info("Setting Pokestop Farmed Count to 0 for this session"); Setout.pokeStopFarmedCount = 0; if (GlobalVars.ContinueLatestSession) { Setout.LoadSession(); } objClient.CurrentAltitude = BotSettings.DefaultAltitude; objClient.CurrentLongitude = BotSettings.DefaultLongitude; objClient.CurrentLatitude = BotSettings.DefaultLatitude; #endregion #region Fix Altitude if (Math.Abs(objClient.CurrentAltitude) < double.Epsilon) { objClient.CurrentAltitude = LocationUtils.getAltitude(objClient.CurrentLatitude, objClient.CurrentLongitude); BotSettings.DefaultAltitude = objClient.CurrentAltitude; Logger.Warning($"Altitude was 0, resolved that. New Altitude is now: {objClient.CurrentAltitude}"); } #endregion #region Use Proxy if (BotSettings.proxySettings.enabled) { Logger.Error("==============================================="); Logger.Error("Proxy enabled."); Logger.Error($"ProxyIP: { BotSettings.proxySettings.hostName }:{BotSettings.proxySettings.port}"); Logger.Error("==============================================="); } #endregion #region Login & Start //Restart unless killswitch thrown while (restartLogic) { try { objClient.Login.DoLogin().Wait(); Logger.Debug("login done"); TelegramLogic.Instantiante(); PostLoginExecute(); Logger.Info("All Pokestops in range was already visited."); } catch (PtcOfflineException) { Logger.Error("PTC Servers are probably down."); } catch (AggregateException ae) { foreach (var e in ae.Flatten().InnerExceptions) { if (e is LoginFailedException) { Logger.Error(e.Message); Logger.Error("Exiting in 10 Seconds."); RandomHelper.RandomSleep(10000, 10001); Environment.Exit(0); } else if (e is GoogleException) { Logger.Error("Login Failed. Your credentials are wrong or Google Account is banned."); Logger.Error("Exiting in 10 Seconds."); RandomHelper.RandomSleep(10000, 10001); Environment.Exit(0); } else if (e is AccountNotVerifiedException) { Logger.Error("Your PTC Account is not activated."); Logger.Error("Exiting in 10 Seconds."); RandomHelper.RandomSleep(10000, 10001); Environment.Exit(0); } else { throw; } } } catch (Exception ex) { #region Log Error Exception realerror = ex; while (realerror.InnerException != null) { realerror = realerror.InnerException; } Logger.ExceptionInfo(ex.Message + "/" + realerror + "/" + ex.GetType()); #endregion } TelegramLogic.Stop(); var msToWait = 50000; Logger.ColoredConsoleWrite(ConsoleColor.Red, $"Restarting in over {(msToWait+5000)/1000} Seconds."); RandomHelper.RandomSleep(msToWait, msToWait + 10000); } #endregion }