From 4d8ff35640e7f0001f9878ec1a358e1958fe9b03 Mon Sep 17 00:00:00 2001 From: Kara Date: Fri, 24 Jun 2022 04:14:47 -0700 Subject: [PATCH] Roleban completions (#9114) * Roleban completions * helpers * eat my peenor dumb robot --- .../Administration/Commands/RoleBanCommand.cs | 32 ++++++++++++++++-- .../Commands/RoleBanListCommand.cs | 20 +++++++++-- .../Commands/RoleUnbanCommand.cs | 14 ++++++-- .../Locale/en-US/job/role-ban-command.ftl | 33 +++++++++++++++++++ 4 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 Resources/Locale/en-US/job/role-ban-command.ftl diff --git a/Content.Server/Administration/Commands/RoleBanCommand.cs b/Content.Server/Administration/Commands/RoleBanCommand.cs index 1f153bc5d3..7f0ec66238 100644 --- a/Content.Server/Administration/Commands/RoleBanCommand.cs +++ b/Content.Server/Administration/Commands/RoleBanCommand.cs @@ -1,6 +1,11 @@ -using Content.Server.Administration.Managers; +using System.Linq; +using Content.Server.Administration.Managers; using Content.Shared.Administration; +using Content.Shared.Roles; +using Robust.Server.Player; using Robust.Shared.Console; +using Robust.Shared.Prototypes; +using Serilog; namespace Content.Server.Administration.Commands; @@ -8,8 +13,8 @@ namespace Content.Server.Administration.Commands; public sealed class RoleBanCommand : IConsoleCommand { public string Command => "roleban"; - public string Description => "Bans a player from a role"; - public string Help => $"Usage: {Command} [duration in minutes, leave out or 0 for permanent ban]"; + public string Description => Loc.GetString("cmd-roleban-desc"); + public string Help => Loc.GetString("cmd-roleban-help"); public async void Execute(IConsoleShell shell, string argStr, string[] args) { @@ -46,4 +51,25 @@ public sealed class RoleBanCommand : IConsoleCommand IoCManager.Resolve().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/RoleBanListCommand.cs b/Content.Server/Administration/Commands/RoleBanListCommand.cs index 14f93099d7..a590472339 100644 --- a/Content.Server/Administration/Commands/RoleBanListCommand.cs +++ b/Content.Server/Administration/Commands/RoleBanListCommand.cs @@ -1,6 +1,8 @@ -using System.Text; +using System.Linq; +using System.Text; using Content.Server.Database; using Content.Shared.Administration; +using Robust.Server.Player; using Robust.Shared.Console; namespace Content.Server.Administration.Commands; @@ -9,8 +11,8 @@ namespace Content.Server.Administration.Commands; public sealed class RoleBanListCommand : IConsoleCommand { public string Command => "rolebanlist"; - public string Description => "Lists the user's role bans"; - public string Help => "Usage: [include unbanned]"; + public string Description => Loc.GetString("cmd-rolebanlist-desc"); + public string Help => Loc.GetString("cmd-rolebanlist-help"); public async void Execute(IConsoleShell shell, string argStr, string[] args) { @@ -88,4 +90,16 @@ public sealed class RoleBanListCommand : IConsoleCommand shell.WriteLine(bansString.ToString()); } + + public CompletionResult GetCompletion(IConsoleShell shell, string[] args) + { + return args.Length switch + { + 1 => CompletionResult.FromHintOptions(CompletionHelper.SessionNames(), + Loc.GetString("cmd-rolebanlist-hint-1")), + 2 => CompletionResult.FromHintOptions(CompletionHelper.Booleans, + Loc.GetString("cmd-rolebanlist-hint-2")), + _ => CompletionResult.Empty + }; + } } diff --git a/Content.Server/Administration/Commands/RoleUnbanCommand.cs b/Content.Server/Administration/Commands/RoleUnbanCommand.cs index 5f5925cd96..1d7458c0f0 100644 --- a/Content.Server/Administration/Commands/RoleUnbanCommand.cs +++ b/Content.Server/Administration/Commands/RoleUnbanCommand.cs @@ -10,8 +10,8 @@ namespace Content.Server.Administration.Commands; public sealed class RoleUnbanCommand : IConsoleCommand { public string Command => "roleunban"; - public string Description => "Pardons a player's role ban"; - public string Help => $"Usage: {Command} "; + public string Description => Loc.GetString("cmd-roleunban-desc"); + public string Help => Loc.GetString("cmd-roleunban-help"); public async void Execute(IConsoleShell shell, string argStr, string[] args) { @@ -57,4 +57,14 @@ public sealed class RoleUnbanCommand : IConsoleCommand shell.WriteLine($"Pardoned ban with id {banId}"); } + + public CompletionResult GetCompletion(IConsoleShell shell, string[] args) + { + // Can't think of good way to do hint options for this + return args.Length switch + { + 1 => CompletionResult.FromHint(Loc.GetString("cmd-roleunban-hint-1")), + _ => CompletionResult.Empty + }; + } } diff --git a/Resources/Locale/en-US/job/role-ban-command.ftl b/Resources/Locale/en-US/job/role-ban-command.ftl new file mode 100644 index 0000000000..17fce9835c --- /dev/null +++ b/Resources/Locale/en-US/job/role-ban-command.ftl @@ -0,0 +1,33 @@ +### Localization for role ban command + +cmd-roleban-desc = Bans a player from a role +cmd-roleban-help = Usage: roleban [duration in minutes, leave out or 0 for permanent ban] + +## Completion result hints +cmd-roleban-hint-1 = +cmd-roleban-hint-2 = +cmd-roleban-hint-3 = +cmd-roleban-hint-4 = [duration in minutes, leave out or 0 for permanent ban] + +cmd-roleban-hint-duration-1 = Permanent +cmd-roleban-hint-duration-2 = 1 day +cmd-roleban-hint-duration-3 = 1 week + + +### Localization for role unban command + +cmd-roleunban-desc = Pardons a player's role ban +cmd-roleunban-help = Usage: roleunban + +## Completion result hints +cmd-roleunban-hint-1 = + + +### Localization for roleban list command + +cmd-rolebanlist-desc = Lists the user's role bans +cmd-rolebanlist-help = Usage: [include unbanned] + +## Completion result hints +cmd-rolebanlist-hint-1 = +cmd-rolebanlist-hint-2 = [include unbanned]