Exemplo n.º 1
0
        private async Task EndPoll()
        {
            if (!_pollService.Current.IsActive())
            {
                return;
            }

            var results    = _pollService.CalculateResults();
            var totalVotes = results.Count;

            var resultsText = "";

            if (results.Any())
            {
                for (var i = 0; i < results.Count; i++)
                {
                    var key           = results.ElementAt(i).Key;
                    var votes         = results.ElementAt(i).Value;
                    var percentageBar = PollHelpers.GeneratePercentageBar(votes, totalVotes);

                    resultsText += $"• {_pollService.Current.Choices[key]}: `{percentageBar}`\n";
                }
            }
            else
            {
                resultsText = "No votes were cast";
            }

            var embed = BasePollEmbed()
                        .WithTitle("Poll over!")
                        .WithDescription(_pollService.Current.Question)
                        .AddField("Vote Results", resultsText);

            await ReplyAsync("", false, embed.Build());

            _pollService.EndCurrent();
        }