Exemplo n.º 1
0
        public Task <ActionResult> PollAsync([Remainder] string all)
        {
            var content  = all.Split(';', StringSplitOptions.RemoveEmptyEntries);
            var pollInfo = PollHelpers.GetPollBody(content, EmojiService);

            if (!pollInfo.IsValid)
            {
                return(BadRequest((content.Length - 1) > 5
                    ? "More than 5 options were specified."
                    : "No options specified."));
            }

            var embed = Context.CreateEmbedBuilder()
                        .WithTitle(Format.Bold(content[0]));

            foreach (var(key, value) in pollInfo.Fields)
            {
                embed.AddField(key, value, true);
            }

            return(Ok(embed.WithFooter(pollInfo.Footer), async msg =>
            {
                _ = await Context.Message.TryDeleteAsync("Poll invocation message.");
                await PollHelpers.AddPollReactionsAsync(content.Length - 1, msg, EmojiService);
            }));
        }
Exemplo n.º 2
0
        public Task <ActionResult> PollAsync([Remainder] string pollText)
        {
            var choices  = pollText.Split(';', StringSplitOptions.RemoveEmptyEntries);
            var pollInfo = PollHelpers.GetPollBody(choices, EmojiService);

            if (!pollInfo.IsValid)
            {
                return(BadRequest(choices.Length - 1 > 5
                    ? "More than 5 options were specified."
                    : "No options specified."));
            }

            var embed = Context.CreateEmbedBuilder()
                        .WithDescription(Format.Bold(choices[0]))
                        .WithTitle($"Poll by {Context.User}")
                        .WithThumbnailUrl("http://survation.com/wp-content/uploads/2016/09/polleverywherelogo.png");

            foreach (var(name, value) in pollInfo.Fields)
            {
                embed.AddField(name, value, true);
            }

            return(Ok(embed.WithFooter(pollInfo.Footer), async msg =>
            {
                _ = await Context.Message.TryDeleteAsync();
                await PollHelpers.AddPollReactionsAsync(choices, msg, EmojiService);
            }));
        }