Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement massban in ModerationModule #39

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Zhongli.Bot/Modules/Moderation/ModerationModule.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Text;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
Expand Down Expand Up @@ -49,6 +50,45 @@ public async Task BanAsync(IUser user, uint deleteDays = 1, TimeSpan? length = n
else
await ReplyReprimandAsync(result, details);
}

[Command("massban")]
[Summary("Ban a list of users permanently from the current guild, and delete messages.")]
[RequireAuthorization(AuthorizationScope.Ban)]
public async Task MassBanAsync(uint deleteDays = 1, string? reason = null, params IUser[] users)
{
var sb = new StringBuilder();
var fail = new StringBuilder();
var fails = 0;

foreach (var u in users)
{
var details = await GetDetailsAsync(u, reason);
var result = await _moderation.TryBanAsync(deleteDays, null, details);

if (result is null)
{
fail.AppendLine($"Failed to ban {u.GetFullUsername()}");
fails += 1;
}

else
sb.AppendLine(u.GetFullUsername());
}

if (sb.Length is 0)
{
await _error.AssociateError(Context.Message, fail.ToString());

}
else
{
var embed = new EmbedBuilder()
.WithTitle($"Banned {users.Length - fails} user(s).")
.WithDescription(sb.ToString() + fail);

await ReplyAsync(embed: embed.Build());
}
}

[Command("kick")]
[Summary("Kick a user from the current guild.")]
Expand Down