]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Rolebanlist command UI (#30827)
authorsativaleanne <49132913+sativaleanne@users.noreply.github.com>
Fri, 20 Sep 2024 11:49:31 +0000 (04:49 -0700)
committerGitHub <noreply@github.com>
Fri, 20 Sep 2024 11:49:31 +0000 (21:49 +1000)
* rolebanlist command opens ui

* removed commented out section

Content.Server/Administration/Commands/RoleBanListCommand.cs

index a5904723390456de34a7767621ef404d72de6013..30bb3073add9328f7210f47dab4f26ab82b1af6e 100644 (file)
@@ -1,5 +1,7 @@
 using System.Linq;
 using System.Text;
+using Content.Server.Administration.BanList;
+using Content.Server.EUI;
 using Content.Server.Database;
 using Content.Shared.Administration;
 using Robust.Server.Player;
@@ -10,6 +12,12 @@ namespace Content.Server.Administration.Commands;
 [AdminCommand(AdminFlags.Ban)]
 public sealed class RoleBanListCommand : IConsoleCommand
 {
+    [Dependency] private readonly IServerDbManager _dbManager = default!;
+
+    [Dependency] private readonly EuiManager _eui = default!;
+
+    [Dependency] private readonly IPlayerLocator _locator = default!;
+
     public string Command => "rolebanlist";
     public string Description => Loc.GetString("cmd-rolebanlist-desc");
     public string Help => Loc.GetString("cmd-rolebanlist-help");
@@ -29,66 +37,37 @@ public sealed class RoleBanListCommand : IConsoleCommand
             return;
         }
 
-        var dbMan = IoCManager.Resolve<IServerDbManager>();
-
-        var target = args[0];
+        var data = await _locator.LookupIdByNameOrIdAsync(args[0]);
 
-        var locator = IoCManager.Resolve<IPlayerLocator>();
-        var located = await locator.LookupIdByNameOrIdAsync(target);
-        if (located == null)
+        if (data == null)
         {
             shell.WriteError("Unable to find a player with that name or id.");
             return;
         }
 
-        var targetUid = located.UserId;
-        var targetHWid = located.LastHWId;
-        var targetAddress = located.LastAddress;
-
-        var bans = await dbMan.GetServerRoleBansAsync(targetAddress, targetUid, targetHWid, includeUnbanned);
-
-        if (bans.Count == 0)
+        if (shell.Player is not { } player)
         {
-            shell.WriteLine("That user has no bans in their record.");
-            return;
-        }
 
-        var bansString = new StringBuilder("Bans in record:\n");
+            var bans = await _dbManager.GetServerRoleBansAsync(data.LastAddress, data.UserId, data.LastHWId, includeUnbanned);
 
-        var first = true;
-        foreach (var ban in bans)
-        {
-            if (!first)
-                bansString.Append("\n\n");
-            else
-                first = false;
-
-            bansString
-                .Append("Ban ID: ")
-                .Append(ban.Id)
-                .Append('\n')
-                .Append("Role: ")
-                .Append(ban.Role)
-                .Append('\n')
-                .Append("Banned on ")
-                .Append(ban.BanTime);
-
-            if (ban.ExpirationTime != null)
+            if (bans.Count == 0)
             {
-                bansString
-                    .Append(" until ")
-                    .Append(ban.ExpirationTime.Value);
+                shell.WriteLine("That user has no bans in their record.");
+                return;
             }
 
-            bansString
-                .Append('\n');
-
-            bansString
-                .Append("Reason: ")
-                .Append(ban.Reason);
+            foreach (var ban in bans)
+            {
+                var msg = $"ID: {ban.Id}: Role: {ban.Role} Reason: {ban.Reason}";
+                shell.WriteLine(msg);
+            }
+            return;
         }
 
-        shell.WriteLine(bansString.ToString());
+        var ui = new BanListEui();
+        _eui.OpenEui(ui, player);
+        await ui.ChangeBanListPlayer(data.UserId);
+
     }
 
     public CompletionResult GetCompletion(IConsoleShell shell, string[] args)