This repository has been archived on 2024-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
OctobotStealth/Boyfriend/Commands/UnmuteCommand.cs

49 lines
1.9 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 UnmuteCommand : ICommand {
public string[] Aliases { get; } = { "unmute", "размут" };
2022-05-14 16:12:24 +03:00
public async Task RunAsync(CommandProcessor cmd, string[] args, string[] cleanArgs) {
if (!cmd.HasPermission(GuildPermission.ModerateMembers)) return;
2022-05-14 16:12:24 +03:00
var toUnmute = cmd.GetMember(args, cleanArgs, 0, "ToUnmute");
if (toUnmute is null) return;
var reason = cmd.GetRemaining(args, 1, "UnmuteReason");
if (reason is not null && cmd.CanInteractWith(toUnmute, "Unmute"))
await UnmuteMemberAsync(cmd, toUnmute, reason);
2022-02-02 16:14:26 +03:00
}
public static async Task UnmuteMemberAsync(CommandProcessor cmd, SocketGuildUser toUnmute,
2022-02-02 16:14:26 +03:00
string reason) {
var requestOptions = Utils.GetRequestOptions($"({cmd.Context.User}) {reason}");
var role = Utils.GetMuteRole(cmd.Context.Guild);
2022-02-02 16:14:26 +03:00
if (role is not null && toUnmute.Roles.Contains(role)) {
var rolesRemoved = Boyfriend.GetRemovedRoles(cmd.Context.Guild.Id);
if (rolesRemoved.TryGetValue(toUnmute.Id, out var unmutedRemovedRoles)) {
await toUnmute.AddRolesAsync(unmutedRemovedRoles);
rolesRemoved.Remove(toUnmute.Id);
cmd.ConfigWriteScheduled = true;
}
await toUnmute.RemoveRoleAsync(role, requestOptions);
} else {
if (toUnmute.TimedOutUntil is null || toUnmute.TimedOutUntil.Value.ToUnixTimeSeconds() <
DateTimeOffset.Now.ToUnixTimeSeconds()) {
cmd.Reply(Messages.MemberNotMuted, ReplyEmojis.Error);
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();
}
var feedback = string.Format(Messages.FeedbackMemberUnmuted, toUnmute.Mention, Utils.Wrap(reason));
cmd.Reply(feedback, ReplyEmojis.Unmuted);
cmd.Audit(feedback);
}
}