private async Task Poll() { try { Console.WriteLine("{0} Check Time", DateTime.Now); var dt = DateTime.Now; if ((dt - _lastCheckDateTime).TotalSeconds > 5) { Console.WriteLine("{0} Poll", DateTime.Now); DateTime lastTimeStamp = _timestampService.Get(".timestamp"); _timestampService.Set(".timestamp", DateTime.Now.ToUniversalTime()); _lastCheckDateTime = dt; var accounts = _accounts.GetAllWithShowTrophies(); foreach (var account in accounts) { var trophies = await _psnService.GetTrophies(account, lastTimeStamp); foreach (var ach in trophies) { var msg = await _telegramClient.SendMessage(new Telegram.SendMessageQuery() { ChatId = _chatId, Text = ach.GetTelegramMessage(), ParseMode = "HTML", DisableWebPagePreview = false, DisableNotification = true }); Thread.Sleep(1000); } if (trophies.Any()) { account.LastPolledTrophy = trophies.Last().TimeStamp; _accounts.Update(account); } Thread.Sleep(1000); } _lastCheckDateTime = dt; } Thread.Sleep(5000); } catch (Exception e) { Console.WriteLine(string.Format("{0}\t{1}", DateTime.Now, e.Message)); } }
private async Task Poll() { try { var dt = DateTime.Now; if ((dt - _lastCheckDateTime).TotalSeconds > 60) { _lastCheckDateTime = dt; DateTime lastPhotoTimeStamp = _timestampService.Get(".phototimestamp"); var msgs = (await _psnService.GetImages(lastPhotoTimeStamp)).OrderBy(m => m.TimeStamp); foreach (var msg in msgs) { var account = _accounts.GetByPSN(msg.Source); if (account != null) { var tlgMsg = await _telegramClient.SendMessage(new Telegram.SendMessageQuery() { ChatId = _chatId, Text = string.Format("Пользователь <b>{0} ({1})</b> опубликовал изображение:", account.PSNName, account.TelegramName), ParseMode = "HTML", }); var message = await _telegramClient.SendPhoto(new Telegram.SendPhotoQuery() { ChatId = _chatId }, msg.Data); Thread.Sleep(1000); } lastPhotoTimeStamp = msg.TimeStamp; } _timestampService.Set(".phototimestamp", lastPhotoTimeStamp); } Thread.Sleep(10000); } catch (Exception e) { Console.WriteLine(string.Format("{0}\t{1}", DateTime.Now, e.Message)); } }