Add vote logs (#14139)

Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
Chief-Engineer
2023-02-16 18:29:44 -06:00
committed by GitHub
parent 061d4de1e4
commit a0ea580260
6 changed files with 67 additions and 0 deletions

View File

@@ -1,8 +1,10 @@
using System.Linq;
using Content.Server.Administration;
using Content.Server.Administration.Logs;
using Content.Server.Chat.Managers;
using Content.Server.Voting.Managers;
using Content.Shared.Administration;
using Content.Shared.Database;
using Content.Shared.Voting;
using Robust.Server.Player;
using Robust.Shared.Console;
@@ -12,6 +14,8 @@ namespace Content.Server.Voting
[AnyCommand]
public sealed class CreateVoteCommand : IConsoleCommand
{
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
public string Command => "createvote";
public string Description => Loc.GetString("cmd-createvote-desc");
public string Help => Loc.GetString("cmd-createvote-help");
@@ -34,6 +38,7 @@ namespace Content.Server.Voting
if (shell.Player != null && !mgr.CanCallVote((IPlayerSession) 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;
}
@@ -56,6 +61,8 @@ namespace Content.Server.Voting
[AdminCommand(AdminFlags.Admin)]
public sealed class CreateCustomCommand : IConsoleCommand
{
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
private const int MaxArgCount = 10;
public string Command => "customvote";
@@ -87,6 +94,11 @@ namespace Content.Server.Voting
options.SetInitiatorOrServer((IPlayerSession?) shell.Player);
if (shell.Player != null)
_adminLogger.Add(LogType.Vote, LogImpact.Medium, $"{shell.Player} initiated a custom vote: {options.Title} - {string.Join("; ", options.Options.Select(x => x.text))}");
else
_adminLogger.Add(LogType.Vote, LogImpact.Medium, $"Initiated a custom vote: {options.Title} - {string.Join("; ", options.Options.Select(x => x.text))}");
var vote = mgr.CreateVote(options);
vote.OnFinished += (_, eventArgs) =>
@@ -95,10 +107,12 @@ namespace Content.Server.Voting
if (eventArgs.Winner == null)
{
var ties = string.Join(", ", eventArgs.Winners.Select(c => args[(int) c]));
_adminLogger.Add(LogType.Vote, LogImpact.Medium, $"Custom vote {options.Title} finished as tie: {ties}");
chatMgr.DispatchServerAnnouncement(Loc.GetString("cmd-customvote-on-finished-tie",("ties", ties)));
}
else
{
_adminLogger.Add(LogType.Vote, LogImpact.Medium, $"Custom vote {options.Title} finished: {args[(int) eventArgs.Winner]}");
chatMgr.DispatchServerAnnouncement(Loc.GetString("cmd-customvote-on-finished-win",("winner", args[(int) eventArgs.Winner])));
}
};
@@ -198,6 +212,8 @@ namespace Content.Server.Voting
[AdminCommand(AdminFlags.Admin)]
public sealed class CancelVoteCommand : IConsoleCommand
{
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
public string Command => "cancelvote";
public string Description => Loc.GetString("cmd-cancelvote-desc");
public string Help => Loc.GetString("cmd-cancelvote-help");
@@ -218,6 +234,10 @@ namespace Content.Server.Voting
return;
}
if (shell.Player != null)
_adminLogger.Add(LogType.Vote, LogImpact.Medium, $"{shell.Player} canceled vote: {vote.Title}");
else
_adminLogger.Add(LogType.Vote, LogImpact.Medium, $"Canceled vote: {vote.Title}");
vote.Cancel();
}