Exemplo n.º 1
0
 public async ValueTask HandleMessageDeleted(object sender, MessageDeletedEventArgs e)
 {
     foreach (var service in MessageDeletedServices)
     {
         await ExecuteAsync((service, e) => service.OnMessageDeleted(e), service, e).ConfigureAwait(false);
     }
 }
Exemplo n.º 2
0
        public async Task HandleAsync(MessageDeletedEventArgs args)
        {
            if (!(args.Channel is CachedTextChannel channel) ||
                !args.Message.HasValue || args.Message.Value.Author.IsBot) // TODO: What to do when message doesn't have value, other than ignore
            {
                return;
            }

            using var ctx = new AdminDatabaseContext(_provider);
            var guild = await ctx.GetOrCreateGuildAsync(channel.Guild.Id);

            if (!(await ctx.GetLoggingChannelAsync(channel.Guild.Id, LogType.MessageDelete) is { } logChannel))
            {
                return;
            }

            var builder = new LocalEmbedBuilder()
                          .WithErrorColor()
                          .WithTitle(_localization.Localize(guild.Language, "logging_message_delete", channel.Tag))
                          .WithDescription(args.Message.Value.Author.Format(false))
                          .AddField(_localization.Localize(guild.Language, "info_id"), args.Message.Id)
                          .WithTimestamp(DateTimeOffset.UtcNow);

            if (!string.IsNullOrWhiteSpace(args.Message.Value.Content))
            {
                builder.AddField(_localization.Localize(guild.Language, "info_content"),
                                 args.Message.Value.Content.TrimTo(1024, true));
            }

            if (channel.Guild.CurrentMember.Permissions.ViewAuditLog)
            {
                await Task.Delay(TimeSpan.FromSeconds(1));

                var logs = await channel.Guild.GetAuditLogsAsync <RestMessagesDeletedAuditLog>(10);

                if (logs.FirstOrDefault(x =>
                                        x.TargetId == args.Message.Value.Author.Id && x.ChannelId == args.Channel.Id) is { } log)
                {
                    var moderator = await args.Client.GetOrDownloadUserAsync(log.ResponsibleUserId);

                    builder.WithTitle(_localization.Localize(guild.Language, "logging_message_delete_moderator", moderator.Tag, channel.Tag));
                }
            }

            if (_temporaryImages.Remove(args.Message.Id, out var attachment))
            {
                using (attachment)
                {
                    await logChannel.SendMessageAsync(attachment,
                                                      embed : builder
                                                      .WithImageUrl($"attachment://{attachment.FileName}")
                                                      .Build());
                }

                return;
            }

            await logChannel.SendMessageAsync(embed : builder.Build());
        }
Exemplo n.º 3
0
        public async Task HandleAsync(MessageDeletedEventArgs args)
        {
            using var ctx = new AdminDatabaseContext(_provider);
            var reactionRoles = await ctx.ReactionRoles.Where(x => x.MessageId == args.Message.Id)
                                .ToListAsync();

            if (reactionRoles.Count > 0)
            {
                ctx.ReactionRoles.RemoveRange(reactionRoles);
            }
        }
Exemplo n.º 4
0
        private void Device_MessageDeleted(object sender, MessageDeletedEventArgs e)
        {
            if (this.MessageId == null)
            {
                return;
            }

            if (e.MessageId != this.MessageId)
            {
                return;
            }

            this.MessageId = null;
        }
Exemplo n.º 5
0
        public static async Task HandleMessageDeletedAsync(VerificationBot bot, MessageDeletedEventArgs e)
        {
            if (e.GuildId == null || e.Message == null)
            {
                return;
            }

            LocalEmbedBuilder embed = null;

            foreach (ConfigChannel channel in bot.Config
                     .GetOrAddGuild(e.GuildId.Value).Channels.Values
                     .Where(c => c.ChangelogChannels.Contains(e.ChannelId)))
            {
                if (embed == null)
                {
                    embed = new LocalEmbedBuilder()
                            .WithTitle("Message deleted")
                            .AddField("Channel", $"<#{e.Message.ChannelId}>")
                            .AddField("Author", e.Message.Author.Mention);

                    if (e.Message.Content.Length > 0)
                    {
                        embed.AddField("Content", e.Message.Content);
                    }

                    if (e.Message.Attachments.Count > 0)
                    {
                        embed.AddField("Attachments", string.Join('\n', e.Message.Attachments.Select(a => a.Url)));
                    }
                }

                if (await bot.GetChannelAsync(channel.GuildId, channel.Id) is ITextChannel textChannel)
                {
                    await textChannel.SendMessageAsync
                    (
                        new LocalMessageBuilder()
                        .WithEmbed(embed)
                        .Build()
                    );
                }
            }
        }
Exemplo n.º 6
0
        public async Task HandleAsync(MessageDeletedEventArgs args)
        {
            if (!(args.Channel is CachedTextChannel channel))
            {
                return;
            }

            using var ctx = new AdminDatabaseContext(_provider);
            if (!(await ctx.Starboard.FirstOrDefaultAsync(x => x.MessageId == args.Message.Id ||
                                                          x.EntryMessageId == args.Message.Id) is { } entry))
            {
                return;
            }

            ctx.Starboard.Remove(entry);
            await ctx.SaveChangesAsync();

            if (args.Message.Id != entry.EntryMessageId)
            {
                await args.Client.DeleteMessageAsync(entry.EntryChannelId, entry.EntryMessageId);
            }
        }
 protected internal virtual ValueTask OnMessageDeleted(MessageDeletedEventArgs e)
 => default;
Exemplo n.º 8
0
 public void OnMessageDeleted(MessageDeletedEventArgs e)
 {
     (this.__Events[__evMessageDeleted] as EventHandler <MessageDeletedEventArgs>)?.Invoke(this, e);
 }
Exemplo n.º 9
0
 private Task OnMessageDeleted(object sender, MessageDeletedEventArgs e)
 => ChangelogService.HandleMessageDeletedAsync(this, e);