NadekoBot/NadekoBot.Core/Modules/Administration/PruneCommands.cs

65 lines
2.3 KiB
C#
Raw Normal View History

2017-06-16 22:17:07 +00:00
using Discord;
using Discord.Commands;
using NadekoBot.Extensions;
using System;
using System.Threading.Tasks;
2017-07-17 19:42:36 +00:00
using NadekoBot.Common.Attributes;
using NadekoBot.Modules.Administration.Services;
2017-06-16 22:17:07 +00:00
namespace NadekoBot.Modules.Administration
{
public partial class Administration
{
[Group]
2017-07-15 16:34:34 +00:00
public class PruneCommands : NadekoSubmodule<PruneService>
2017-06-16 22:17:07 +00:00
{
private readonly TimeSpan twoWeeks = TimeSpan.FromDays(14);
//delets her own messages, no perm required
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Prune()
{
var user = await Context.Guild.GetCurrentUserAsync().ConfigureAwait(false);
2017-07-15 16:34:34 +00:00
await _service.PruneWhere((ITextChannel)Context.Channel, 100, (x) => x.Author.Id == user.Id).ConfigureAwait(false);
2017-06-16 22:17:07 +00:00
Context.Message.DeleteAfter(3);
}
// prune x
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[RequireUserPermission(ChannelPermission.ManageMessages)]
[RequireBotPermission(GuildPermission.ManageMessages)]
[Priority(1)]
2017-06-16 22:17:07 +00:00
public async Task Prune(int count)
{
count++;
2017-06-16 22:17:07 +00:00
if (count < 1)
return;
if (count > 1000)
count = 1000;
2017-07-15 16:34:34 +00:00
await _service.PruneWhere((ITextChannel)Context.Channel, count, x => true).ConfigureAwait(false);
2017-06-16 22:17:07 +00:00
}
//prune @user [x]
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[RequireUserPermission(ChannelPermission.ManageMessages)]
[RequireBotPermission(GuildPermission.ManageMessages)]
[Priority(0)]
2017-06-16 22:17:07 +00:00
public async Task Prune(IGuildUser user, int count = 100)
{
if (user.Id == Context.User.Id)
count++;
2017-06-16 22:17:07 +00:00
if (count < 1)
return;
if (count > 1000)
count = 1000;
2017-07-15 16:34:34 +00:00
await _service.PruneWhere((ITextChannel)Context.Channel, count, m => m.Author.Id == user.Id && DateTime.UtcNow - m.CreatedAt < twoWeeks);
2017-06-16 22:17:07 +00:00
}
}
}
}