Пример #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()
            });
        }
Пример #2
0
        private async Task <string> 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 sb = new StringBuilder();

            sb.Append($"{entry.GetEntryLink(gameweek)} ");
            if (transfers.Any())
            {
                try
                {
                    var picks              = await picksTask;
                    var transferCost       = picks.EventEntryHistory.EventTransfersCost;
                    var wildcardPlayed     = picks.ActiveChip == Constants.ChipNames.Wildcard;
                    var transferCostString = transferCost > 0 ? $" (-{transferCost} pts)" : wildcardPlayed ? " (:fire:wildcard:fire:)" : "";
                    sb.Append($"transferred{transferCostString}:\n");
                    foreach (var entryTransfer in transfers)
                    {
                        sb.Append($"   {entryTransfer.PlayerTransferredOut} ({Formatter.FormatCurrency(entryTransfer.SoldFor)}) :arrow_right: {entryTransfer.PlayerTransferredIn} ({Formatter.FormatCurrency(entryTransfer.BoughtFor)})\n");
                    }
                }
                catch (Exception e)
                {
                    sb.Append("was perhaps not part of this gameweek :shrug:\n");
                    Console.WriteLine(e.Message);
                }
            }
            else
            {
                sb.Append("made no transfers :shrug:\n");
            }

            return(sb.ToString());
        }