public async Task ReactionRemoved(ICacheable <IUserMessage, ulong> cachedMessage, IISocketMessageChannel channel, ISocketReaction reaction) { //Bugfix for NRE? if (reaction is null || reaction.User.Value is null) { return; } //Don't trigger if the emoji is wrong, or if the user is bot if (reaction.User.IsSpecified && reaction.User.Value.IsBot) { return; } if (reaction.Emote.Name != _emoji) { return; } //If there's an error reply when the reaction is removed, delete that reply, //remove the cached error, remove it from the cached replies, and remove //the reactions from the original message if (ErrorReplies.TryGetValue(cachedMessage.Id, out var botReplyId) == false) { return; } await channel.DeleteMessageAsync(botReplyId); if ( AssociatedErrors.TryRemove(cachedMessage.Id, out _) && ErrorReplies.TryRemove(cachedMessage.Id, out _) ) { var originalMessage = await cachedMessage.GetOrDownloadAsync(); //If we know what user added the reaction, remove their and our reaction //Otherwise just remove ours if (reaction.User.IsSpecified) { await originalMessage.RemoveReactionAsync(_emote, reaction.User.Value); } await originalMessage.RemoveReactionAsync(_emote, await _selfUserProvider.GetSelfUserAsync()); } }
private async Task HandleReactionAsync(ICacheable <IUserMessage, ulong> cachedMessage, IReaction reaction) { var emote = reaction.Emote; if (!_starboardService.IsStarEmote(emote)) { return; } var message = await cachedMessage.GetOrDownloadAsync(); if (!(message.Channel is IGuildChannel channel)) { return; } var isIgnoredFromStarboard = await _designatedChannelService .ChannelHasDesignationAsync(channel.Guild, channel, DesignatedChannelType.IgnoredFromStarboard); var starboardExists = await _designatedChannelService .AnyDesignatedChannelAsync(channel.GuildId, DesignatedChannelType.Starboard); if (isIgnoredFromStarboard || !starboardExists) { return; } var reactionCount = await _starboardService.GetReactionCount(message, emote); if (await _starboardService.ExistsOnStarboard(message)) { if (_starboardService.IsAboveReactionThreshold(reactionCount)) { await _starboardService.ModifyEntry(channel.Guild, message, FormatContent(reactionCount), GetEmbedColor(reactionCount)); } else { await _starboardService.RemoveFromStarboard(channel.Guild, message); } } else if (_starboardService.IsAboveReactionThreshold(reactionCount)) { var embed = GetStarEmbed(message, GetEmbedColor(reactionCount)); await _starboardService.AddToStarboard(channel.Guild, message, FormatContent(reactionCount), embed); } }
private async Task ModifyRatings(ICacheable <IUserMessage, ulong> cachedMessage, ISocketReaction reaction, ReactionState state) { if (reaction.Emote.Name != "tldr") { return; } var message = await cachedMessage.GetOrDownloadAsync(); if (message.Content.Length < 100) { return; } var roleIds = (reaction.User.GetValueOrDefault() as IGuildUser)?.RoleIds; if (roleIds == null) { return; } _repasteRatings.TryGetValue(message.Id, out var currentRating); var modifier = state == ReactionState.Added ? 1 : -1; if (roleIds.Count > 1) { currentRating += 2 * modifier; } else { currentRating += 1 * modifier; } _repasteRatings[message.Id] = currentRating; if (currentRating >= 2) { await UploadMessage(message); _repasteRatings.Remove(message.Id); } }