public override async Task OnMessageReceived(IUserMessage message, ITextChannel channel) { if (IgnoreNSFW && channel.IsNsfw) { return; } var matches = Regex.Matches(message.Content, RGX); if (matches.Count > 0) { var txt = await Service.GetAdminChannel(Guild); var embed = GetBuilder(withOperator: false); embed.Description = $"Message {message.Id} removed and user escalated for discussing a blocked topic. Matched content below."; foreach (Match match in matches) { if (embed.Fields.Count > 25) { break; } embed.AddField($"{match.Index}", Program.Clamp(match.Value, 256)); } await txt.SendMessageAsync(embed : embed.Build()); await message.DeleteAndTrackAsync($"Violation of topic block {Id}"); await this.Escalate(message.Author as SocketGuildUser); } }
public override async Task OnMessageReceived(IUserMessage message, ITextChannel channel) { if (IgnoreNSFW && channel.IsNsfw) { return; } if (message.Attachments.Count == 0) { return; } var attachment = message.Attachments.First(); var path = Path.Combine(Path.GetTempPath(), $"{message.Id}_{attachment.Filename}"); if (File.Exists(path) == false) { using var wc = new WebClient(); wc.DownloadFile(attachment.Url, path); } using var fstream = new FileStream(path, FileMode.Open); var algo = new DifferenceHash(); var hash = algo.Hash(fstream); var sim = CompareHash.Similarity(ImageHash, hash); if (sim < 97.5) { return; } await message.DeleteAndTrackAsync($"Image {sim:00}% similar to one blocked under {Id}"); await this.Escalate(message.Author as SocketGuildUser, $"Similarity: {sim:00.0}%"); }
public override async Task OnMessageReceived(IUserMessage message, ITextChannel channel) { if (channel.Name == "muted") { return; } var mutedRole = await GetMutedRole(); await channel.AddPermissionOverwriteAsync(mutedRole, new OverwritePermissions(sendMessages : PermValue.Deny)); await message.DeleteAndTrackAsync("User is muted"); }
public async Task Move(IUserMessage message, ITextChannel to) { var webhook = await Webhooks.GetWebhookClientAsync(to); var embeds = new List <Embed>(); if (message.Embeds != null) { foreach (var em in message.Embeds) { embeds.Add((Embed)em); } } string fileUrl = null; if (message.Attachments != null) { var diffSeconds = (DateTimeOffset.Now - message.CreatedAt).TotalSeconds; var sleepFor = 10 - diffSeconds; if (sleepFor > 0) { // give logging thread time to download & upload attachment Thread.Sleep((int)sleepFor * 1000); } var msgService = Program.Services.GetRequiredService <MsgService>(); var newAttachment = await msgService.GetSavedAttachment(to.Guild, message.Id); if (newAttachment == null) { var x = message.Attachments.First(); embeds.Add(new EmbedBuilder() .WithTitle(x.Filename) .WithUrl(x.Url) .WithImageUrl(x.Url) .WithFooter("Note: This file link may not work.") .Build()); } else { fileUrl = newAttachment.Url; } } string content = message.Content; if (fileUrl != null) { if (string.IsNullOrWhiteSpace(content)) { content = fileUrl; } else { content += "\r\n" + fileUrl; } } await webhook.SendMessageAsync( content, false, embeds, (message.Author as IGuildUser).Nickname ?? message.Author.Username, message.Author.GetAnyAvatarUrl() ); await message.DeleteAndTrackAsync("moving message"); }