Beispiel #1
0
        public static async Task <PolarReactionState> polarReaction(CommandContext ctx, DiscordMessage mes)
        {
            await mes.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":white_check_mark:"));

            await mes.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":x:"));

            // var collectedReactions = await mes.CollectReactionsAsync(TimeSpan.FromSeconds(60));
            // System.Collections.ObjectModel.ReadOnlyCollection<DSharpPlus.Interactivity.EventHandling.Reaction> collectedReactions;
            System.Collections.ObjectModel.ReadOnlyCollection <DSharpPlus.Interactivity.EventHandling.Reaction> collectedReactions;
            IEnumerable <DSharpPlus.Interactivity.EventHandling.Reaction> result = null;
            AsyncBinder checkReaction = async() => {
                collectedReactions = await mes.CollectReactionsAsync(TimeSpan.FromMilliseconds(500));

                result = collectedReactions.Where(r => new string[] { ":white_check_mark:", ":x:" }.Contains(r.Emoji.GetDiscordName()) && r.Users.Contains(ctx.Message.Author));
                return(result.Count() > 0);
            };

            await asyncExecuteFor(() => checkReaction(), TimeSpan.FromSeconds(60));

            if (result != null)
            {
                if (result.FirstOrDefault(r => r.Emoji.GetDiscordName() == ":white_check_mark:") != null)
                {
                    return(PolarReactionState.Yes);
                }
                else
                {
                    return(PolarReactionState.No);
                }
            }
            else
            {
                return(PolarReactionState.TimedOut);
            }
        }
Beispiel #2
0
        public async Task CollectionCommand(CommandContext ctx)
        {
            DiscordMessage message = await ctx.RespondAsync("React here!");

            var reactions = await message.CollectReactionsAsync();

            var strBuilder = new StringBuilder();
            Dictionary <DiscordUser, bool> winners = new Dictionary <DiscordUser, bool>();
            Dictionary <DiscordUser, bool> losers  = new Dictionary <DiscordUser, bool>();
            DiscordEmoji correctEmote = reactions[0].Emoji;

            foreach (var reaction in reactions)
            {
                foreach (DiscordUser person in reaction.Users)
                {
                    if (!correctEmote.Equals(reaction.Emoji))
                    {
                        losers.Add(person, true);
                    }
                    else
                    {
                        winners.Add(person, true);
                    }
                }
            }
            foreach (KeyValuePair <DiscordUser, bool> pair in winners)
            {
                if (losers.ContainsKey(pair.Key))
                {
                    winners.Remove(pair.Key);
                }
            }
            strBuilder.AppendLine("Winners are:");
            foreach (KeyValuePair <DiscordUser, bool> item in winners)
            {
                strBuilder.AppendLine(item.Key.Mention);
            }
            await ctx.RespondAsync(strBuilder.ToString());
        }