Ejemplo n.º 1
0
        //Tallies the result and displays the outcome in the original embed
        public async Task TallyResults()
        {
            //Recalculate the current ballot
            int votes = CalculateBallotScore();

            for (int i = 0; i < ballotItems.Length; i++)
            {
                ballotItems[i].movie.TotalScore     += ballotItems[i].score;
                ballotItems[i].movie.TotalVotes     += ballotItems[i].votes;
                ballotItems[i].movie.TimesUpForVote += 1;
            }

            //Determine the winner
            int maxWin = -1;

            for (int i = 0; i < ballotItems.Length; i++)
            {
                if (maxWin == -1)
                {
                    maxWin = i;
                    continue;
                }
                if (ballotItems[i].score > ballotItems[maxWin].score)
                {
                    maxWin = i;
                }
            }
            BallotItem winner = ballotItems[maxWin];
            //Show the winner in the old embed
            EmbedBuilder builder = new EmbedBuilder()
                                   .WithTitle($"The winning vote was {winner.movie.Title}!")
                                   .WithDescription($"To set the movie as watched use the command m!set_watched {winner.movie.Title}")
                                   .WithColor(new Color(0xE314C7));
            DateTime now = DateTime.UtcNow;
            string   fuu = $"{now.Month}/{now.Day}/{now.Year} {serverData.MovieTimeHour}:00:00";

            now = DateTime.Parse(fuu);
            DateTimeOffset offset = new DateTimeOffset(now, new TimeSpan(0, 0, 0));

            builder.WithTimestamp(offset);
            //We dooone - Remove this from the current setup.
            RankedServerVoting.ServersAndVotes.Remove(associatedGuild.Id);
            try {
                await voteMessage.RemoveAllReactionsAsync();
            } catch (Exception ex) {
                //We don't really want to do anything. This is to catch the servers which don't give permissions to the bot.
                LogMessage lm = new LogMessage(LogSeverity.Error, "Movie Information Embed", "Unable to remove reactions from the movie information embed! The server likely has not given permission to do this.");
                await Program.Instance.Log(lm);
            }

            await voteMessage.ModifyAsync(VoteMessage => {
                VoteMessage.Content = "Movie Vote!!!";
                VoteMessage.Embed   = builder.Build();
                return;
            });

            await channel.SendMessageAsync($"The winning vote was {winner.movie.Title}! To set the movie as watched use the command \n **m!set_watched {winner.movie.Title}**");
        }
Ejemplo n.º 2
0
        public RankedServerVote(SocketGuild guild, Movie[] movieOptions, ISocketMessageChannel channel)
        {
            this.associatedGuild = guild;
            this.channel         = channel;
            voters            = new Dictionary <ulong, List <int> >();
            this.movieOptions = movieOptions;
            Program.SubscribeToReactionAdded(ReactCallback);
            Program.SubscribeToReactionRemoved(UnReactCallback);
            //ServerData data = ServerData.Get(guild);
            //maxUserVotes = MoviesData.Model.GetVoteCount(guild);
            ballotItems = new BallotItem[movieOptions.Length];
            serverData  = ServerData.Get(guild);

            for (int i = 0; i < ballotItems.Length; i++)
            {
                ballotItems[i]       = new BallotItem();
                ballotItems[i].movie = movieOptions[i];
                ballotItems[i].votes = 0;
                ballotItems[i].score = 0;
            }
        }