]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Kill resolves in vote commands (#37637)
authorKyle Tyo <36606155+VerinSenpai@users.noreply.github.com>
Tue, 27 May 2025 03:18:59 +0000 (23:18 -0400)
committerGitHub <noreply@github.com>
Tue, 27 May 2025 03:18:59 +0000 (05:18 +0200)
* kill resolves in VoteCommand.cs

* consistency and cleanup

* final touch

Content.Server/Voting/VoteCommands.cs

index d4c236f3945e6df326364a53bb78e1c61f128235..e7b85998553fda320609ad2c3a4b38803016d8ed 100644 (file)
@@ -8,23 +8,20 @@ using Content.Shared.Administration;
 using Content.Shared.CCVar;
 using Content.Shared.Database;
 using Content.Shared.Voting;
-using Robust.Server;
 using Robust.Shared.Configuration;
 using Robust.Shared.Console;
-using Robust.Shared.Utility;
 
 namespace Content.Server.Voting
 {
     [AnyCommand]
-    public sealed class CreateVoteCommand : IConsoleCommand
+    public sealed class CreateVoteCommand : LocalizedEntityCommands
     {
         [Dependency] private readonly IAdminLogManager _adminLogger = default!;
+        [Dependency] private readonly IVoteManager _voteManager = default!;
 
-        public string Command => "createvote";
-        public string Description => Loc.GetString("cmd-createvote-desc");
-        public string Help => Loc.GetString("cmd-createvote-help");
+        public override string Command => "createvote";
 
-        public void Execute(IConsoleShell shell, string argStr, string[] args)
+        public override void Execute(IConsoleShell shell, string argStr, string[] args)
         {
             if (args.Length != 1 && args[0] != StandardVoteType.Votekick.ToString())
             {
@@ -44,19 +41,17 @@ namespace Content.Server.Voting
                 return;
             }
 
-            var mgr = IoCManager.Resolve<IVoteManager>();
-
-            if (shell.Player != null && !mgr.CanCallVote(shell.Player, type))
+            if (shell.Player != null && !_voteManager.CanCallVote(shell.Player, type))
             {
                 _adminLogger.Add(LogType.Vote, LogImpact.Medium, $"{shell.Player} failed to start {type.ToString()} vote");
                 shell.WriteError(Loc.GetString("cmd-createvote-cannot-call-vote-now"));
                 return;
             }
 
-            mgr.CreateStandardVote(shell.Player, type, args.Skip(1).ToArray());
+            _voteManager.CreateStandardVote(shell.Player, type, args.Skip(1).ToArray());
         }
 
-        public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
+        public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
         {
             if (args.Length == 1)
             {
@@ -77,16 +72,12 @@ namespace Content.Server.Voting
         [Dependency] private readonly VoteWebhooks _voteWebhooks = default!;
         [Dependency] private readonly IConfigurationManager _cfg = default!;
 
-        private ISawmill _sawmill = default!;
-
         private const int MaxArgCount = 10;
 
         public override string Command => "customvote";
 
         public override void Execute(IConsoleShell shell, string argStr, string[] args)
         {
-            _sawmill = Logger.GetSawmill("vote");
-
             if (args.Length < 3 || args.Length > MaxArgCount)
             {
                 shell.WriteError(Loc.GetString("shell-need-between-arguments",("lower", 3), ("upper", 10)));
@@ -154,13 +145,13 @@ namespace Content.Server.Voting
     }
 
     [AnyCommand]
-    public sealed class VoteCommand : IConsoleCommand
+    public sealed class VoteCommand : LocalizedEntityCommands
     {
-        public string Command => "vote";
-        public string Description => Loc.GetString("cmd-vote-desc");
-        public string Help => Loc.GetString("cmd-vote-help");
+        [Dependency] private readonly IVoteManager _voteManager = default!;
+
+        public override string Command => "vote";
 
-        public void Execute(IConsoleShell shell, string argStr, string[] args)
+        public override void Execute(IConsoleShell shell, string argStr, string[] args)
         {
             if (shell.Player == null)
             {
@@ -186,8 +177,7 @@ namespace Content.Server.Voting
                 return;
             }
 
-            var mgr = IoCManager.Resolve<IVoteManager>();
-            if (!mgr.TryGetVote(voteId, out var vote))
+            if (!_voteManager.TryGetVote(voteId, out var vote))
             {
                 shell.WriteError(Loc.GetString("cmd-vote-on-execute-error-invalid-vote"));
                 return;
@@ -213,17 +203,15 @@ namespace Content.Server.Voting
     }
 
     [AnyCommand]
-    public sealed class ListVotesCommand : IConsoleCommand
+    public sealed class ListVotesCommand : LocalizedEntityCommands
     {
-        public string Command => "listvotes";
-        public string Description => Loc.GetString("cmd-listvotes-desc");
-        public string Help => Loc.GetString("cmd-listvotes-help");
+        [Dependency] private readonly IVoteManager _voteManager = default!;
 
-        public void Execute(IConsoleShell shell, string argStr, string[] args)
-        {
-            var mgr = IoCManager.Resolve<IVoteManager>();
+        public override string Command => "listvotes";
 
-            foreach (var vote in mgr.ActiveVotes)
+        public override void Execute(IConsoleShell shell, string argStr, string[] args)
+        {
+            foreach (var vote in _voteManager.ActiveVotes)
             {
                 shell.WriteLine($"[{vote.Id}] {vote.InitiatorText}: {vote.Title}");
             }
@@ -231,25 +219,22 @@ namespace Content.Server.Voting
     }
 
     [AdminCommand(AdminFlags.Moderator)]
-    public sealed class CancelVoteCommand : IConsoleCommand
+    public sealed class CancelVoteCommand : LocalizedEntityCommands
     {
         [Dependency] private readonly IAdminLogManager _adminLogger = default!;
+        [Dependency] private readonly IVoteManager _voteManager = default!;
 
-        public string Command => "cancelvote";
-        public string Description => Loc.GetString("cmd-cancelvote-desc");
-        public string Help => Loc.GetString("cmd-cancelvote-help");
+        public override string Command => "cancelvote";
 
-        public void Execute(IConsoleShell shell, string argStr, string[] args)
+        public override void Execute(IConsoleShell shell, string argStr, string[] args)
         {
-            var mgr = IoCManager.Resolve<IVoteManager>();
-
             if (args.Length < 1)
             {
                 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))
+            if (!int.TryParse(args[0], out var id) || !_voteManager.TryGetVote(id, out var vote))
             {
                 shell.WriteError(Loc.GetString("cmd-cancelvote-error-invalid-vote-id"));
                 return;
@@ -262,7 +247,7 @@ namespace Content.Server.Voting
             vote.Cancel();
         }
 
-        public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
+        public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
         {
             var mgr = IoCManager.Resolve<IVoteManager>();
             if (args.Length == 1)