public async Task RemoveJanitor() { using (Context.Channel.EnterTypingState()) { bool worked = StaticBase.ChannelJanitors.TryGetValue(Context.Channel.Id, out ChannelJanitor janitor); if (worked) { await ChannelJanitor.RemoveFromDBAsync(janitor); StaticBase.ChannelJanitors.Remove(Context.Channel.Id); await ReplyAsync("Removed janitor for this channel."); } else { await ReplyAsync("Could not find a janitor service for this channel."); } } }
public async Task Prune(bool testing = true) { using (Context.Channel.EnterTypingState()) { var toCheck = StaticBase.ChannelJanitors.Keys; var toPrune = toCheck.Select(x => Tuple.Create(x, Program.Client.GetChannel(x) == null)); if (!testing) { foreach (var channel in toPrune.Where(x => x.Item2).Select(x => x.Item1).ToList()) { bool worked = StaticBase.ChannelJanitors.TryGetValue(channel, out ChannelJanitor janitor); if (worked) { await ChannelJanitor.RemoveFromDBAsync(janitor); StaticBase.ChannelJanitors.Remove(channel); } } } await ReplyAsync($"Pruned {toPrune.Where(x => x.Item2).Count()} objects"); } }