Kill resolves in vote commands (#37637)

* kill resolves in VoteCommand.cs

* consistency and cleanup

* final touch
This commit is contained in:
Kyle Tyo
2025-05-26 23:18:59 -04:00
committed by GitHub
parent be761ea537
commit cc6f364e9d

View File

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