public async Task GetGameReportAsync()
        {
            if (!this.Manager.TryGet(this.Context.Channel.Id, out GameState currentGame) ||
                currentGame?.ReaderId == null ||
                !(this.Context.Channel is IGuildChannel guildChannel))
            {
                return;
            }

            IEnumerable <PhaseScore> phaseScores = await currentGame.GetPhaseScores();

            // If there's been no buzzes in the last question, don't show it in the report (could be end of the packet)
            PhaseScore lastQuestion = phaseScores.LastOrDefault();

            if (lastQuestion?.ScoringSplitsOnActions?.Any() != true)
            {
                phaseScores = phaseScores.SkipLast(1);
            }

            IEnumerable <ScoringSplit> splits = phaseScores
                                                .SelectMany(pairs => pairs.ScoringSplitsOnActions.Select(pair => pair.Split));
            HighestPointsLevel highestPointsLevel = FindHighestPointLevel(splits);

            // Because we only have the scoring splits here, we have to rely on buzzes having a team ID
            bool hasTeams = phaseScores
                            .Any(scoresInPhase => scoresInPhase.ScoringSplitsOnActions.Any(pair => pair.Action.Buzz.TeamId != null));
            IReadOnlyDictionary <string, string> teamIdToName = await currentGame.TeamManager.GetTeamIdToNames();

            int scoresByQuestionCount = phaseScores.Count();
            int questionsReported     = await this.Context.Channel.SendAllEmbeds(
                phaseScores,
                () => new EmbedBuilder()
            {
                Title = GameReportTitle,
                Color = Color.Gold
            },
                (phaseScore, index) =>
                GetEmbedFieldForPhase(
                    currentGame, phaseScore, teamIdToName, highestPointsLevel, index, index == scoresByQuestionCount - 1));

            if (questionsReported > 0)
            {
                return;
            }

            EmbedBuilder embedBuilder = new EmbedBuilder()
            {
                Title       = GameReportTitle,
                Color       = Color.Gold,
                Description = "No questions read or answered yet."
            };

            await this.Context.Channel.SendMessageAsync(embed : embedBuilder.Build());
        }
Esempio n. 2
0
        public static async Task GetScoreAsync(ICommandContext context, GameStateManager manager)
        {
            if (!manager.TryGet(context.Channel.Id, out GameState currentGame) ||
                currentGame?.ReaderId == null ||
                !(context.Channel is IGuildChannel guildChannel))
            {
                return;
            }

            IGuildUser guildBotUser = await context.Guild.GetCurrentUserAsync();

            ChannelPermissions channelPermissions = guildBotUser.GetPermissions(guildChannel);

            if (!channelPermissions.EmbedLinks)
            {
                await context.Channel.SendMessageAsync(
                    "This bot must have \"Embed Links\" permissions to show the score");

                return;
            }

            IEnumerable <KeyValuePair <PlayerTeamPair, LastScoringSplit> > scoringSplits =
                await currentGame.GetLastScoringSplits();

            HighestPointsLevel highestPointsLevel = FindHighestPointLevel(
                scoringSplits.Where(kvp => kvp.Value != null).Select(kvp => kvp.Value.Split));

            bool hasTeams        = scoringSplits.Any(kvp => kvp.Key.IsOnTeam);
            int  embedsSentCount = hasTeams ?
                                   await ShowScoreForTeams(context, currentGame, scoringSplits, highestPointsLevel) :
                                   await ShowScoreForShootout(context, currentGame, scoringSplits, highestPointsLevel);

            if (embedsSentCount == 0)
            {
                await context.Channel.SendMessageAsync("No one has scored yet");
            }
        }