예제 #1
0
        public async Task End()
        {
            if (_votingService.VotingOpen())
            {
                Console.WriteLine("Ending voting session");
                _votingService.EndVote();

                var results = _votingService.GetResults(_nominationsService.GetNominations());
                _votingService.ClearResults();
                _nominationsService.ClearNominations();

                var sb = new StringBuilder();
                sb.AppendLine("Voting has ended! The results: ");

                foreach (var res in results)
                {
                    sb.AppendLine($"{res.Movie.Name}: {res.Votes}");
                }

                var winner = _votingService.GetWinner(results);

                sb.AppendLine($"The winner is: {winner.Movie.Name}");

                await ReplyAsync(sb.ToString());

                var movie = await _omdbService.GetMovieById(winner.Movie.ImdbId);
                await ReplyAsync(movie.ToString());
            }
            else
            {
                await ReplyAsync($"There is no vote in progress");
            }
        }
예제 #2
0
        public async Task EndVote([Remainder] string voteId = "0")
        {
            //The input is just a number
            if (ulong.TryParse(voteId, NumberStyles.None, CultureInfo.InvariantCulture, out ulong id))
            {
                //Cancel last vote the user started
                if (id == 0)
                {
                    UserAccount user = UserAccountsManager.GetAccount((SocketGuildUser)Context.User);
                    if (user.UserLastVoteId != 0)
                    {
                        await VotingService.EndVote(
                            ServerListsManager.GetServer(Context.Guild).GetVote(user.UserLastVoteId), Context.Guild);
                    }
                    else
                    {
                        await Context.Channel.SendMessageAsync(
                            "You don't appear to have any votes running, if you do, put in the ID of the vote message with this command as well!");
                    }
                    return;
                }

                Vote vote = ServerListsManager.GetServer(Context.Guild).GetVote(id);
                if (vote == null)
                {
                    await Context.Channel.SendMessageAsync("There are no votes with that ID!");

                    return;
                }

                if (((SocketGuildUser)Context.User).GuildPermissions.ManageMessages)
                {
                    await VotingService.EndVote(vote, Context.Guild);

                    await Context.Channel.SendMessageAsync("That vote was ended.");

                    return;
                }
                if (vote.VoteStarterUserId != Context.User.Id)
                {
                    await VotingService.EndVote(vote, Context.Guild);

                    await Context.Channel.SendMessageAsync("Your vote was ended.");

                    return;
                }
            }

            //End all votes
            if (voteId.RemoveWhitespace() == "*")
            {
                if (!((SocketGuildUser)Context.User).GuildPermissions.ManageMessages)
                {
                    await Context.Channel.SendMessageAsync("You don't have permissions to end all votes!");

                    return;
                }

                Vote[] votes = ServerListsManager.GetServer(Context.Guild).Votes.ToArray();
                foreach (Vote vote in votes)
                {
                    await VotingService.EndVote(vote, Context.Guild);
                }

                await Context.Channel.SendMessageAsync("All votes were ended.");

                return;
            }

            await Context.Channel.SendMessageAsync(
                "Unknown argument! Either needs to be none or a message ID to end a vote, or `*` to end all.");
        }