public async Task Handle(PublishAggregatedEntrySuggestions message, IMessageHandlerContext context) { string text; try { var entry = await _entryClient.Get(message.EntryId); text = $"{Link(entry)} for {entry.PlayerFullName}{Counting(message.SuggestionCount)}. \n{Formatter.BulletPoints(message.Descriptions)}"; } catch (Exception) { text = $"{message.EntryId} suggested{Counting(message.SuggestionCount)}, but it does not exist ЪциРђЇРЎѓ№ИЈ. \n{Formatter.BulletPoints(message.Descriptions)}"; } await context.SendLocal(new PublishToSlack(ThrottleSuggestionConstants.TeamId, ThrottleSuggestionConstants.SlackChannel, "Verified suggestion: " + text)); }
private async Task <VerifiedEntryPointsUpdate> GetLiveStatsForEntry(VerifiedEntry entry) { var basicEntry = await _entryClient.Get(entry.EntryId); return(new VerifiedEntryPointsUpdate( CurrentGwTotalPoints: basicEntry.SummaryOverallPoints ?? 0, OverallRank: basicEntry.SummaryOverallRank ?? 0, PointsThisGw: basicEntry.SummaryEventPoints ?? 0)); }
public async Task <(EntryItem[], bool)> GetBatchToIndex(int i, int batchSize) { var batch = await ClientHelper.PolledRequests(() => Enumerable.Range(i, batchSize).Select(n => _entryClient.Get(n, tolerate404: true)).ToArray(), _logger); var items = batch .Where(x => x != null && x.Exists) .Select(y => new EntryItem { Id = y.Id, TeamName = y.TeamName, RealName = y.PlayerFullName }).ToArray(); if (!items.Any()) { _currentConsecutiveCountOfMissingEntries += batchSize; } else { _currentConsecutiveCountOfMissingEntries = 0; } // There are large "gaps" of missing entries (deleted ones, perhaps). The indexing job needs to work its way past these gaps, but still stop when // we think that there are none left to index var couldBeMore = _currentConsecutiveCountOfMissingEntries < _options.ConsecutiveCountOfMissingLeaguesBeforeStoppingIndexJob; if (!couldBeMore) { if (_options.ResetIndexingBookmarkWhenDone) { await _indexBookmarkProvider.SetBookmark(1); } else { var resetBookmarkTo = i - _options.ConsecutiveCountOfMissingLeaguesBeforeStoppingIndexJob; await _indexBookmarkProvider.SetBookmark(resetBookmarkTo > 1?resetBookmarkTo : 1); } } else if (_bookmarkCounter > 50) // Set a bookmark at every 50th batch { await _indexBookmarkProvider.SetBookmark(i + batchSize); _bookmarkCounter = 0; } else { _bookmarkCounter++; } return(items, couldBeMore); }
public async Task <EntryItem> GetSingleEntryToIndex(int entryId) { await RefreshVerifiedEntries(); if (IsVerifiedEntry(entryId)) { return(ToEntryItem(_allVerifiedEntries.Single(x => x.EntryId == entryId))); } var entry = await _entryClient.Get(entryId); return(new EntryItem { Id = entry.Id, RealName = entry.PlayerFullName, TeamName = entry.TeamName }); }
private async Task <string> GetCountryToBoost(SlackTeam slackTeam) { string countryToBoost = null; if (slackTeam?.FplbotLeagueId != null) { var league = await _leagueClient.GetClassicLeague((int)slackTeam.FplbotLeagueId); var adminEntry = league?.Properties?.AdminEntry; if (adminEntry != null) { var admin = await _entryClient.Get(adminEntry.Value); if (admin != null) { countryToBoost = admin.PlayerRegionShortIso; } } } return(countryToBoost); }
public async Task <(LeagueItem[], bool)> GetBatchToIndex(int i, int batchSize) { var batch = await GetBatchOfLeagues(i, batchSize, (client, x) => client.GetClassicLeague(x, tolerate404: true)); var items = batch .Where(x => x != null && x.Exists) .Select(x => new LeagueItem { Id = x.Properties.Id, Name = x.Properties.Name, AdminEntry = x.Properties.AdminEntry }) .ToArray(); var adminsToFetch = items.Where(x => x.AdminEntry != null).Select(x => x.AdminEntry.Value).Distinct() .ToArray(); if (adminsToFetch.Any()) { var admins = await ClientHelper.PolledRequests(() => adminsToFetch.Select(x => _entryClient.Get(x)).ToArray(), _logger); foreach (var leagueItem in items) { var admin = admins.SingleOrDefault(a => a.Id == leagueItem.AdminEntry); if (admin != null) { leagueItem.AdminName = admin.PlayerFullName; leagueItem.AdminTeamName = admin.TeamName; leagueItem.AdminCountry = admin.PlayerRegionShortIso; } } } if (!items.Any()) { _currentConsecutiveCountOfMissingLeagues += batchSize; } else { _currentConsecutiveCountOfMissingLeagues = 0; } // There are large "gaps" of missing leagues (deleted ones, perhaps). The indexing job needs to work its way past these gaps, but still stop when // we think that there are none left to index var couldBeMore = _currentConsecutiveCountOfMissingLeagues < _options.ConsecutiveCountOfMissingLeaguesBeforeStoppingIndexJob; if (!couldBeMore) { await _indexBookmarkProvider.SetBookmark(1); } else if (_bookmarkCounter > 50) // Set a bookmark at every 50th batch { await _indexBookmarkProvider.SetBookmark(i + batchSize); _bookmarkCounter = 0; } else { _bookmarkCounter++; } return(items, couldBeMore); }