public async Task <MuteResult> TryMuteUserAsync(SocketGuildUser moderator, SocketGuildUser user, string reason = null, TimeSpan?expiry = null) { try { if (user.TimedOutUntil is not null && user.TimedOutUntil.Value.UtcDateTime > DateTime.UtcNow) { return(MuteResult.FromError("The user is already under a timeout.", user.Id)); } if (expiry is null || expiry > TimeSpan.FromDays(28)) { expiry = TimeSpan.FromDays(28); } await user.SetTimeOutAsync(expiry.Value, new RequestOptions { AuditLogReason = reason }); var action = new ModerationAction(user.Id, moderator.Id, user.Guild.Id, merlin.classes.ActionType.Mute, expiry, reason); AddAction(action); return(MuteResult.FromSuccess(action)); } catch (Exception e) { return(MuteResult.FromError($"There was an exception while adding a timeout to the user. ({e.Message})", user.Id)); } }
public async Task <MuteResult> TryUnmuteUserAsync(SocketGuildUser user) { try { if (user.TimedOutUntil is null) { return(MuteResult.FromError("The user is not under a timeout.", user.Id)); } await user.RemoveTimeOutAsync(); RemoveAction(_actions.First(x => x.Type == classes.ActionType.Mute && x.UserId == user.Id && x.GuildId == user.Guild.Id)); return(MuteResult.FromSuccess("", user.Id)); } catch (Exception e) { return(MuteResult.FromError($"There was an exception while removing the user's timeout. ({e.Message})", user.Id)); } }