Example #1
0
 public async Task Close()
 {
     if (CurrentVote.IsStarted)
     {
         await CurrentVote.Close();
     }
 }
Example #2
0
            public async Task Poll([Remainder, Summary("The question and options for the poll")] string poll)
            {
                if (CheckIfVoteIsAlreadyRunning().Result)
                {
                    return;
                }

                string optionDisplay = string.Empty;

                string[] pollOptions1 = poll.Split('|');
                string[] pollOptions2 = new string[pollOptions1.Length - 1];
                string   question     = pollOptions1[0];

                Array.Copy(pollOptions1, 1, pollOptions2, 0, pollOptions2.Length);
                optionDisplay = string.Join("\n", pollOptions2);

                //test for duplicates
                var groupings = pollOptions2.GroupBy(x => x);
                var duplicate = groupings.Where(x => x.Count() > 1);

                if (duplicate.Count() > 0)
                {
                    await ReplyAsync("Error! Duplicate poll options were found. Poll has not been started");

                    return;
                }

                CurrentVote.Question = question;
                pollOptions2.ToList().ForEach(x => CurrentVote.Options.Add(x.Trim()));
                CurrentVote._VoteType = CurrentVote.VoteType.Poll;

                CurrentVote.Start(Context);

                await ReplyAsync($"A poll has been initiated by {Context.User.Username}! \"{question}?\"\ntype \"$vote for <your choice>\", your choice being one of the following:\n{optionDisplay}");
            }
Example #3
0
            private async Task <bool> CheckIfVoteIsAlreadyRunning()
            {
                if (CurrentVote.IsStarted)
                {
                    TimeSpan tr            = CurrentVote.TimeRemaining();
                    string   timeRemaining = $"{tr.Hours} hours, {tr.Minutes} minutes, and {tr.Seconds} seconds";
                    await ReplyAsync($"There is already a vote running. {timeRemaining} remains. A vote will be closed if a majority has been reached. The current poll is:\n");
                    await DisplayVote();
                }

                return(CurrentVote.IsStarted);
            }
Example #4
0
            public async Task YesNo([Remainder, Summary("The question that is being voted on")] string question)
            {
                if (CheckIfVoteIsAlreadyRunning().Result)
                {
                    return;
                }

                CurrentVote.Question = question;
                CurrentVote.Options.Add("yes");
                CurrentVote.Options.Add("no");
                CurrentVote._VoteType = CurrentVote.VoteType.YesOrNo;

                CurrentVote.Start(Context);
                await ReplyAsync($"A yes or no vote has been initiated by {Context.User.Username}! \"{question}?\"\ntype \"$vote for <your choice>\", your choice being yes or no, to vote.");
            }
Example #5
0
        public async Task For([Remainder, Summary("The user's choice for the current vote.")] string choice)
        {
            if (CurrentVote.IsStarted)
            {
                bool hasVoted = CurrentVote.Votes.Keys.Contains(Context.User.Id);

                if (CurrentVote._VoteType == CurrentVote.VoteType.YesOrNo)
                {
                    choice = choice.ToLower();
                    choice = choice.Trim();
                    if (choice.Equals("y") || choice.Equals("yes"))
                    {
                        if (hasVoted)
                        {
                            CurrentVote.Votes[Context.User.Id] = "yes";
                        }
                        else
                        {
                            CurrentVote.Votes.Add(Context.User.Id, "yes");
                        }
                    }
                    else if (choice.Equals("n") || choice.Equals("no"))
                    {
                        if (hasVoted)
                        {
                            CurrentVote.Votes[Context.User.Id] = "no";
                        }
                        else
                        {
                            CurrentVote.Votes.Add(Context.User.Id, "no");
                        }
                    }
                    else
                    {
                        await ReplyAsync($"{choice} is not a valid selection for this poll. Please try again.");

                        return;
                    }
                }
                else
                {
                    if (CurrentVote.Options.Contains(choice))
                    {
                        if (hasVoted)
                        {
                            CurrentVote.Votes[Context.User.Id] = choice;
                        }
                        else
                        {
                            CurrentVote.Votes.Add(Context.User.Id, choice);
                        }
                    }
                    else
                    {
                        await ReplyAsync($"{choice} is not a valid selection for this poll. Please try again.");

                        return;
                    }
                }

                if (hasVoted)
                {
                    await ReplyAsync($"Your vote has been changed to {choice}");
                }
                else
                {
                    await ReplyAsync($"Your vote for {choice} has been submitted.");
                }

                CurrentVote.ResolveIfAble();
            }
            else
            {
                await ReplyAsync("There is no vote currently taking place.");
            }
        }
Example #6
0
 private async Task DisplayVote()
 {
     await ReplyAsync(CurrentVote.VoteText());
 }
Example #7
0
 public async Task Display([Remainder, Summary("dummy param")] string dummy = null)
 {
     await ReplyAsync(CurrentVote.VoteText());
 }