added .masskick to complement massban and masskill

This commit is contained in:
Toastie 2025-03-18 13:44:23 +13:00
parent ca46786c5e
commit 8025b9f9fe
Signed by: toastie_t0ast
GPG key ID: 74226CF45EEE5AAF
3 changed files with 197 additions and 157 deletions
src/EllieBot
Modules/Administration/UserPunish
strings

View file

@ -721,7 +721,6 @@ public partial class Administration
} }
catch catch
{ {
} }
var toSend = CreateEmbed() var toSend = CreateEmbed()
@ -836,21 +835,38 @@ public partial class Administration
await Response().Embed(toSend).SendAsync(); await Response().Embed(toSend).SendAsync();
} }
public enum PunishType
{
Kick,
Ban
}
[Cmd]
[RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.KickMembers)]
[BotPerm(GuildPerm.KickMembers)]
[Ratelimit(30)]
public async Task MassKick(params string[] users)
=> await MassPunish(PunishType.Ban, users);
[Cmd] [Cmd]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.BanMembers)] [UserPerm(GuildPerm.BanMembers)]
[BotPerm(GuildPerm.BanMembers)] [BotPerm(GuildPerm.BanMembers)]
[Ratelimit(30)] [Ratelimit(30)]
public async Task MassBan(params string[] userStrings) public async Task MassBan(params string[] users)
=> await MassPunish(PunishType.Ban, users);
private async Task MassPunish(PunishType type, params string[] users)
{ {
if (userStrings.Length == 0) if (users.Length == 0)
return; return;
var missing = new List<string>(); var missing = new List<string>();
var banning = new HashSet<IUser>(); var punishing = new HashSet<IUser>();
await ctx.Channel.TriggerTypingAsync(); await ctx.Channel.TriggerTypingAsync();
foreach (var userStr in userStrings) foreach (var userStr in users)
{ {
if (ulong.TryParse(userStr, out var userId)) if (ulong.TryParse(userStr, out var userId))
{ {
@ -875,7 +891,7 @@ public partial class Administration
if (user is IGuildUser gu && !await CheckRoleHierarchy(gu)) if (user is IGuildUser gu && !await CheckRoleHierarchy(gu))
return; return;
banning.Add(user); punishing.Add(user);
} }
else else
missing.Add(userStr); missing.Add(userStr);
@ -886,29 +902,44 @@ public partial class Administration
missStr = "-"; missStr = "-";
var toSend = CreateEmbed() var toSend = CreateEmbed()
.WithDescription(GetText(strs.mass_ban_in_progress(banning.Count))) .WithDescription(GetText(strs.mass_ban_in_progress(punishing.Count)))
.AddField(GetText(strs.invalid(missing.Count)), missStr) .AddField(GetText(strs.invalid(missing.Count)), missStr)
.WithPendingColor(); .WithPendingColor();
var banningMessage = await Response().Embed(toSend).SendAsync(); var banningMessage = await Response().Embed(toSend).SendAsync();
var banPrune = await _service.GetBanPruneAsync(ctx.Guild.Id) ?? 7; var banPrune = await _service.GetBanPruneAsync(ctx.Guild.Id) ?? 7;
foreach (var toBan in banning)
foreach (var toPunish in punishing)
{
if (type == PunishType.Kick)
{ {
try try
{ {
await ctx.Guild.AddBanAsync(toBan.Id, banPrune, $"{ctx.User} | Massban"); if (toPunish is IGuildUser u)
await u.KickAsync($"{ctx.User} | Masskick");
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Warning(ex, "Error banning {User} user in {GuildId} server", toBan.Id, ctx.Guild.Id); Log.Warning(ex, "Error kicking {User} user in {GuildId} server", toPunish.Id, ctx.Guild.Id);
}
}
else
{
try
{
await ctx.Guild.AddBanAsync(toPunish.Id, banPrune, $"{ctx.User} | Massban");
}
catch (Exception ex)
{
Log.Warning(ex, "Error banning {User} user in {GuildId} server", toPunish.Id, ctx.Guild.Id);
}
} }
} }
await banningMessage.ModifyAsync(x => x.Embed = CreateEmbed() await banningMessage.ModifyAsync(x => x.Embed = CreateEmbed()
.WithDescription( .WithDescription(
GetText(strs.mass_ban_completed( GetText(strs.mass_ban_completed(
banning.Count()))) punishing.Count())))
.AddField(GetText(strs.invalid(missing.Count)), .AddField(GetText(strs.invalid(missing.Count)),
missStr) missStr)
.WithOkColor() .WithOkColor()

View file

@ -1220,6 +1220,8 @@ crypto:
- c - c
massban: massban:
- massban - massban
masskick:
- masskick
masskill: masskill:
- masskill - masskill
reroadd: reroadd:

View file

@ -3952,13 +3952,20 @@ stock:
params: params:
- query: - query:
desc: "The ticker symbol or company name used to retrieve the stock's information." desc: "The ticker symbol or company name used to retrieve the stock's information."
masskick:
desc: Kicks multiple users at once. Specify a space separated list of IDs of users who you wish to kick.
ex:
- 123123123 3333333333 444444444
params:
- users:
desc: "The list of user IDs to kick. Whitespace-separated string."
massban: massban:
desc: Bans multiple users at once. Specify a space separated list of IDs of users who you wish to ban. desc: Bans multiple users at once. Specify a space separated list of IDs of users who you wish to ban.
ex: ex:
- 123123123 3333333333 444444444 - 123123123 3333333333 444444444
params: params:
- userStrings: - users:
desc: "The list of user IDs to ban, provided as a comma-separated string." desc: "The list of user IDs to ban. Whitespace-separated string."
masskill: masskill:
desc: Specify a new-line separated list of `userid reason`. You can use Username#discrim instead of UserId. Specified users will be banned from the current server, blacklisted from the bot, and have all of their currency taken away. desc: Specify a new-line separated list of `userid reason`. You can use Username#discrim instead of UserId. Specified users will be banned from the current server, blacklisted from the bot, and have all of their currency taken away.
ex: ex: