public async Task SpamRemoveAsync(CommandContext ctx, [Description("The key to search for.")] string key, [Description("A specific user to search for, this param is optional")] DiscordMember ByUser = null) { try { IReadOnlyList <DiscordMessage> Messages = await ctx.Channel.GetMessagesAsync(); DiscordMessage InitRemoveMessage; key = key.ToLower(); bool ByUserInput = false; InitRemoveMessage = await ctx.RespondAsync("Checking messages..."); ByUserInput |= ByUser != null; IEnumerable <DiscordMessage> FilteredMessages; if (ByUserInput) { FilteredMessages = Messages.Where(xr => xr.Content.ToLower().Contains(key) && xr.Author.Id == ByUser.Id && xr != ctx.Message); } else { FilteredMessages = Messages.Where(xr => xr.Content.ToLower().Contains(key) && xr != ctx.Message); } await ctx.Channel.DeleteMessagesAsync(FilteredMessages, "Spam Removal Command Deletion"); ctx.Client.Logger.Log(Microsoft.Extensions.Logging.LogLevel.Information, $"Removed {FilteredMessages.Count()} matching messages."); await InitRemoveMessage.ModifyAsync($"Removed {FilteredMessages.Count()} matching messages."); await Task.Delay(3000); await InitRemoveMessage.DeleteAsync("Command auto deletion."); await ctx.Message.DeleteAsync(); } catch (Exception ex) { DiscordMessage ErrorMessage = await ctx.RespondAsync($"Something went wrong: {ex.Message}"); ctx.Client.Logger.Log(LogLevel.Error, $"Error in /s remove; {ex.Message}"); await Task.Delay(5000); await ErrorMessage.DeleteAsync("Command auto deletion."); await ctx.Message.DeleteAsync("Command auto deletion."); } }
private async void RefreshFilteredMessages() { if (waiting) { return; } waiting = true; await Task.Delay(500); waiting = false; var selection = await Dispatcher.InvokeAsync(() => session.ActiveAssetView.SelectedAssets.ToList()); FilteredMessages.Clear(); var ids = await Task.Run(() => { var result = new HashSet <AssetId>(); foreach (var asset in selection) { result.Add(asset.Id); var dependencyManager = asset.AssetItem.Package.Session.DependencyManager; var dependencies = dependencyManager.ComputeDependencies(asset.AssetItem.Id, AssetDependencySearchOptions.Out | AssetDependencySearchOptions.Recursive, ContentLinkType.All); if (dependencies != null) { foreach (var reference in dependencies.LinksOut) { result.Add(reference.Item.Id); } } } return(result); }); var selectedLoggers = loggers.Where(x => ids.Contains(x.Key.AssetId)); foreach (var loggerResult in selectedLoggers.Select(x => x.Value).OfType <LoggerResult>()) { FilteredMessages.AddRange(loggerResult.Messages); } ErrorCount = FilteredMessages.Count(x => x.IsAtLeast(LogMessageType.Warning)); }