1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-01-31 17:19:00 +03:00
Octobot/Boyfriend/Commands/BanCommand.cs

41 lines
1.6 KiB
C#
Raw Normal View History

using Discord;
2022-05-14 16:12:24 +03:00
using Discord.WebSocket;
namespace Boyfriend.Commands;
public sealed class BanCommand : ICommand {
public string[] Aliases { get; } = { "ban", "бан" };
2022-05-14 16:12:24 +03:00
public async Task RunAsync(CommandProcessor cmd, string[] args, string[] cleanArgs) {
var toBan = cmd.GetUser(args, cleanArgs, 0, "ToBan");
if (toBan == null || !cmd.HasPermission(GuildPermission.BanMembers)) return;
2022-05-14 16:12:24 +03:00
var memberToBan = cmd.GetMember(toBan, null);
if (memberToBan != null && !cmd.CanInteractWith(memberToBan, "Ban")) return;
var duration = CommandProcessor.GetTimeSpan(args, 1);
var reason = cmd.GetRemaining(args, duration.TotalSeconds < 1 ? 1 : 2, "BanReason");
if (reason == null) return;
2022-05-14 16:12:24 +03:00
await BanUser(cmd, toBan, duration, reason);
2022-05-14 16:12:24 +03:00
}
public static async Task BanUser(CommandProcessor cmd, SocketUser toBan, TimeSpan duration, string reason) {
var author = cmd.Context.User;
var guild = cmd.Context.Guild;
await Utils.SendDirectMessage(toBan,
string.Format(Messages.YouWereBanned, author.Mention, guild.Name, Utils.Wrap(reason)));
2022-02-02 16:14:26 +03:00
var guildBanMessage = $"({author}) {reason}";
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,
Utils.GetHumanizedTimeOffset(duration), Utils.Wrap(reason));
cmd.Reply(feedback, ":hammer: ");
cmd.Audit(feedback);
2022-02-02 16:14:26 +03:00
if (duration.TotalSeconds > 0)
await Task.FromResult(Utils.DelayedUnbanAsync(cmd, toBan.Id, Messages.PunishmentExpired, duration));
}
}