/// <summary> /// Unlogs an emoji from the database. /// </summary> /// <param name="channel">The channel that the emoji was used in.</param> /// <param name="message">The message associated with the emoji.</param> /// <param name="reaction">The emoji that was used.</param> /// <param name="emote">The emote that was used, if any.</param> /// <returns> /// A <see cref="Task"/> that will complete when the operation completes. /// </returns> private async Task UnlogReactionAsync(ITextChannel channel, IUserMessage message, ISocketReaction reaction, IEmoteEntity emote) { using (var transaction = await _emojiRepository.BeginMaintainTransactionAsync()) { await _emojiRepository.DeleteAsync(new EmojiSearchCriteria() { GuildId = channel.GuildId, ChannelId = channel.Id, MessageId = message.Id, UserId = reaction.UserId, EmojiId = emote?.Id, EmojiName = emote is null ? reaction.Emote.Name : null, UsageType = EmojiUsageType.Reaction, });
/// <summary> /// Logs a reaction in the database. /// </summary> /// <param name="channel">The channel that the emoji was used in.</param> /// <param name="message">The message associated with the emoji.</param> /// <param name="reaction">The emoji that was used.</param> /// <param name="emote">The emote that was used, if any.</param> /// <returns> /// A <see cref="Task"/> that will complete when the operation completes. /// </returns> private async Task LogReactionAsync(ITextChannel channel, IUserMessage message, ISocketReaction reaction, IEmoteEntity emote) { using (var transaction = await _emojiRepository.BeginMaintainTransactionAsync()) { await _emojiRepository.CreateAsync(new EmojiCreationData() { GuildId = channel.GuildId, ChannelId = channel.Id, MessageId = message.Id, UserId = reaction.UserId, EmojiId = emote?.Id, EmojiName = reaction.Emote.Name, IsAnimated = emote?.Animated ?? false, UsageType = EmojiUsageType.Reaction, }); transaction.Commit(); } }
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); } }
private Task OnReactionRemovedAsync(ICacheable <IUserMessage, ulong> message, IISocketMessageChannel channel, ISocketReaction reaction) { MessageDispatcher.Dispatch(new ReactionRemovedNotification(message, channel, reaction)); return(Task.CompletedTask); }
public async Task ReactionAdded(ICacheable <IUserMessage, ulong> cachedMessage, IISocketMessageChannel channel, ISocketReaction reaction) { //Don't trigger if the emoji is wrong, if the user is a bot, or if we've //made an error message reply already if (reaction.User.IsSpecified && reaction.User.Value.IsBot) { return; } if (reaction.Emote.Name != _emoji || ErrorReplies.ContainsKey(cachedMessage.Id)) { return; } //If the message that was reacted to has an associated error, reply in the same channel //with the error message then add that to the replies collection if (AssociatedErrors.TryGetValue(cachedMessage.Id, out var value)) { var msg = await channel.SendMessageAsync("", false, new EmbedBuilder() { Author = new EmbedAuthorBuilder { IconUrl = "https://raw.githubusercontent.com/twitter/twemoji/gh-pages/2/72x72/26a0.png", Name = "That command had an error" }, Description = value, Footer = new EmbedFooterBuilder { Text = "Remove your reaction to delete this message" } }.Build()); if (ErrorReplies.TryAdd(cachedMessage.Id, msg.Id) == false) { await msg.DeleteAsync(); } } }
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()); } }
/// <summary> /// Constructs a new <see cref="ReactionRemovedNotification"/> object from the given data values. /// </summary> /// <param name="message">The value to use for <see cref="Message"/>.</param> /// <param name="channel">The value to use for <see cref="Channel"/>.</param> /// <param name="reaction">The value to use for <see cref="Reaction"/>.</param> /// <exception cref="ArgumentNullException">Throws for <paramref name="channel"/> and <paramref name="reaction"/>.</exception> public ReactionRemovedNotification(ICacheable <IUserMessage, ulong> message, IISocketMessageChannel channel, ISocketReaction reaction) { Message = message; Channel = channel ?? throw new ArgumentNullException(nameof(channel)); Reaction = reaction ?? throw new ArgumentNullException(nameof(reaction)); }