Exemple #1
0
        public Poll CreatePoll(PollCommandArguments args, List <string> optionList, IUser author)
        {
            EmbedBuilder builder = new EmbedBuilder()
                                   .WithAuthor(author)
                                   .WithTitle(args.Title)
                                   .WithDescription(args.Description)
                                   .WithCurrentTimestamp()
                                   .WithColor(Color.DarkBlue);

            if (optionList.Count == 0)
            {
                return(new Poll
                {
                    Message = builder
                              .AddField("👍", "Yes", true)
                              .AddField("👎", "No", true)
                              .Build(),
                    Emojis = new[] { "👍", "👎" }
                });
            }
            else
            {
                string        ops    = string.Join("\n\n", optionList.Select((o, i) => $"{ZeroIndexedEmojiNumbers[i]} {o}"));
                List <string> emojis = optionList.Select((o, i) => ZeroIndexedEmojiNumbers[i]).ToList();
                return(new Poll
                {
                    Message = builder
                              .AddField("# Options", ops, false)
                              .Build(),
                    Emojis = emojis
                });
            }
        }
Exemple #2
0
        public async Task GetCoinsAsync(List <string> options, PollCommandArguments args)
        {
            Optional <string> errorMessage = _service.ValidatePollCommandArguments(args, options);

            if (errorMessage.IsSpecified)
            {
                await ReplyAsync(errorMessage.Value);
            }
            else
            {
                Poll         poll        = _service.CreatePoll(args, options, Context.User);
                IUserMessage pollMessage = await ReplyAsync(string.Empty, false, poll.Message);

                await pollMessage.AddReactionsAsync(poll.Emojis.Select(e => new Emoji(e)).ToArray());
            }
        }
Exemple #3
0
 public Optional <string> ValidatePollCommandArguments(PollCommandArguments args, IEnumerable <string> options)
 {
     if (string.IsNullOrWhiteSpace(args.Title))
     {
         return(Optional.Create("Title must not be empty."));
     }
     if (string.IsNullOrWhiteSpace(args.Description))
     {
         return(Optional.Create("Description must not be empty."));
     }
     if (options.Count() == 1)
     {
         return(Optional.Create("Don't provide options for yes/no poll and provide more than one option for custom poll."));
     }
     if (options.Count() > 10)
     {
         return(Optional.Create("10 options max."));
     }
     return(Optional <string> .Unspecified);
 }