closes #259 merged .clr and .prune and implemented as described in my comment. UNTESTED
This commit is contained in:
parent
5fbe36e5da
commit
26e034f29f
@ -565,21 +565,74 @@ namespace NadekoBot.Modules.Administration
|
|||||||
var heap = await Task.Run(() => NadekoStats.Instance.Heap()).ConfigureAwait(false);
|
var heap = await Task.Run(() => NadekoStats.Instance.Heap()).ConfigureAwait(false);
|
||||||
await e.Channel.SendMessage($"`Heap Size:` {heap}").ConfigureAwait(false);
|
await e.Channel.SendMessage($"`Heap Size:` {heap}").ConfigureAwait(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
cgb.CreateCommand(Prefix + "prune")
|
cgb.CreateCommand(Prefix + "prune")
|
||||||
.Parameter("num", ParameterType.Required)
|
.Alias(".clr")
|
||||||
.Description("Prunes a number of messages from the current channel.\n**Usage**: .prune 5")
|
.Description("Prunes a number of messages from the current channel.\n**Usage**: .prune 5")
|
||||||
.AddCheck(SimpleCheckers.ManageMessages())
|
.Parameter("user_or_num", ParameterType.Optional)
|
||||||
|
.Parameter("num", ParameterType.Required)
|
||||||
.Do(async e =>
|
.Do(async e =>
|
||||||
{
|
{
|
||||||
int val;
|
if (string.IsNullOrWhiteSpace("user_or_num")) // if nothing is set, clear nadeko's messages, no permissions required
|
||||||
if (string.IsNullOrWhiteSpace(e.GetArg("num")) || !int.TryParse(e.GetArg("num"), out val) || val < 0)
|
{
|
||||||
return;
|
await Task.Run(async () =>
|
||||||
|
{
|
||||||
|
var msgs = (await e.Channel.DownloadMessages(100).ConfigureAwait(false)).Where(m => m.User.Id == e.Server.CurrentUser.Id);
|
||||||
|
foreach (var m in msgs)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await m.Delete().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
await Task.Delay(100).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}).ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!e.User.ServerPermissions.ManageMessages)
|
||||||
|
return;
|
||||||
|
else if (e.Server.CurrentUser.ServerPermissions.ManageMessages)
|
||||||
|
{
|
||||||
|
await e.Channel.SendMessage("💢I don't have the permission to manage messages.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int val;
|
||||||
|
if (int.TryParse(e.GetArg("user_or_num"), out val)) // if num is set in the first argument,
|
||||||
|
//delete that number of messages.
|
||||||
|
{
|
||||||
|
if (val <= 0)
|
||||||
|
return;
|
||||||
|
val++;
|
||||||
foreach (var msg in await e.Channel.DownloadMessages(val).ConfigureAwait(false))
|
foreach (var msg in await e.Channel.DownloadMessages(val).ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
await msg.Delete().ConfigureAwait(false);
|
await msg.Delete().ConfigureAwait(false);
|
||||||
await Task.Delay(100).ConfigureAwait(false);
|
await Task.Delay(100).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
//else if first argument is user
|
||||||
|
var usr = e.Server.FindUsers(e.GetArg("user_or_num")).FirstOrDefault();
|
||||||
|
if (usr == null)
|
||||||
|
return;
|
||||||
|
val = 100;
|
||||||
|
int.TryParse("num", out val);
|
||||||
|
if (val <= 0)
|
||||||
|
return;
|
||||||
|
await Task.Run(async () =>
|
||||||
|
{
|
||||||
|
var msgs = (await e.Channel.DownloadMessages(100).ConfigureAwait(false)).Where(m => m.User.Id == usr.Id).Take(val);
|
||||||
|
foreach (var m in msgs)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await m.Delete().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
await Task.Delay(100).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}).ConfigureAwait(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
cgb.CreateCommand(Prefix + "die")
|
cgb.CreateCommand(Prefix + "die")
|
||||||
@ -593,34 +646,6 @@ namespace NadekoBot.Modules.Administration
|
|||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
cgb.CreateCommand(Prefix + "clr")
|
|
||||||
.Description("Clears some of Nadeko's messages from the current channel. If given a user, will clear the user's messages from the current channel. Second one requires Manage messages permission.\n**Usage**: .clr @X")
|
|
||||||
.Parameter("user", ParameterType.Unparsed)
|
|
||||||
.Do(async e =>
|
|
||||||
{
|
|
||||||
var usrId = NadekoBot.Client.CurrentUser.Id;
|
|
||||||
if (!string.IsNullOrWhiteSpace(e.GetArg("user")) && e.User.ServerPermissions.ManageMessages)
|
|
||||||
{
|
|
||||||
var usr = e.Server.FindUsers(e.GetArg("user")).FirstOrDefault();
|
|
||||||
if (usr != null)
|
|
||||||
usrId = usr.Id;
|
|
||||||
}
|
|
||||||
await Task.Run(async () =>
|
|
||||||
{
|
|
||||||
var msgs = (await e.Channel.DownloadMessages(100).ConfigureAwait(false)).Where(m => m.User.Id == usrId);
|
|
||||||
foreach (var m in msgs)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await m.Delete().ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
await Task.Delay(200).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}).ConfigureAwait(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
//cgb.CreateCommand(Prefix + "newnick")
|
//cgb.CreateCommand(Prefix + "newnick")
|
||||||
// .Alias(Prefix + "setnick")
|
// .Alias(Prefix + "setnick")
|
||||||
// .Description("Give the bot a new nickname. You need manage server permissions.")
|
// .Description("Give the bot a new nickname. You need manage server permissions.")
|
||||||
|
Loading…
Reference in New Issue
Block a user