private void registerPurgeCmd() { commands.CreateCommand("purge") .Parameter("n", ParameterType.Required) .Parameter("channel", ParameterType.Optional) .AddCheck((cm, u, ch) => u.ServerPermissions.Administrator) .Do(async(e) => { int.TryParse(e.GetArg("n"), out int n); if (n > 100) { await e.Channel.SendMessage("Uh... I can only delete up to a hundred messages at a time. Sorry..."); return; } else if (e.GetArg("channel") == "") { Discord.Message[] messagesToDelete = await e.Channel.DownloadMessages(n); await e.Channel.DeleteMessages(messagesToDelete); } else { Discord.Channel channel = e.Server.FindChannels(e.GetArg("channel")).FirstOrDefault(); Debug.WriteLine(channel.Name); Discord.Message[] messagesToDelete = await channel.DownloadMessages(n); await channel.DeleteMessages(messagesToDelete); } await e.Channel.SendMessage("Got 'em."); }); }
public async void RemoveMessages(Discord.Server server) { if (server.Id != DiscordIds.AtlasId) { SettingsRepo settingsRepo = new SettingsRepo(new SettingsContext()); Discord.Channel channel = server.GetChannel(settingsRepo.GetLfgChannel(server.Id)); Discord.Message[] temp = await channel.DownloadMessages(100); bool found = false; try { while (temp.Length > 1 && temp.Last().Text != "queue has been cleared!") { await channel.DeleteMessages(temp); found = true; temp = await channel.DownloadMessages(100); } } catch { found = true; } if (found == true) { await channel.SendMessage("Queue has been cleared!"); } } else if (server.Id == DiscordIds.AtlasId) { List <Channel> channels = new List <Channel>(); foreach (var channel in server.TextChannels) { if (channel.Name.Contains("queue")) { channels.Add(channel); } } foreach (var channel in channels) { Discord.Message[] temp = await channel.DownloadMessages(); bool found = false; try { while (temp.Length > 1 && temp.Last().Text != "queue has been cleared!") { await channel.DeleteMessages(temp); found = true; temp = await channel.DownloadMessages(); } } catch { found = true; } if (found) { await channel.SendMessage("Queue has been cleared!"); } } } }