private async Task TryLogAsync( ISocketGuild?guild, IMessage?oldMessage, IMessage?newMessage, IISocketMessageChannel channel, Func <Embed> renderLogMessage, CancellationToken cancellationToken) { if (guild is null) { MessageLoggingLogMessages.IgnoringNonGuildMessage(_logger); return; } // I.E. we have content for both messages and can see for sure it hasn't changed, E.G. Embed changes if ((oldMessage?.Content == newMessage?.Content) && (oldMessage is { }) &&
private Task OnReactionRemovedAsync(ICacheable <IUserMessage, ulong> message, IISocketMessageChannel channel, ISocketReaction reaction) { MessageDispatcher.Dispatch(new ReactionRemovedNotification(message, channel, reaction)); return(Task.CompletedTask); }
private Task OnMessageUpdatedAsync(ICacheable <IMessage, ulong> oldMessage, ISocketMessage newMessage, IISocketMessageChannel channel) { MessageDispatcher.Dispatch(new MessageUpdatedNotification(oldMessage, newMessage, channel)); 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="MessageUpdatedNotification"/> from the given values. /// </summary> /// <param name="oldMessage">The value to use for <see cref="OldMessage"/>.</param> /// <param name="newMessage">The value to use for <see cref="NewMessage"/>.</param> /// <param name="channel">The value to use for <see cref="Channel"/>.</param> /// <exception cref="ArgumentNullException">Throws for <paramref name="oldMessage"/>, <paramref name="newMessage"/>, and <paramref name="channel"/>.</exception> public MessageUpdatedNotification(ICacheable <IMessage, ulong> oldMessage, ISocketMessage newMessage, IISocketMessageChannel channel) { OldMessage = oldMessage ?? throw new ArgumentNullException(nameof(oldMessage)); NewMessage = newMessage ?? throw new ArgumentNullException(nameof(newMessage)); Channel = channel ?? throw new ArgumentNullException(nameof(channel)); }
/// <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)); }
/// <summary> /// Constructs a new <see cref="MessageDeletedNotification"/> from the given values. /// </summary> /// <param name="message">The value to use for <see cref="Message"/>.</param> /// <param name="message">The value to use for <see cref="Channel"/>.</param> /// <exception cref="ArgumentNullException">Throws for <paramref name="message"/> and <paramref name="channel"/>.</exception> public MessageDeletedNotification(ICacheable <IMessage, ulong> message, IISocketMessageChannel channel) { Message = message ?? throw new ArgumentNullException(nameof(message)); Channel = channel ?? throw new ArgumentNullException(nameof(channel)); }