2022-01-18 20:38:15 +03:00
|
|
|
|
using Discord;
|
2022-05-14 16:12:24 +03:00
|
|
|
|
using Discord.WebSocket;
|
2022-01-18 20:38:15 +03:00
|
|
|
|
|
|
|
|
|
namespace Boyfriend.Commands;
|
|
|
|
|
|
2022-09-18 17:41:29 +03:00
|
|
|
|
public sealed class BanCommand : ICommand {
|
|
|
|
|
public string[] Aliases { get; } = { "ban", "бан" };
|
2022-05-14 16:12:24 +03:00
|
|
|
|
|
2022-09-18 17:41:29 +03:00
|
|
|
|
public async Task RunAsync(CommandProcessor cmd, string[] args, string[] cleanArgs) {
|
|
|
|
|
var toBan = cmd.GetUser(args, cleanArgs, 0, "ToBan");
|
2022-11-11 22:59:11 +03:00
|
|
|
|
if (toBan is null || !cmd.HasPermission(GuildPermission.BanMembers)) return;
|
2022-05-14 16:12:24 +03:00
|
|
|
|
|
2022-11-12 09:02:44 +03:00
|
|
|
|
var memberToBan = cmd.GetMember(toBan);
|
2022-11-11 22:59:11 +03:00
|
|
|
|
if (memberToBan is not null && !cmd.CanInteractWith(memberToBan, "Ban")) return;
|
2022-06-06 18:39:47 +03:00
|
|
|
|
|
2022-08-30 18:15:01 +03:00
|
|
|
|
var duration = CommandProcessor.GetTimeSpan(args, 1);
|
|
|
|
|
var reason = cmd.GetRemaining(args, duration.TotalSeconds < 1 ? 1 : 2, "BanReason");
|
2022-11-11 22:59:11 +03:00
|
|
|
|
if (reason is not null) await BanUserAsync(cmd, toBan, duration, reason);
|
2022-05-14 16:12:24 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-11 22:59:11 +03:00
|
|
|
|
private static async Task BanUserAsync(CommandProcessor cmd, SocketUser toBan, TimeSpan duration, string reason) {
|
2022-08-30 18:15:01 +03:00
|
|
|
|
var author = cmd.Context.User;
|
|
|
|
|
var guild = cmd.Context.Guild;
|
2022-02-21 20:08:55 +03:00
|
|
|
|
await Utils.SendDirectMessage(toBan,
|
2022-06-06 18:39:47 +03:00
|
|
|
|
string.Format(Messages.YouWereBanned, author.Mention, guild.Name, Utils.Wrap(reason)));
|
2022-02-02 16:14:26 +03:00
|
|
|
|
|
2022-08-30 18:15:01 +03:00
|
|
|
|
var guildBanMessage = $"({author}) {reason}";
|
2022-01-18 20:38:15 +03:00
|
|
|
|
await guild.AddBanAsync(toBan, 0, guildBanMessage);
|
2022-02-02 16:14:26 +03:00
|
|
|
|
|
2022-05-14 16:12:24 +03:00
|
|
|
|
var feedback = string.Format(Messages.FeedbackUserBanned, toBan.Mention,
|
2022-08-30 18:15:01 +03:00
|
|
|
|
Utils.GetHumanizedTimeOffset(duration), Utils.Wrap(reason));
|
|
|
|
|
cmd.Reply(feedback, ":hammer: ");
|
|
|
|
|
cmd.Audit(feedback);
|
2022-02-02 16:14:26 +03:00
|
|
|
|
|
2022-09-18 17:41:29 +03:00
|
|
|
|
if (duration.TotalSeconds > 0)
|
|
|
|
|
await Task.FromResult(Utils.DelayedUnbanAsync(cmd, toBan.Id, Messages.PunishmentExpired, duration));
|
2022-01-18 20:38:15 +03:00
|
|
|
|
}
|
2022-09-18 17:41:29 +03:00
|
|
|
|
}
|