1
0

ShowAlert.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Content.Server.Administration;
  2. using Content.Server.Commands;
  3. using Content.Shared.Administration;
  4. using Content.Shared.Alert;
  5. using Robust.Shared.Console;
  6. namespace Content.Server.Alert.Commands
  7. {
  8. [AdminCommand(AdminFlags.Debug)]
  9. public sealed class ShowAlert : IConsoleCommand
  10. {
  11. [Dependency] private readonly IEntityManager _e = default!;
  12. public string Command => "showalert";
  13. public string Description => "Shows an alert for a player, defaulting to current player";
  14. public string Help => "showalert <alertType> <severity, -1 if no severity> <name or userID, omit for current player>";
  15. public void Execute(IConsoleShell shell, string argStr, string[] args)
  16. {
  17. var player = shell.Player;
  18. if (player?.AttachedEntity == null)
  19. {
  20. shell.WriteLine("You cannot run this from the server or without an attached entity.");
  21. return;
  22. }
  23. var attachedEntity = player.AttachedEntity.Value;
  24. if (args.Length > 2)
  25. {
  26. var target = args[2];
  27. if (!CommandUtils.TryGetAttachedEntityByUsernameOrId(shell, target, player, out attachedEntity)) return;
  28. }
  29. if (!_e.TryGetComponent(attachedEntity, out AlertsComponent? alertsComponent))
  30. {
  31. shell.WriteLine("user has no alerts component");
  32. return;
  33. }
  34. var alertType = args[0];
  35. var severity = args[1];
  36. var alertsSystem = _e.System<AlertsSystem>();
  37. if (!alertsSystem.TryGet(alertType, out var alert))
  38. {
  39. shell.WriteLine("unrecognized alertType " + alertType);
  40. return;
  41. }
  42. if (!short.TryParse(severity, out var sevint))
  43. {
  44. shell.WriteLine("invalid severity " + sevint);
  45. return;
  46. }
  47. short? severity1 = sevint == -1 ? null : sevint;
  48. alertsSystem.ShowAlert(attachedEntity, alert.ID, severity1, null);
  49. }
  50. }
  51. }