public async Task TempMuteUser([RequireHierarchy] UserRef userRef, TimeSpan time, [Remainder] string reason) { if (time.TotalMinutes < 1) { await ReplyAsync("Can't temp-mute for less than a minute"); return; } ModerationSettings settings = Context.Guild.LoadFromFile <ModerationSettings>(); if (!(Context.Message.Author as IGuildUser).HasAdmin()) { if (settings?.maxTempAction != null && time > settings.maxTempAction) { await ReplyAsync("You are not allowed to punish for that long"); return; } } if (settings == null || settings.mutedRole == 0 || Context.Guild.GetRole(settings.mutedRole) == null) { await ReplyAsync("Muted role is null or invalid"); return; } TempActionList actions = Context.Guild.LoadFromFile <TempActionList>(true); TempAct oldAct = actions.tempMutes.FirstOrDefault(tempMute => tempMute.User == userRef.ID); if (oldAct != null) { if (!(Context.Message.Author as IGuildUser).HasAdmin() && (oldAct.Length - (DateTime.UtcNow - oldAct.DateBanned)) >= time) { await ReplyAsync($"{Context.User.Mention} please contact your admin(s) in order to shorten length of a punishment"); return; } string text = $"{userRef.Name()} is already temp-muted for {oldAct.Length.LimitedHumanize()} ({(oldAct.Length - (DateTime.UtcNow - oldAct.DateBanned)).LimitedHumanize()} left), are you sure you want to change the length?"; var request = new ConfirmationBuilder() .WithContent(new PageBuilder().WithText(text)) .Build(); var result = await Interactivity.SendConfirmationAsync(request, Context.Channel, TimeSpan.FromMinutes(2)); if (result.Value) { actions.tempMutes.Remove(oldAct); actions.SaveToFile(); } else { await ReplyAsync("Command canceled"); return; } } await userRef.TempMute(time, reason, Context, settings, actions); Context.Message.DeleteOrRespond($"Temporarily muted {userRef.Mention()} for {time.LimitedHumanize(3)} because of {reason}", Context.Guild); }
public async Task Ban([RequireHierarchy] UserRef userRef, [Remainder] string reason) { if (reason.Split(' ').First().ToTime() != null) { var query = "Are you sure you don't mean to use !tempban?"; var request = new ConfirmationBuilder() .WithContent(new PageBuilder().WithText(query)) .Build(); var result = await Interactivity.SendConfirmationAsync(request, Context.Channel, TimeSpan.FromMinutes(1)); if (result.Value) { await ReplyAsync("Command Canceled"); return; } } TempActionList actions = Context.Guild.LoadFromFile <TempActionList>(false); if (actions?.tempBans?.Any(tempBan => tempBan.User == userRef.ID) ?? false) { var query = "User is already tempbanned, are you sure you want to ban?"; var request = new ConfirmationBuilder() .WithContent(new PageBuilder().WithText(query)) .Build(); var result = await Interactivity.SendConfirmationAsync(request, Context.Channel, TimeSpan.FromMinutes(2)); if (result.Value) { await ReplyAsync("Command Canceled"); return; } actions.tempBans.Remove(actions.tempBans.First(tempban => tempban.User == userRef.ID)); } else if ((await Context.Guild.GetBansAsync()).Any(ban => ban.User.Id == userRef.ID)) { await ReplyAsync("User has already been banned permanently"); return; } userRef.User?.TryNotify($"You have been perm banned in the {Context.Guild.Name} discord for {reason}"); await Context.Guild.AddBanAsync(userRef.ID, reason : reason); DiscordLogging.LogTempAct(Context.Guild, Context.Message.Author, userRef, "Bann", reason, Context.Message.GetJumpUrl(), TimeSpan.Zero); Context.Message.DeleteOrRespond($"{userRef.Name(true)} has been banned for {reason}", Context.Guild); }