Пример #1
0
        public Discord.Embed FormatPlay(PlayFile playFile)
        {
            var game         = playFile.Games.FirstOrDefault();
            var location     = playFile.Locations.FirstOrDefault();
            var play         = playFile.Plays.FirstOrDefault();
            var playerScores = play?.PlayerScores;
            var players      = playFile.Players;

            var builder = new Discord.EmbedBuilder()
                          .WithTitle(game?.Name ?? "None")
                          .WithDescription(BuildDescription(location, play))
                          .WithFooter(BuildFooter(game))
                          .WithThumbnailUrl(game.UrlThumb)
                          .WithColor(Discord.Color.Green);

            if (DateTimeOffset.TryParse(play.EntryDate, out DateTimeOffset timestamp))
            {
                builder.WithTimestamp(timestamp.ToLocalTime());
            }

            if (play.UsesTeams)
            {
                var teams = playerScores.GroupBy(x => x.Team).OrderBy(g => g.Key);
                var i     = 1;
                foreach (var team in teams)
                {
                    var teamWon  = team.Any(x => x.Winner);
                    var teamName = $"\r\nTeam {i++}{(teamWon ? " :trophy:" : "")}";

                    var sb = new StringBuilder();

                    foreach (var playerScore in team)
                    {
                        var playerData = players.FirstOrDefault(x => x.Id == playerScore.PlayerRefId);
                        if (playerData == null)
                        {
                            continue;
                        }

                        sb.AppendLine($"{playerData.Name}{(string.IsNullOrEmpty(playerScore.Score) ? "" : $" - {playerScore.Score}")}");
                        sb.AppendLine($"```{(string.IsNullOrEmpty(playerScore.TeamRole) ? "" : $"Role: {playerScore.TeamRole}\r\n")}BGG: {(string.IsNullOrEmpty(playerData.BggUsername) ? "Not set" : playerData.BggUsername)}```");
                    }

                    builder.AddField(x =>
                    {
                        x.Name  = teamName;
                        x.Value = sb.ToString();
                    });
                }
            }