added .masskick to complement massban and masskill
This commit is contained in:
parent
ca46786c5e
commit
8025b9f9fe
3 changed files with 197 additions and 157 deletions
src/EllieBot
|
@ -721,7 +721,6 @@ public partial class Administration
|
|||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
var toSend = CreateEmbed()
|
||||
|
@ -836,21 +835,38 @@ public partial class Administration
|
|||
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]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[UserPerm(GuildPerm.BanMembers)]
|
||||
[BotPerm(GuildPerm.BanMembers)]
|
||||
[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;
|
||||
|
||||
var missing = new List<string>();
|
||||
var banning = new HashSet<IUser>();
|
||||
var punishing = new HashSet<IUser>();
|
||||
|
||||
await ctx.Channel.TriggerTypingAsync();
|
||||
foreach (var userStr in userStrings)
|
||||
foreach (var userStr in users)
|
||||
{
|
||||
if (ulong.TryParse(userStr, out var userId))
|
||||
{
|
||||
|
@ -875,7 +891,7 @@ public partial class Administration
|
|||
if (user is IGuildUser gu && !await CheckRoleHierarchy(gu))
|
||||
return;
|
||||
|
||||
banning.Add(user);
|
||||
punishing.Add(user);
|
||||
}
|
||||
else
|
||||
missing.Add(userStr);
|
||||
|
@ -886,29 +902,44 @@ public partial class Administration
|
|||
missStr = "-";
|
||||
|
||||
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)
|
||||
.WithPendingColor();
|
||||
|
||||
var banningMessage = await Response().Embed(toSend).SendAsync();
|
||||
|
||||
var banPrune = await _service.GetBanPruneAsync(ctx.Guild.Id) ?? 7;
|
||||
foreach (var toBan in banning)
|
||||
|
||||
foreach (var toPunish in punishing)
|
||||
{
|
||||
if (type == PunishType.Kick)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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()
|
||||
.WithDescription(
|
||||
GetText(strs.mass_ban_completed(
|
||||
banning.Count())))
|
||||
punishing.Count())))
|
||||
.AddField(GetText(strs.invalid(missing.Count)),
|
||||
missStr)
|
||||
.WithOkColor()
|
||||
|
|
|
@ -1220,6 +1220,8 @@ crypto:
|
|||
- c
|
||||
massban:
|
||||
- massban
|
||||
masskick:
|
||||
- masskick
|
||||
masskill:
|
||||
- masskill
|
||||
reroadd:
|
||||
|
|
|
@ -3952,13 +3952,20 @@ stock:
|
|||
params:
|
||||
- query:
|
||||
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:
|
||||
desc: Bans multiple users at once. Specify a space separated list of IDs of users who you wish to ban.
|
||||
ex:
|
||||
- 123123123 3333333333 444444444
|
||||
params:
|
||||
- userStrings:
|
||||
desc: "The list of user IDs to ban, provided as a comma-separated string."
|
||||
- users:
|
||||
desc: "The list of user IDs to ban. Whitespace-separated string."
|
||||
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.
|
||||
ex:
|
||||
|
|
Loading…
Add table
Reference in a new issue