diff --git a/Content.Server/Administration/Commands/DepartmentBanCommand.cs b/Content.Server/Administration/Commands/DepartmentBanCommand.cs new file mode 100644 index 0000000000..37eb034e1d --- /dev/null +++ b/Content.Server/Administration/Commands/DepartmentBanCommand.cs @@ -0,0 +1,85 @@ +using Content.Server.Administration.Managers; +using Content.Shared.Administration; +using Content.Shared.Roles; +using Robust.Shared.Console; +using Robust.Shared.Prototypes; + +namespace Content.Server.Administration.Commands; + +[AdminCommand(AdminFlags.Ban)] +public sealed class DepartmentBanCommand : IConsoleCommand +{ + public string Command => "departmentban"; + public string Description => Loc.GetString("cmd-departmentban-desc"); + public string Help => Loc.GetString("cmd-departmentban-help"); + + public async void Execute(IConsoleShell shell, string argStr, string[] args) + { + string target; + string department; + string reason; + uint minutes; + + switch (args.Length) + { + case 3: + target = args[0]; + department = args[1]; + reason = args[2]; + minutes = 0; + break; + case 4: + target = args[0]; + department = args[1]; + reason = args[2]; + + if (!uint.TryParse(args[3], out minutes)) + { + shell.WriteError(Loc.GetString("cmd-roleban-minutes-parse", ("time", args[3]), ("help", Help))); + return; + } + + break; + default: + shell.WriteError(Loc.GetString("cmd-roleban-arg-count")); + shell.WriteLine(Help); + return; + } + + var protoManager = IoCManager.Resolve(); + + if (!protoManager.TryIndex(department, out var departmentProto)) + { + return; + } + + var banManager = IoCManager.Resolve(); + + foreach (var job in departmentProto.Roles) + { + banManager.CreateJobBan(shell, target, job, reason, minutes); + } + } + + public CompletionResult GetCompletion(IConsoleShell shell, string[] args) + { + var durOpts = new CompletionOption[] + { + new("0", Loc.GetString("cmd-roleban-hint-duration-1")), + new("1440", Loc.GetString("cmd-roleban-hint-duration-2")), + new("10080", Loc.GetString("cmd-roleban-hint-duration-3")), + }; + + return args.Length switch + { + 1 => CompletionResult.FromHintOptions(CompletionHelper.SessionNames(), + Loc.GetString("cmd-roleban-hint-1")), + 2 => CompletionResult.FromHintOptions(CompletionHelper.PrototypeIDs(), + Loc.GetString("cmd-roleban-hint-2")), + 3 => CompletionResult.FromHint(Loc.GetString("cmd-roleban-hint-3")), + 4 => CompletionResult.FromHintOptions(durOpts, Loc.GetString("cmd-roleban-hint-4")), + _ => CompletionResult.Empty + }; + } + +} diff --git a/Content.Server/Administration/Commands/RoleBanCommand.cs b/Content.Server/Administration/Commands/RoleBanCommand.cs index 7f0ec66238..c8b7931861 100644 --- a/Content.Server/Administration/Commands/RoleBanCommand.cs +++ b/Content.Server/Administration/Commands/RoleBanCommand.cs @@ -38,13 +38,13 @@ public sealed class RoleBanCommand : IConsoleCommand if (!uint.TryParse(args[3], out minutes)) { - shell.WriteLine($"{args[3]} is not a valid amount of minutes.\n{Help}"); + shell.WriteError(Loc.GetString("cmd-roleban-minutes-parse", ("time", args[3]), ("help", Help))); return; } break; default: - shell.WriteLine($"Invalid amount of arguments."); + shell.WriteError(Loc.GetString("cmd-roleban-arg-count")); shell.WriteLine(Help); return; } diff --git a/Content.Server/Administration/Managers/RoleBanManager.cs b/Content.Server/Administration/Managers/RoleBanManager.cs index ae150979a6..57fe253e0c 100644 --- a/Content.Server/Administration/Managers/RoleBanManager.cs +++ b/Content.Server/Administration/Managers/RoleBanManager.cs @@ -102,7 +102,7 @@ public sealed class RoleBanManager { if (!_prototypeManager.TryIndex(job, out JobPrototype? _)) { - shell.WriteLine($"Job {job} does not exist."); + shell.WriteError(Loc.GetString("cmd-roleban-job-parse", ("job", job))); return; } @@ -127,7 +127,7 @@ public sealed class RoleBanManager var located = await _playerLocator.LookupIdByNameOrIdAsync(target); if (located == null) { - shell.WriteError("Unable to find a player with that name."); + shell.WriteError(Loc.GetString("cmd-roleban-name-parse")); return; } @@ -167,17 +167,12 @@ public sealed class RoleBanManager if (!await AddRoleBan(banDef)) { - shell.WriteLine($"{target} already has a role ban for {role}"); + shell.WriteLine(Loc.GetString("cmd-roleban-existing", ("target", target), ("role", role))); return; } - var response = new StringBuilder($"Role banned {target} with reason \"{reason}\""); - - response.Append(expires == null ? - " permanently." - : $" until {expires}"); - - shell.WriteLine(response.ToString()); + var length = expires == null ? Loc.GetString("cmd-roleban-inf") : Loc.GetString("cmd-roleban-until", ("expires", expires)); + shell.WriteLine(Loc.GetString("cmd-roleban-success", ("target", target), ("role", role), ("reason", reason), ("length", length))); } #endregion } diff --git a/Resources/Locale/en-US/job/role-ban-command.ftl b/Resources/Locale/en-US/job/role-ban-command.ftl index 17fce9835c..f02a89924b 100644 --- a/Resources/Locale/en-US/job/role-ban-command.ftl +++ b/Resources/Locale/en-US/job/role-ban-command.ftl @@ -31,3 +31,18 @@ cmd-rolebanlist-help = Usage: [include unbanned] ## Completion result hints cmd-rolebanlist-hint-1 = cmd-rolebanlist-hint-2 = [include unbanned] + + +cmd-roleban-minutes-parse = {$time} is not a valid amount of minutes.\n{$help} +cmd-roleban-arg-count = Invalid amount of arguments. +cmd-roleban-job-parse = Job {$job} does not exist. +cmd-roleban-name-parse = Unable to find a player with that name. +cmd-roleban-existing = {$target} already has a role ban for {$role}. +cmd-roleban-success = Role banned {$target} from {$role} with reason {$reason} {$length}. + +cmd-roleban-inf = permanently +cmd-roleban-until = until {$expires} + +# Department bans +cmd-departmentban-desc = Bans a player from the roles comprising a department +cmd-departmentban-help = Usage: departmentban [duration in minutes, leave out or 0 for permanent ban]