MOTDCommand.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using Content.Server.Administration.Managers;
  2. using Content.Shared.Administration;
  3. using Robust.Shared.Console;
  4. namespace Content.Server.Motd;
  5. /// <summary>
  6. /// A console command which acts as an alias for <see cref="GetMotdCommand"/> or <see cref="SetMotdCommand"/> depending on the number of arguments given.
  7. /// </summary>
  8. [AnyCommand]
  9. internal sealed class MOTDCommand : LocalizedCommands
  10. {
  11. [Dependency] private readonly IAdminManager _adminManager = default!;
  12. public override string Command => "motd";
  13. public override void Execute(IConsoleShell shell, string argStr, string[] args)
  14. {
  15. var player = shell.Player;
  16. if (args.Length < 1 || (player != null && _adminManager is AdminManager aMan && !aMan.CanCommand(player, "set-motd")))
  17. shell.ConsoleHost.ExecuteCommand(shell.Player, "get-motd");
  18. else
  19. shell.ConsoleHost.ExecuteCommand(shell.Player, $"set-motd {string.Join(" ", args)}");
  20. }
  21. public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
  22. {
  23. var player = shell.Player;
  24. if (player != null && _adminManager is AdminManager aMan && !aMan.CanCommand(player, "set-motd"))
  25. return CompletionResult.Empty;
  26. if (args.Length == 1)
  27. return CompletionResult.FromHint(Loc.GetString("cmd-set-motd-hint-head"));
  28. return CompletionResult.FromHint(Loc.GetString("cmd-set-motd-hint-cont"));
  29. }
  30. }