public async Task HandleNotificationAsync( MessageDeletedNotification notification, CancellationToken cancellationToken) { var guild = (notification.Channel as ISocketGuildChannel)?.Guild; using var logScope = MessageLoggingLogMessages.BeginMessageNotificationScope(_logger, guild?.Id, notification.Channel.Id, notification.Message.Id); MessageLoggingLogMessages.MessageDeletedHandling(_logger); await TryLogAsync( guild, notification.Message.HasValue?notification.Message.Value : null, null, notification.Channel, () => { var fields = Enumerable.Empty <EmbedFieldBuilder>() .Concat(FormatMessageContent(notification.Message.HasValue ? notification.Message.Value.Content : null) .EnumerateLongTextAsFieldBuilders("**Content**")) .Append(new EmbedFieldBuilder() .WithName("Channel ID") .WithValue(notification.Channel.Id) .WithIsInline(true)) .Append(new EmbedFieldBuilder() .WithName("Message ID") .WithValue(notification.Message.Id) .WithIsInline(true)); var embedBuilder = new EmbedBuilder(); if (notification.Message.HasValue) { embedBuilder = embedBuilder .WithUserAsAuthor(notification.Message.Value.Author, notification.Message.Value.Author.Id.ToString()); if (notification.Message.Value.Attachments.Any()) { fields = fields .Append(new EmbedFieldBuilder() .WithName("Attachments") .WithValue(string.Join(", ", notification.Message.Value.Attachments.Select(attachment => $"{attachment.Filename} ({attachment.Size}b)")))); } } return(embedBuilder // ↓ This character is a "wastebasket", don't worry .WithDescription($"\\🗑️ **Message deleted in {MentionUtils.MentionChannel(notification.Channel.Id)}**") .WithCurrentTimestamp() .WithFields(fields) .Build()); }, cancellationToken); MessageLoggingLogMessages.MessageDeletedHandled(_logger); }
public async Task HandleNotificationAsync( MessageUpdatedNotification notification, CancellationToken cancellationToken) { var guild = (notification.Channel as ISocketGuildChannel)?.Guild; if (notification.NewMessage.Author.Id == default) { // update caused by new thread created or deleted return; } using var logScope = MessageLoggingLogMessages.BeginMessageNotificationScope(_logger, guild?.Id, notification.Channel.Id, notification.NewMessage.Id); MessageLoggingLogMessages.MessageUpdatedHandling(_logger); await TryLogAsync( guild, notification.OldMessage.HasValue?notification.OldMessage.Value : null, notification.NewMessage, notification.Channel, () => new EmbedBuilder() .WithUserAsAuthor(notification.NewMessage.Author, notification.NewMessage.Author.Id.ToString()) .WithDescription($"\\📝 **Message edited in {notification.NewMessage.GetJumpUrlForEmbed()}**") .WithCurrentTimestamp() .WithFields(Enumerable.Empty <EmbedFieldBuilder>() .Concat(FormatMessageContent(notification.OldMessage.HasValue ? notification.OldMessage.Value.Content : null) .EnumerateLongTextAsFieldBuilders("**Original**")) .Concat(FormatMessageContent(notification.NewMessage.Content) .EnumerateLongTextAsFieldBuilders("**Updated**")) .Append(new EmbedFieldBuilder() .WithName("Channel ID") .WithValue(notification.Channel.Id) .WithIsInline(true)) .Append(new EmbedFieldBuilder() .WithName("Message ID") .WithValue(notification.NewMessage.Id) .WithIsInline(true))) .Build(), cancellationToken); MessageLoggingLogMessages.MessageUpdatedHandled(_logger); }