Пример #1
0
        public async Task Poll(CommandContext ctx,
                               [Description("How long the poll should last.")] TimeSpan duration,
                               [Description("What options should the poll have.")] params DiscordEmoji[] options)
        {
            ctx.Client.DebugLogger.LogMessage(LogLevel.Info, "PotatoBot", $"{ctx.Member.Username} started a poll between: {options.ToString()}", DateTime.Now);

            // Load interactivity module and poll options
            InteractivityModule interactivity = ctx.Client.GetInteractivityModule();
            var pollOptions = options.Select(xe => xe.ToString());

            // Display the poll
            var embed = new DiscordEmbedBuilder {
                Title       = "Poll Time!",
                Color       = DiscordColor.DarkButNotBlack,
                Description = "Choose your fighter: " + string.Join(" ", pollOptions)
            };
            DiscordMessage msg = await ctx.RespondAsync(embed : embed);

            // Add options as reactions
            for (int i = 0; i < options.Length; i++)
            {
                await msg.CreateReactionAsync(options[i]);
            }

            // Collect responses
            ReactionCollectionContext pollResult = await interactivity.CollectReactionsAsync(msg, duration); //TODO: Why this not working?

            var results = pollResult.Reactions.Where(xkvp => options.Contains(xkvp.Key))
                          .Select(xkvp => $"{xkvp.Key}: {xkvp.Value}");

            // Post response
            await ctx.RespondAsync(string.Join("\n", results));
        }
Пример #2
0
        public async Task Poll(CommandContext ctx, [Description("How long should the poll last.")] TimeSpan duration, [Description("What options should people have.")] params DiscordEmoji[] options)
        {
            // first retrieve the interactivity module from the client
            InteractivityModule interactivity = ctx.Client.GetInteractivityModule();
            var poll_options = options.Select(xe => xe.ToString());

            // then let's present the poll
            DiscordEmbedBuilder embed = new DiscordEmbedBuilder
            {
                Title       = "Poll time!",
                Description = string.Join(" ", poll_options)
            };
            DiscordMessage msg = await ctx.RespondAsync(embed : embed);

            // add the options as reactions
            for (int i = 0; i < options.Length; i++)
            {
                await msg.CreateReactionAsync(options[i]);
            }

            // collect and filter responses
            ReactionCollectionContext poll_result = await interactivity.CollectReactionsAsync(msg, duration);

            var results = poll_result.Reactions.Where(xkvp => options.Contains(xkvp.Key))
                          .Select(xkvp => $"{xkvp.Key}: {xkvp.Value}");

            // and finally post the results
            await ctx.RespondAsync(string.Join("\n", results));
        }
Пример #3
0
        public override async Task RunAsync(TimeSpan timespan)
        {
            this.endTime   = DateTime.Now + timespan;
            this.IsRunning = true;

            this.msgHandle = await this.channel.SendMessageAsync(embed : this.ToDiscordEmbed());

            this.rctx = await this.interactivity.CreatePollAsync(this.msgHandle, StaticDiscordEmoji.Numbers.Take(this.Options.Count), timespan);

            await this.channel.SendMessageAsync(embed : this.ResultsToDiscordEmbed());

            this.IsRunning = false;
        }