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

70 lines
2.5 KiB
C#
Raw Normal View History

using Discord;
using Discord.Commands;
2022-05-14 16:12:24 +03:00
using Discord.WebSocket;
namespace Boyfriend.Commands;
public class UnmuteCommand : Command {
public override string[] Aliases { get; } = { "unmute", "размут" };
2022-05-14 16:12:24 +03:00
public override int ArgsLengthRequired => 2;
public override async Task Run(SocketCommandContext context, string[] args) {
var author = (SocketGuildUser)context.User;
2022-05-14 16:12:24 +03:00
var permissionCheckResponse = CommandHandler.HasPermission(ref author, GuildPermission.ModerateMembers);
if (permissionCheckResponse != "") {
Error(permissionCheckResponse, true);
return;
}
var toUnmute = Utils.ParseMember(context.Guild, args[0]);
if (toUnmute == null) {
Error(Messages.UserDoesntExist, false);
return;
}
var interactionCheckResponse = CommandHandler.CanInteract(ref author, ref toUnmute);
if (interactionCheckResponse != "") {
Error(interactionCheckResponse, true);
return;
}
var reason = Utils.JoinString(ref args, 1);
await UnmuteMember(context.Guild, author, toUnmute, reason);
2022-02-02 16:14:26 +03:00
}
2022-05-14 16:12:24 +03:00
public static async Task UnmuteMember(SocketGuild guild, SocketGuildUser author, SocketGuildUser toUnmute,
2022-02-02 16:14:26 +03:00
string reason) {
2022-05-14 16:12:24 +03:00
var requestOptions = Utils.GetRequestOptions($"({author}) {reason}");
var role = Utils.GetMuteRole(ref guild);
2022-02-02 16:14:26 +03:00
2022-01-30 11:43:15 +03:00
if (role != null) {
2022-05-14 16:12:24 +03:00
var rolesRemoved = Boyfriend.GetRemovedRoles(guild.Id);
2022-05-14 16:12:24 +03:00
if (rolesRemoved.ContainsKey(toUnmute.Id)) {
await toUnmute.AddRolesAsync(rolesRemoved[toUnmute.Id]);
rolesRemoved.Remove(toUnmute.Id);
2022-05-14 16:12:24 +03:00
CommandHandler.ConfigWriteScheduled = true;
}
if (toUnmute.Roles.Contains(role)) { await toUnmute.RemoveRoleAsync(role, requestOptions); } else {
2022-05-14 16:12:24 +03:00
Error(Messages.MemberNotMuted, false);
return;
2022-01-30 11:43:15 +03:00
}
} else {
2022-05-14 16:12:24 +03:00
if (toUnmute.TimedOutUntil == null || toUnmute.TimedOutUntil.Value.ToUnixTimeMilliseconds() <
DateTimeOffset.Now.ToUnixTimeMilliseconds()) {
Error(Messages.MemberNotMuted, false);
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));
2022-05-14 16:12:24 +03:00
Success(feedback, author.Mention, false, false);
await Utils.SendFeedback(feedback, guild.Id, author.Mention, true);
}
2022-01-30 11:43:15 +03:00
}