示例#1
0
        public async Task StartAsync(TelegramBotClient client, string channelIdentifier, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Login into Flypack with account: {account}", _settings.Username);
            path = await _flypack.LoginAsync(_settings.Username, _settings.Password);

            if (string.IsNullOrEmpty(path))
            {
                LogFailedLogin(client, channelIdentifier); return;
            }

            while (!cancellationToken.IsCancellationRequested)
            {
                _logger.LogDebug("Fetch running at: {time}", DateTime.Now);
                var packages = await _flypack.GetPackagesAsync(path);

                if (packages == null && _retriesCount < MAX_RETRIES)
                {
                    LogFailedListPackages(client, channelIdentifier, path);
                    path = await _flypack.LoginAsync(_settings.Username, _settings.Password);

                    _retriesCount++; continue;
                }
                else if (_retriesCount >= MAX_RETRIES)
                {
                    LogMaxLoginAttemptsReached(client, channelIdentifier, path);
                    break;
                }
                else
                {
                    _retriesCount = 0;
                }

                packages = FilterPackages(packages);

                if (packages.Any())
                {
                    var message = ParseMessageFor(packages);
                    await client.SendTextMessageAsync(
                        chatId : channelIdentifier,
                        text : message,
                        parseMode : ParseMode.Markdown
                        );
                }
                await Task.Delay(TimeSpan.FromMinutes(_settings.FetchInterval), cancellationToken);
            }

            _logger.LogInformation("Cancellation requested");
        }
示例#2
0
 public async Task <bool> TestCredentialsAsync(string username, string password)
 => (await _flypack.LoginAsync(username, password)) != null;