private async Task OnReactionEvent(DiscordEmoji emoji, bool cleared, DiscordGuild guild, DiscordMessage message) { // ignore DM reactions if (guild == null) { return; } if (emoji.Equals(_emoji)) { var starboardChannelId = await GetStarboardChannel(guild.Id); // only process if the starboard channel has a value and it's not in the starboard. if (starboardChannelId.HasValue) { // Fetch the message contents message = await message.Channel.GetMessageAsync(message.Id); // ignore bot messages if (message.Author.IsBot || message.ChannelId == starboardChannelId.Value) { return; } // only check the last days of messages var dateThreshold = DateTimeOffset.Now.AddDays(-1); if (message.CreationTimestamp < dateThreshold) { return; } var reactionCount = 0; if (!cleared) { DiscordReaction reaction = null; foreach (var e in message.Reactions) { if (e.Emoji.Equals(_emoji)) { reaction = e; break; } } reactionCount = reaction?.Count ?? 0; } await ProcessReaction(starboardChannelId.Value, message.Channel, message, reactionCount); } } }
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()); }