public void OnMessageReactionAdded(DiscordMessage message, DiscordReaction reaction) { foreach (var e in this.message) { e.OnMessageReactionAdded(message, reaction); } }
public void OnMessageEmojiReactionRemoved(DiscordMessage message, DiscordReaction reaction) { foreach (var e in this.message) { e.OnMessageEmojiReactionRemoved(message, reaction); } }
/// <summary> /// When the wrapper receives a reaction added /// </summary> /// <param name="cachable"></param> /// <param name="channel"></param> /// <param name="reaction"></param> protected Task OnReactionAddedAsync(Cacheable <IUserMessage, ulong> cachable, ISocketMessageChannel channel, SocketReaction reaction) { return(Task.Run(async() => { var reactionObj = new DiscordReaction(this, reaction); await OnReactionAddedAsync(reactionObj).ConfigureAwait(false); })); }
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); } } }
private void ReactionTracker() { try { Client.ReactionAdded += async(cachedMsg, msg, reaction) => { if (reaction.User.Value.IsBot) { return; } IMessage reactedMessage = await reaction.Channel.GetMessageAsync(cachedMsg.Id); if (reaction.User.Value.Id == reactedMessage.Author.Id) { return; } DiscordReaction reactionObj; if ((reaction.Emote as Emoji) == null) { reactionObj = new DiscordReaction(reaction.MessageId.ToString(), reaction.Channel.Id.ToString(), reactedMessage.Author.Id.ToString(), reaction.UserId.ToString(), (reaction.Emote as Emote).Id.ToString(), reaction.Emote.Name, DateTime.Now); } else { reactionObj = new DiscordReaction(reaction.MessageId.ToString(), reaction.Channel.Id.ToString(), reactedMessage.Author.Id.ToString(), reaction.UserId.ToString(), (reaction.Emote as Emoji).Name, DateTime.Now); } using (BotDBContext DBContext = DBFactory.Create <BotDBContext>()) { DBContext.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; await DBContext.AddAsync(reactionObj); await DBContext.SaveChangesAsync(); } }; Client.ReactionRemoved += async(cachedMsg, msg, reaction) => { if (reaction.User.Value.IsBot) { return; } IMessage reactedMessage = await reaction.Channel.GetMessageAsync(cachedMsg.Id); if (reaction.User.Value.Id == reactedMessage.Author.Id) { return; } using (BotDBContext DBContext = DBFactory.Create <BotDBContext>()) { DBContext.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; DiscordReaction existingReaction = DBContext.Reactions.FirstOrDefault(x => x.ReceiverId == reactedMessage.Author.Id.ToString() && x.ReactorId == reaction.UserId.ToString() && x.ReactionName == reaction.Emote.Name && x.Id == reaction.MessageId.ToString()); if (existingReaction != null) { DBContext.Remove(existingReaction); } await DBContext.SaveChangesAsync(); } }; Client.ReactionsCleared += async(msgCache, msgChannel) => { using (BotDBContext DBContext = DBFactory.Create <BotDBContext>()) { DBContext.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; IUserMessage fetchedMsg = await msgCache.GetOrDownloadAsync(); DBContext.Reactions.RemoveRange(DBContext.Reactions.FromSql("SELECT * FROM Reactions WHERE Id = {0}", fetchedMsg.Id).AsNoTracking().ToList()); ConsoleEx.WriteColoredLine($"Reactions cleared from message ID($[[DarkCyan]]${fetchedMsg.Id}$[[Gray]]$."); await DBContext.SaveChangesAsync(); } }; } catch (Exception ex) { Console.WriteLine(ex.Message); } }