2023-01-18 17:39:24 +03:00
|
|
|
using Boyfriend.Data;
|
2022-12-06 18:33:46 +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 UnmuteCommand : ICommand {
|
|
|
|
public string[] Aliases { get; } = { "unmute", "размут" };
|
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) {
|
2022-08-30 18:15:01 +03:00
|
|
|
if (!cmd.HasPermission(GuildPermission.ModerateMembers)) return;
|
2022-05-14 16:12:24 +03:00
|
|
|
|
2023-01-18 17:39:24 +03:00
|
|
|
var toUnmute = cmd.GetMember(args, 0);
|
2022-11-11 22:59:11 +03:00
|
|
|
if (toUnmute is null) return;
|
2022-08-30 18:15:01 +03:00
|
|
|
var reason = cmd.GetRemaining(args, 1, "UnmuteReason");
|
2022-11-11 22:59:11 +03:00
|
|
|
if (reason is not null && cmd.CanInteractWith(toUnmute, "Unmute"))
|
|
|
|
await UnmuteMemberAsync(cmd, toUnmute, reason);
|
2022-02-02 16:14:26 +03:00
|
|
|
}
|
|
|
|
|
2023-01-18 17:39:24 +03:00
|
|
|
private static async Task UnmuteMemberAsync(CommandProcessor cmd, SocketGuildUser toUnmute,
|
2022-02-02 16:14:26 +03:00
|
|
|
string reason) {
|
2023-01-18 17:39:24 +03:00
|
|
|
var isMuted = await Utils.UnmuteMemberAsync(GuildData.Get(cmd.Context.Guild), cmd.Context.User.ToString(),
|
|
|
|
toUnmute, reason);
|
|
|
|
|
|
|
|
if (!isMuted) {
|
|
|
|
cmd.Reply(Messages.MemberNotMuted, ReplyEmojis.Error);
|
|
|
|
return;
|
2022-01-18 20:38:15 +03:00
|
|
|
}
|
|
|
|
|
2023-01-18 17:39:24 +03:00
|
|
|
cmd.ConfigWriteScheduled = true;
|
|
|
|
|
2022-06-06 18:39:47 +03:00
|
|
|
var feedback = string.Format(Messages.FeedbackMemberUnmuted, toUnmute.Mention, Utils.Wrap(reason));
|
2022-12-06 18:33:46 +03:00
|
|
|
cmd.Reply(feedback, ReplyEmojis.Unmuted);
|
2022-08-30 18:15:01 +03:00
|
|
|
cmd.Audit(feedback);
|
2022-01-18 20:38:15 +03:00
|
|
|
}
|
2022-09-18 17:41:29 +03:00
|
|
|
}
|