.prune is heavily nerfed

This commit is contained in:
Master Kwoth 2016-02-09 23:45:34 +01:00
parent 9f9ef8923b
commit b3ef288a27
2 changed files with 11 additions and 22 deletions

View File

@ -359,17 +359,16 @@ namespace NadekoBot.Modules {
}); });
cgb.CreateCommand(".leaveall") cgb.CreateCommand(".leaveall")
.Description("Nadeko leaves all servers") .Description("Nadeko leaves all servers **OWNER ONLY**")
.Do(e => { .Do(e => {
if (e.User.Id == NadekoBot.OwnerID) if (e.User.Id == NadekoBot.OwnerID)
NadekoBot.client.Servers.ForEach(async s => { if (s.Name == e.Server.Name) return; await s.Leave(); }); NadekoBot.client.Servers.ForEach(async s => { if (s.Name == e.Server.Name) return; await s.Leave(); });
}); });
ConcurrentDictionary<Server, bool> pruneDict = new ConcurrentDictionary<Server, bool>(); ConcurrentDictionary<Server, bool> pruneDict = new ConcurrentDictionary<Server, bool>();
cgb.CreateCommand(".prune") cgb.CreateCommand(".prune")
.Parameter("num", ParameterType.Required) .Parameter("num", ParameterType.Required)
.Description("Prunes a number of messages from the current channel.\n**Usage**: .prune 50") .Description("Prunes a number of messages from the current channel.\n**Usage**: .prune 5")
.Do(async e => { .Do(async e => {
if (!e.User.ServerPermissions.ManageMessages) return; if (!e.User.ServerPermissions.ManageMessages) return;
if (pruneDict.ContainsKey(e.Server)) if (pruneDict.ContainsKey(e.Server))
@ -379,24 +378,13 @@ namespace NadekoBot.Modules {
await e.Send("Incorrect amount."); await e.Send("Incorrect amount.");
return; return;
} }
pruneDict.TryAdd(e.Server, true); if (num > 10)
await Task.Factory.StartNew(async () => { num = 10;
try { var msgs = await e.Channel.DownloadMessages(num);
Message last = null;
while (num > 0) {
var msgs = await e.Channel.DownloadMessages(num, last?.Id);
last = msgs.LastOrDefault();
foreach (var m in msgs) { foreach (var m in msgs) {
await m.Delete(); await m.Delete();
await Task.Delay(500); await Task.Delay(500);
} }
num -= 100;
}
} catch (Exception) { await e.Send("Failed pruning. Make sure the bot has correct permissions."); }
}, TaskCreationOptions.LongRunning);
bool throwAway;
pruneDict.TryRemove(e.Server, out throwAway);
}); });
cgb.CreateCommand(".die") cgb.CreateCommand(".die")

View File

@ -128,6 +128,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Classes\DBHandler.cs" /> <Compile Include="Classes\DBHandler.cs" />
<Compile Include="Classes\FlowersHandler.cs" />
<Compile Include="Classes\Music\MusicControls.cs" /> <Compile Include="Classes\Music\MusicControls.cs" />
<Compile Include="Classes\Music\StreamRequest.cs" /> <Compile Include="Classes\Music\StreamRequest.cs" />
<Compile Include="Classes\Music\SoundCloud.cs" /> <Compile Include="Classes\Music\SoundCloud.cs" />