private async void Load(TimeSpan duration, IEnumerable<Message> context) { Duration = duration; VictimList = new List<string>(); Cancel = false; PreordainedVictims = context.Where(c => !c.IsMod).Where(s => Predicate(s.SanitizedText) || Predicate(s.OriginalText)).Select(x => x.SenderName).Distinct().ToList(); Logger.Write(string.Join(",", PreordainedVictims), ConsoleColor.Cyan); try { var nuke = new AntiNuke(_messageProcessor); var cancelToken = nuke.CancellationTokenSource.Token; await Task.Run(() => nuke.Dissipate(this), cancelToken); } catch (TaskCanceledException e) { Logger.Write($"Cancelled!{Word}{Regex}"); Logger.Write(e.Message); } _messageProcessor.Nukes.Add(this); _messageProcessor.Sender.Post(new PublicMessage($"{Tools.PrettyDeltaTime(duration)} missiles away!")); while (PreordainedVictims.Except(VictimList).Any()) { if (!Cancel) { var victim = PreordainedVictims.Except(VictimList).First(); _messageProcessor.Sender.Post(new Mute(victim, Duration, null)); VictimList.Add(victim); await Task.Delay(Settings.NukeLoopWait); } else { return; } } _messageProcessor.Sender.Post(new PublicMessage( $"{VictimList.Count} souls were vaporized in a single blinding instant")); }
private async void Load(TimeSpan duration, IEnumerable <Message> context) { Duration = duration; VictimList = new List <string>(); Cancel = false; PreordainedVictims = context.Where(c => !c.IsMod).Where(s => Predicate(s.SanitizedText) || Predicate(s.OriginalText)).Select(x => x.SenderName).Distinct().ToList(); Logger.Write(string.Join(",", PreordainedVictims), ConsoleColor.Cyan); try { var nuke = new AntiNuke(_messageProcessor); var cancelToken = nuke.CancellationTokenSource.Token; await Task.Run(() => nuke.Dissipate(this), cancelToken); } catch (TaskCanceledException e) { Logger.Write($"Cancelled!{Word}{Regex}"); Logger.Write(e.Message); } _messageProcessor.Nukes.Add(this); _messageProcessor.Sender.Post(new PublicMessage($"{Tools.PrettyDeltaTime(duration)} missiles away!")); while (PreordainedVictims.Except(VictimList).Any()) { if (!Cancel) { var victim = PreordainedVictims.Except(VictimList).First(); _messageProcessor.Sender.Post(new Mute(victim, Duration, null)); VictimList.Add(victim); await Task.Delay(Settings.NukeLoopWait); } else { return; } } _messageProcessor.Sender.Post(new PublicMessage( $"{VictimList.Count} souls were vaporized in a single blinding instant")); }