Esempio n. 1
0
        private async Task <EntryTranfers> GetTransfersTextForEntry(ClassicLeagueEntry entry, int gameweek, ICollection <Player> players)
        {
            var transfersTask = _transfersClient.GetTransfers(entry.Entry);
            var picksTask     = _entryClient.GetPicks(entry.Entry, gameweek);

            var transfers = (await transfersTask).Where(x => x.Event == gameweek).Select(x => new
            {
                EntryId = x.Entry,
                PlayerTransferredOut = GetPlayerName(players, x.ElementOut),
                PlayerTransferredIn  = GetPlayerName(players, x.ElementIn),
                SoldFor   = x.ElementOutCost,
                BoughtFor = x.ElementInCost
            }).ToArray();

            var hasTransfers = transfers.Any();
            var sb           = new StringBuilder();

            if (hasTransfers)
            {
                try
                {
                    var picks          = await picksTask;
                    var transferCost   = picks.EventEntryHistory.EventTransfersCost;
                    var wildcardPlayed = picks.ActiveChip == FplConstants.ChipNames.Wildcard;
                    var freeHitPlayed  = picks.ActiveChip == FplConstants.ChipNames.FreeHit;
                    if (wildcardPlayed)
                    {
                        sb.Append($"{entry.GetEntryLink(gameweek)} threw a WILDCAAAAARD :fire::fire::fire::\n");
                    }
                    else if (freeHitPlayed)
                    {
                        sb.Append($"{entry.GetEntryLink(gameweek)} went all in with the Free Hit chip:\n");
                    }
                    else
                    {
                        var transferCostString = transferCost > 0 ? $" (-{transferCost} pts)" : "";
                        sb.Append($"{entry.GetEntryLink(gameweek)} transferred{transferCostString}:\n");
                    }
                    foreach (var entryTransfer in transfers)
                    {
                        sb.Append($"   :black_small_square:{entryTransfer.PlayerTransferredOut} ({Formatter.FormatCurrency(entryTransfer.SoldFor)}) :arrow_right: {entryTransfer.PlayerTransferredIn} ({Formatter.FormatCurrency(entryTransfer.BoughtFor)})\n");
                    }
                }
                catch (Exception e)
                {
                    _logger.LogError(e.Message, e);
                }
            }

            return(new EntryTranfers
            {
                Entry = entry,
                DidTransfer = hasTransfers,
                Text = sb.ToString()
            });
        }