IsAfkCommand.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Content.Server.Administration;
  2. using Content.Shared.Administration;
  3. using Robust.Server.Player;
  4. using Robust.Shared.Console;
  5. namespace Content.Server.Afk
  6. {
  7. [AdminCommand(AdminFlags.Admin)]
  8. public sealed class IsAfkCommand : IConsoleCommand
  9. {
  10. [Dependency] private readonly IPlayerManager _players = default!;
  11. public string Command => "isafk";
  12. public string Description => "Checks if a specified player is AFK";
  13. public string Help => "Usage: isafk <playerName>";
  14. public void Execute(IConsoleShell shell, string argStr, string[] args)
  15. {
  16. var afkManager = IoCManager.Resolve<IAfkManager>();
  17. if (args.Length == 0)
  18. {
  19. shell.WriteError("Need one argument");
  20. return;
  21. }
  22. if (!_players.TryGetSessionByUsername(args[0], out var player))
  23. {
  24. shell.WriteError("Unable to find that player");
  25. return;
  26. }
  27. shell.WriteLine(afkManager.IsAfk(player) ? "They are indeed AFK" : "They are not AFK");
  28. }
  29. public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
  30. {
  31. if (args.Length == 1)
  32. {
  33. return CompletionResult.FromHintOptions(
  34. CompletionHelper.SessionNames(players: _players),
  35. "<playerName>");
  36. }
  37. return CompletionResult.Empty;
  38. }
  39. }
  40. }