update the announce command (#34889)
This commit is contained in:
@@ -1,38 +1,79 @@
|
|||||||
using Content.Server.Administration;
|
using Content.Server.Administration;
|
||||||
using Content.Server.Chat;
|
|
||||||
using Content.Server.Chat.Systems;
|
using Content.Server.Chat.Systems;
|
||||||
using Content.Shared.Administration;
|
using Content.Shared.Administration;
|
||||||
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.Console;
|
using Robust.Shared.Console;
|
||||||
|
using Robust.Shared.ContentPack;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
|
||||||
namespace Content.Server.Announcements
|
namespace Content.Server.Announcements;
|
||||||
|
|
||||||
|
[AdminCommand(AdminFlags.Moderator)]
|
||||||
|
public sealed class AnnounceCommand : LocalizedEntityCommands
|
||||||
{
|
{
|
||||||
[AdminCommand(AdminFlags.Moderator)]
|
[Dependency] private readonly ChatSystem _chat = default!;
|
||||||
public sealed class AnnounceCommand : IConsoleCommand
|
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||||
{
|
[Dependency] private readonly IResourceManager _res = default!;
|
||||||
public string Command => "announce";
|
|
||||||
public string Description => "Send an in-game announcement.";
|
|
||||||
public string Help => $"{Command} <sender> <message> or {Command} <message> to send announcement as CentCom.";
|
|
||||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
||||||
{
|
|
||||||
var chat = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<ChatSystem>();
|
|
||||||
|
|
||||||
if (args.Length == 0)
|
public override string Command => "announce";
|
||||||
|
public override string Description => Loc.GetString("cmd-announce-desc");
|
||||||
|
public override string Help => Loc.GetString("cmd-announce-help", ("command", Command));
|
||||||
|
|
||||||
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||||
{
|
{
|
||||||
shell.WriteError("Not enough arguments! Need at least 1.");
|
switch (args.Length)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
shell.WriteError(Loc.GetString("shell-need-minimum-one-argument"));
|
||||||
|
return;
|
||||||
|
case > 4:
|
||||||
|
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.Length == 1)
|
var message = args[0];
|
||||||
|
var sender = Loc.GetString("cmd-announce-sender");
|
||||||
|
var color = Color.Gold;
|
||||||
|
var sound = new SoundPathSpecifier("/Audio/Announcements/announce.ogg");
|
||||||
|
|
||||||
|
// Optional sender argument
|
||||||
|
if (args.Length >= 2)
|
||||||
|
sender = args[1];
|
||||||
|
|
||||||
|
// Optional color argument
|
||||||
|
if (args.Length >= 3)
|
||||||
{
|
{
|
||||||
chat.DispatchGlobalAnnouncement(args[0], colorOverride: Color.Gold);
|
try
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// Explicit IEnumerable<string> due to overload ambiguity on .NET 9
|
color = Color.FromHex(args[2]);
|
||||||
var message = string.Join(' ', (IEnumerable<string>)new ArraySegment<string>(args, 1, args.Length-1));
|
|
||||||
chat.DispatchGlobalAnnouncement(message, args[0], colorOverride: Color.Gold);
|
|
||||||
}
|
}
|
||||||
shell.WriteLine("Sent!");
|
catch
|
||||||
|
{
|
||||||
|
shell.WriteError(Loc.GetString("shell-invalid-color-hex"));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Optional sound argument
|
||||||
|
if (args.Length >= 4)
|
||||||
|
sound = new SoundPathSpecifier(args[3]);
|
||||||
|
|
||||||
|
_chat.DispatchGlobalAnnouncement(message, sender, true, sound, color);
|
||||||
|
shell.WriteLine(Loc.GetString("shell-command-success"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
||||||
|
{
|
||||||
|
return args.Length switch
|
||||||
|
{
|
||||||
|
1 => CompletionResult.FromHint(Loc.GetString("cmd-announce-arg-message")),
|
||||||
|
2 => CompletionResult.FromHint(Loc.GetString("cmd-announce-arg-sender")),
|
||||||
|
3 => CompletionResult.FromHint(Loc.GetString("cmd-announce-arg-color")),
|
||||||
|
4 => CompletionResult.FromHintOptions(
|
||||||
|
CompletionHelper.AudioFilePath(args[3], _proto, _res),
|
||||||
|
Loc.GetString("cmd-announce-arg-sound")
|
||||||
|
),
|
||||||
|
_ => CompletionResult.Empty
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
cmd-announce-desc = Send an in-game announcement with custom color and sound.
|
||||||
|
cmd-announce-help = {$command} <message> [sender] [color] [sound] - Send announcement. Sender defaults to CentCom, color to Gold, sound to announce.ogg. The color should be in a #RRGGBB format.
|
||||||
|
|
||||||
|
# The default sender for the announcement
|
||||||
|
cmd-announce-sender = Central Command
|
||||||
|
|
||||||
|
# Completion hints
|
||||||
|
cmd-announce-arg-message = <message>
|
||||||
|
cmd-announce-arg-sender = [sender]
|
||||||
|
cmd-announce-arg-color = [color]
|
||||||
|
cmd-announce-arg-sound = [sound]
|
||||||
Reference in New Issue
Block a user