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 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
|
|
|
|
|
2022-09-18 17:41:29 +03:00
|
|
|
|
var toUnmute = cmd.GetMember(args, cleanArgs, 0, "ToUnmute");
|
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
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 17:41:29 +03:00
|
|
|
|
public static async Task UnmuteMemberAsync(CommandProcessor cmd, SocketGuildUser toUnmute,
|
2022-02-02 16:14:26 +03:00
|
|
|
|
string reason) {
|
2022-08-30 18:15:01 +03:00
|
|
|
|
var requestOptions = Utils.GetRequestOptions($"({cmd.Context.User}) {reason}");
|
|
|
|
|
var role = Utils.GetMuteRole(cmd.Context.Guild);
|
2022-02-02 16:14:26 +03:00
|
|
|
|
|
2022-11-11 22:59:11 +03:00
|
|
|
|
if (role is not null && toUnmute.Roles.Contains(role)) {
|
2022-08-30 18:15:01 +03:00
|
|
|
|
var rolesRemoved = Boyfriend.GetRemovedRoles(cmd.Context.Guild.Id);
|
2022-01-18 20:38:15 +03:00
|
|
|
|
|
2022-10-21 09:09:56 +03:00
|
|
|
|
if (rolesRemoved.TryGetValue(toUnmute.Id, out var unmutedRemovedRoles)) {
|
|
|
|
|
await toUnmute.AddRolesAsync(unmutedRemovedRoles);
|
2022-01-18 20:38:15 +03:00
|
|
|
|
rolesRemoved.Remove(toUnmute.Id);
|
2022-08-30 18:15:01 +03:00
|
|
|
|
cmd.ConfigWriteScheduled = true;
|
2022-01-18 20:38:15 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-15 16:32:54 +03:00
|
|
|
|
await toUnmute.RemoveRoleAsync(role, requestOptions);
|
2022-08-30 18:15:01 +03:00
|
|
|
|
} else {
|
2022-11-11 22:59:11 +03:00
|
|
|
|
if (toUnmute.TimedOutUntil is null || toUnmute.TimedOutUntil.Value.ToUnixTimeSeconds() <
|
2022-09-18 17:41:29 +03:00
|
|
|
|
DateTimeOffset.Now.ToUnixTimeSeconds()) {
|
2022-08-30 18:15:01 +03:00
|
|
|
|
cmd.Reply(Messages.MemberNotMuted, ":x: ");
|
2022-05-14 16:12:24 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-02-02 16:14:26 +03:00
|
|
|
|
|
2022-01-30 11:43:15 +03:00
|
|
|
|
await toUnmute.RemoveTimeOutAsync();
|
2022-01-18 20:38:15 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 18:39:47 +03:00
|
|
|
|
var feedback = string.Format(Messages.FeedbackMemberUnmuted, toUnmute.Mention, Utils.Wrap(reason));
|
2022-08-30 18:15:01 +03:00
|
|
|
|
cmd.Reply(feedback, ":loud_sound: ");
|
|
|
|
|
cmd.Audit(feedback);
|
2022-01-18 20:38:15 +03:00
|
|
|
|
}
|
2022-09-18 17:41:29 +03:00
|
|
|
|
}
|