public async Task Mute(IGuildUser userToMute, [Remainder] string reason = "No reason.") { var guild = GuildRepository.FetchGuild(Context.Guild.Id); var mutedRole = Context.Guild.GetRole(guild.MutedRoleId); if (mutedRole == null) { throw new Exception($"You may not mute users if the muted role is not valid.\nPlease use the " + $"`{guild.Prefix}SetMutedRole` command to change that."); } if (ModuleMethods.IsMod(Context, userToMute)) { throw new Exception("You cannot mute another mod!"); } await ModuleMethods.InformSubjectAsync(Context.User, "Mute", userToMute, reason); await userToMute.AddRoleAsync(mutedRole); MuteRepository.AddMute(userToMute.Id, Context.Guild.Id, Config.DEFAULT_MUTE_TIME); await Logger.ModLog(Context, "Mute", new Color(255, 114, 14), reason, userToMute, $"\n**Length:** {Config.DEFAULT_MUTE_TIME.TotalHours} hours"); await ReplyAsync($"{Context.User.Mention} has successfully muted {userToMute.Mention}!"); }
public async Task CustomMute(double hours, IGuildUser userToMute, [Remainder] string reason = "No reason.") { if (hours > 168) { throw new Exception("You may not mute a user for more than a week."); } if (hours < 1) { throw new Exception("You may not mute a user for less than 1 hour."); } string time = "hours"; if (hours == 1) { time = "hour"; } var guild = GuildRepository.FetchGuild(Context.Guild.Id); var mutedRole = Context.Guild.GetRole(guild.MutedRoleId); if (mutedRole == null) { throw new Exception($"You may not mute users if the muted role is not valid.\nPlease use the " + $"{guild.Prefix}SetMutedRole command to change that."); } if (ModuleMethods.IsMod(Context, userToMute)) { throw new Exception("You cannot mute another mod!"); } await ModuleMethods.InformSubjectAsync(Context.User, "Mute", userToMute, reason); await userToMute.AddRoleAsync(mutedRole); MuteRepository.AddMute(userToMute.Id, Context.Guild.Id, TimeSpan.FromHours(hours)); await Logger.ModLog(Context, "Mute", new Color(255, 114, 14), reason, userToMute, $"\n**Length:** {hours} {time}"); await ReplyAsync($"{Context.User.Mention} has successfully muted {userToMute.Mention} for {hours} {time}!"); }