From 2499b4e2bd266fc104d6471a60948dbe83e211f2 Mon Sep 17 00:00:00 2001 From: Chief-Engineer <119664036+Chief-Engineer@users.noreply.github.com> Date: Mon, 19 Dec 2022 22:14:43 -0600 Subject: [PATCH] Add osay command (#13057) * add osay command * replace obsolete method * inherit LocalizedCommands instead of IConsoleCommand * streamline * make OSay class public to match other commands * re-scope namespace to file --- .../Administration/Commands/OSay.cs | 62 +++++++++++++++++++ .../administration/commands/osay-command.ftl | 9 +++ 2 files changed, 71 insertions(+) create mode 100644 Content.Server/Administration/Commands/OSay.cs create mode 100644 Resources/Locale/en-US/administration/commands/osay-command.ftl diff --git a/Content.Server/Administration/Commands/OSay.cs b/Content.Server/Administration/Commands/OSay.cs new file mode 100644 index 0000000000..e89bd56881 --- /dev/null +++ b/Content.Server/Administration/Commands/OSay.cs @@ -0,0 +1,62 @@ +using System.Linq; +using Content.Server.Administration.Logs; +using Content.Server.Chat.Systems; +using Content.Shared.Administration; +using Content.Shared.Database; +using Robust.Shared.Console; + +namespace Content.Server.Administration.Commands; + +[AdminCommand(AdminFlags.Admin)] +public sealed class OSay : LocalizedCommands +{ + [Dependency] private readonly IAdminLogManager _adminLogger = default!; + [Dependency] private readonly IEntityManager _entityManager = default!; + + public override string Command => "osay"; + + public override CompletionResult GetCompletion(IConsoleShell shell, string[] args) + { + if (args.Length == 1) + { + return CompletionResult.FromHint(Loc.GetString("osay-command-arg-uid")); + } + + if (args.Length == 2) + { + return CompletionResult.FromHintOptions( Enum.GetNames(typeof(InGameICChatType)), + Loc.GetString("osay-command-arg-type")); + } + + if (args.Length > 2) + { + return CompletionResult.FromHint(Loc.GetString("osay-command-arg-message")); + } + + return CompletionResult.Empty; + } + + public override void Execute(IConsoleShell shell, string argStr, string[] args) + { + if (args.Length < 3) + { + shell.WriteLine(Loc.GetString("osay-command-error-args")); + return; + } + + var chatType = (InGameICChatType) Enum.Parse(typeof(InGameICChatType), args[1]); + + if (!EntityUid.TryParse(args[0], out var source) || !_entityManager.EntityExists(source)) + { + shell.WriteLine(Loc.GetString("osay-command-error-euid", ("arg", args[0]))); + return; + } + + var message = string.Join(" ", args.Skip(2)).Trim(); + if (string.IsNullOrEmpty(message)) + return; + + _entityManager.System().TrySendInGameICMessage(source, message, chatType, false); + _adminLogger.Add(LogType.Action, LogImpact.Low, $"{(shell.Player != null ? shell.Player.Name : "An administrator")} forced {_entityManager.ToPrettyString(source)} to {args[1]}: {message}"); + } +} diff --git a/Resources/Locale/en-US/administration/commands/osay-command.ftl b/Resources/Locale/en-US/administration/commands/osay-command.ftl new file mode 100644 index 0000000000..de7cecf158 --- /dev/null +++ b/Resources/Locale/en-US/administration/commands/osay-command.ftl @@ -0,0 +1,9 @@ +osay-command-description = Forces another entity to try to send a message +osay-command-help-text = Usage: {$command} + +osay-command-arg-uid = source uid +osay-command-arg-type = type +osay-command-arg-message = message + +osay-command-error-args = Invalid number of arguments +osay-command-error-euid = {$arg} is not a valid entity uid.