diff --git a/Content.Server/Voting/VoteCommands.cs b/Content.Server/Voting/VoteCommands.cs index 8649eae114..6a77644bb4 100644 --- a/Content.Server/Voting/VoteCommands.cs +++ b/Content.Server/Voting/VoteCommands.cs @@ -13,8 +13,8 @@ namespace Content.Server.Voting public sealed class CreateVoteCommand : IConsoleCommand { public string Command => "createvote"; - public string Description => Loc.GetString("create-vote-command-description"); - public string Help => Loc.GetString("create-vote-command-help"); + public string Description => Loc.GetString("cmd-createvote-desc"); + public string Help => Loc.GetString("cmd-createvote-help"); public void Execute(IConsoleShell shell, string argStr, string[] args) { @@ -26,7 +26,7 @@ namespace Content.Server.Voting if (!Enum.TryParse(args[0], ignoreCase: true, out var type)) { - shell.WriteError(Loc.GetString("create-vote-command-invalid-vote-type")); + shell.WriteError(Loc.GetString("cmd-createvote-invalid-vote-type")); return; } @@ -34,24 +34,37 @@ namespace Content.Server.Voting if (shell.Player != null && !mgr.CanCallVote((IPlayerSession) shell.Player, type)) { - shell.WriteError(Loc.GetString("create-vote-command-cannot-call-vote-now")); + shell.WriteError(Loc.GetString("cmd-createvote-cannot-call-vote-now")); return; } mgr.CreateStandardVote((IPlayerSession?) shell.Player, type); } + + public CompletionResult GetCompletion(IConsoleShell shell, string[] args) + { + if (args.Length == 1) + { + var options = Enum.GetNames(); + return CompletionResult.FromHintOptions(options, Loc.GetString("cmd-createvote-arg-vote-type")); + } + + return CompletionResult.Empty; + } } [AdminCommand(AdminFlags.Admin)] public sealed class CreateCustomCommand : IConsoleCommand { + private const int MaxArgCount = 10; + public string Command => "customvote"; - public string Description => Loc.GetString("create-custom-command-description"); - public string Help => Loc.GetString("create-custom-command-help"); + public string Description => Loc.GetString("cmd-customvote-desc"); + public string Help => Loc.GetString("cmd-customvote-help"); public void Execute(IConsoleShell shell, string argStr, string[] args) { - if (args.Length < 3 || args.Length > 10) + if (args.Length < 3 || args.Length > MaxArgCount) { shell.WriteError(Loc.GetString("shell-need-between-arguments",("lower", 3), ("upper", 10))); return; @@ -82,14 +95,26 @@ namespace Content.Server.Voting if (eventArgs.Winner == null) { var ties = string.Join(", ", eventArgs.Winners.Select(c => args[(int) c])); - chatMgr.DispatchServerAnnouncement(Loc.GetString("create-custom-command-on-finished-tie",("ties", ties))); + chatMgr.DispatchServerAnnouncement(Loc.GetString("cmd-customvote-on-finished-tie",("ties", ties))); } else { - chatMgr.DispatchServerAnnouncement(Loc.GetString("create-custom-command-on-finished-win",("winner", args[(int) eventArgs.Winner]))); + chatMgr.DispatchServerAnnouncement(Loc.GetString("cmd-customvote-on-finished-win",("winner", args[(int) eventArgs.Winner]))); } }; } + + public CompletionResult GetCompletion(IConsoleShell shell, string[] args) + { + if (args.Length == 1) + return CompletionResult.FromHint(Loc.GetString("cmd-customvote-arg-title")); + + if (args.Length > MaxArgCount) + return CompletionResult.Empty; + + var n = args.Length - 1; + return CompletionResult.FromHint(Loc.GetString("cmd-customvote-arg-option-n", ("n", n))); + } } @@ -97,14 +122,14 @@ namespace Content.Server.Voting public sealed class VoteCommand : IConsoleCommand { public string Command => "vote"; - public string Description => Loc.GetString("vote-command-description"); - public string Help => Loc.GetString("vote-command-help"); + public string Description => Loc.GetString("cmd-vote-desc"); + public string Help => Loc.GetString("cmd-vote-help"); public void Execute(IConsoleShell shell, string argStr, string[] args) { if (shell.Player == null) { - shell.WriteError(Loc.GetString("vote-command-on-execute-error-must-be-player")); + shell.WriteError(Loc.GetString("cmd-vote-on-execute-error-must-be-player")); return; } @@ -116,20 +141,20 @@ namespace Content.Server.Voting if (!int.TryParse(args[0], out var voteId)) { - shell.WriteError(Loc.GetString("vote-command-on-execute-error-invalid-vote-id")); + shell.WriteError(Loc.GetString("cmd-vote-on-execute-error-invalid-vote-id")); return; } if (!int.TryParse(args[1], out var voteOption)) { - shell.WriteError(Loc.GetString("vote-command-on-execute-error-invalid-vote-options")); + shell.WriteError(Loc.GetString("cmd-vote-on-execute-error-invalid-vote-options")); return; } var mgr = IoCManager.Resolve(); if (!mgr.TryGetVote(voteId, out var vote)) { - shell.WriteError(Loc.GetString("vote-command-on-execute-error-invalid-vote")); + shell.WriteError(Loc.GetString("cmd-vote-on-execute-error-invalid-vote")); return; } @@ -144,7 +169,7 @@ namespace Content.Server.Voting } else { - shell.WriteError(Loc.GetString("vote-command-on-execute-error-invalid-option")); + shell.WriteError(Loc.GetString("cmd-vote-on-execute-error-invalid-option")); return; } @@ -156,8 +181,8 @@ namespace Content.Server.Voting public sealed class ListVotesCommand : IConsoleCommand { public string Command => "listvotes"; - public string Description => Loc.GetString("list-votes-command-description"); - public string Help => Loc.GetString("list-votes-command-help"); + public string Description => Loc.GetString("cmd-listvotes-desc"); + public string Help => Loc.GetString("cmd-listvotes-help"); public void Execute(IConsoleShell shell, string argStr, string[] args) { @@ -174,8 +199,8 @@ namespace Content.Server.Voting public sealed class CancelVoteCommand : IConsoleCommand { public string Command => "cancelvote"; - public string Description => Loc.GetString("cancel-vote-command-description"); - public string Help => Loc.GetString("cancel-vote-command-help"); + public string Description => Loc.GetString("cmd-cancelvote-desc"); + public string Help => Loc.GetString("cmd-cancelvote-help"); public void Execute(IConsoleShell shell, string argStr, string[] args) { @@ -183,17 +208,32 @@ namespace Content.Server.Voting if (args.Length < 1) { - shell.WriteError(Loc.GetString("cancel-vote-command-on-execute-error-missing-vote-id")); + shell.WriteError(Loc.GetString("cmd-cancelvote-error-missing-vote-id")); return; } if (!int.TryParse(args[0], out var id) || !mgr.TryGetVote(id, out var vote)) { - shell.WriteError(Loc.GetString("cancel-vote-command-on-execute-error-invalid-vote-id")); + shell.WriteError(Loc.GetString("cmd-cancelvote-error-invalid-vote-id")); return; } vote.Cancel(); } + + public CompletionResult GetCompletion(IConsoleShell shell, string[] args) + { + var mgr = IoCManager.Resolve(); + if (args.Length == 1) + { + var options = mgr.ActiveVotes + .OrderBy(v => v.Id) + .Select(v => new CompletionOption(v.Id.ToString(), v.Title)); + + return CompletionResult.FromHintOptions(options, Loc.GetString("cmd-cancelvote-arg-id")); + } + + return CompletionResult.Empty; + } } } diff --git a/Resources/Locale/en-US/voting/vote-commands.ftl b/Resources/Locale/en-US/voting/vote-commands.ftl index e3dcdeada3..94320294c8 100644 --- a/Resources/Locale/en-US/voting/vote-commands.ftl +++ b/Resources/Locale/en-US/voting/vote-commands.ftl @@ -1,37 +1,43 @@ -## CreateVoteCommand +### Voting system related console commands -create-vote-command-description = Creates a vote -create-vote-command-help = Usage: createvote <'restart'|'preset'> -create-vote-command-cannot-call-vote-now = You can't call a vote right now! -create-vote-command-invalid-vote-type = You can't call a vote right now! +## 'createvote' command -## CreateCustomCommand +cmd-createvote-desc = Creates a vote +cmd-createvote-help = Usage: createvote <'restart'|'preset'|'map'> +cmd-createvote-cannot-call-vote-now = You can't call a vote right now! +cmd-createvote-invalid-vote-type = Invalid vote type +cmd-createvote-arg-vote-type = -create-custom-command-description = Creates a custom vote -create-custom-command-help = customvote <option1> <option2> [option3...] -create-custom-command-on-finished-tie = Tie between {$ties}! -create-custom-command-on-finished-win = {$winner} wins! +## 'customvote' command -## VoteCommand +cmd-customvote-desc = Creates a custom vote +cmd-customvote-help = Usage: customvote <title> <option1> <option2> [option3...] +cmd-customvote-on-finished-tie = Tie between {$ties}! +cmd-customvote-on-finished-win = {$winner} wins! +cmd-customvote-arg-title = <title> +cmd-customvote-arg-option-n = <option{ $n }> -vote-command-description = Votes on an active vote -vote-command-help = vote <voteId> <option> -vote-command-cannot-call-vote-now = You can't call a vote right now! -vote-command-on-execute-error-must-be-player = Must be a player -vote-command-on-execute-error-invalid-vote-id = Invalid vote ID -vote-command-on-execute-error-invalid-vote-options = Invalid vote options -vote-command-on-execute-error-invalid-vote = Invalid vote -vote-command-on-execute-error-invalid-option = Invalid option +## 'vote' command -## ListVotesCommand +cmd-vote-desc = Votes on an active vote +cmd-vote-help = vote <voteId> <option> +cmd-vote-cannot-call-vote-now = You can't call a vote right now! +cmd-vote-on-execute-error-must-be-player = Must be a player +cmd-vote-on-execute-error-invalid-vote-id = Invalid vote ID +cmd-vote-on-execute-error-invalid-vote-options = Invalid vote options +cmd-vote-on-execute-error-invalid-vote = Invalid vote +cmd-vote-on-execute-error-invalid-option = Invalid option -list-votes-command-description = Lists currently active votes -list-votes-command-help = Usage: listvotes +## 'listvotes' command -## CancelVoteCommand +cmd-listvotes-desc = Lists currently active votes +cmd-listvotes-help = Usage: listvotes -cancel-vote-command-description = Cancels an active vote -cancel-vote-command-help = Usage: cancelvote <id> - You can get the ID from the listvotes command. -cancel-vote-command-on-execute-error-invalid-vote-id = Invalid vote ID -cancel-vote-command-on-execute-error-missing-vote-id = Missing ID \ No newline at end of file +## 'cancelvote' command + +cmd-cancelvote-desc = Cancels an active vote +cmd-cancelvote-help = Usage: cancelvote <id> + You can get the ID from the listvotes command. +cmd-cancelvote-error-invalid-vote-id = Invalid vote ID +cmd-cancelvote-error-missing-vote-id = Missing ID +cmd-cancelvote-arg-id = <id>