SetMOTDCommand.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Content.Server.Administration;
  2. using Content.Server.Administration.Logs;
  3. using Content.Shared.Administration;
  4. using Content.Shared.Database;
  5. using Content.Shared.CCVar;
  6. using Content.Server.Chat.Managers;
  7. using Robust.Shared.Configuration;
  8. using Robust.Shared.Console;
  9. namespace Content.Server.Motd;
  10. /// <summary>
  11. /// A console command usable by any user which prints or sets the Message of the Day.
  12. /// </summary>
  13. [AdminCommand(AdminFlags.Moderator)]
  14. public sealed class SetMotdCommand : LocalizedCommands
  15. {
  16. [Dependency] private readonly IAdminLogManager _adminLogManager = default!;
  17. [Dependency] private readonly IChatManager _chatManager = default!;
  18. [Dependency] private readonly IConfigurationManager _configurationManager = default!;
  19. public override string Command => "set-motd";
  20. public override void Execute(IConsoleShell shell, string argStr, string[] args)
  21. {
  22. string motd = "";
  23. var player = shell.Player;
  24. if (args.Length > 0)
  25. {
  26. motd = string.Join(" ", args).Trim();
  27. if (player != null && _chatManager.MessageCharacterLimit(player, motd))
  28. return; // check function prints its own error response
  29. }
  30. _configurationManager.SetCVar(CCVars.MOTD, motd); // A hook in MOTDSystem broadcasts changes to the MOTD to everyone so we don't need to do it here.
  31. if (string.IsNullOrEmpty(motd))
  32. {
  33. shell.WriteLine(Loc.GetString("cmd-set-motd-cleared-motd-message"));
  34. _adminLogManager.Add(LogType.Chat, LogImpact.Low, $"{(player == null ? "LOCALHOST" : player.Channel.UserName):Player} cleared the MOTD for the server.");
  35. }
  36. else
  37. {
  38. shell.WriteLine(Loc.GetString("cmd-set-motd-set-motd-message", ("motd", motd)));
  39. _adminLogManager.Add(LogType.Chat, LogImpact.Low, $"{(player == null ? "LOCALHOST" : player.Channel.UserName):Player} set the MOTD for the server to \"{motd:motd}\"");
  40. }
  41. }
  42. public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
  43. {
  44. if (args.Length == 1)
  45. return CompletionResult.FromHint(Loc.GetString("cmd-set-motd-hint-head"));
  46. return CompletionResult.FromHint(Loc.GetString("cmd-set-motd-hint-cont"));
  47. }
  48. }