-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
probably didn't break anything important
- Loading branch information
Showing
2 changed files
with
70 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,80 @@ | ||
using Content.Server.Administration; | ||
using Content.Server.Chat; | ||
using Content.Server.Chat.Systems; | ||
using Content.Shared.Administration; | ||
using Robust.Shared.Audio; | ||
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 : IConsoleCommand | ||
{ | ||
[AdminCommand(AdminFlags.Moderator)] | ||
public sealed class AnnounceCommand : IConsoleCommand | ||
[Dependency] private readonly IPrototypeManager _proto = default!; | ||
[Dependency] private readonly IResourceManager _res = default!; | ||
|
||
public string Command => "announce"; | ||
public string Description => Loc.GetString("cmd-announce-desc"); | ||
public string Help => Loc.GetString("cmd-announce-help", ("command", Command)); | ||
|
||
public void Execute(IConsoleShell shell, string argStr, string[] args) | ||
{ | ||
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>(); | ||
var chat = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<ChatSystem>(); | ||
|
||
if (args.Length == 0) | ||
{ | ||
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; | ||
} | ||
|
||
var message = args[0]; | ||
var sender = "Central Command"; | ||
var color = Color.Gold; | ||
var sound = new SoundPathSpecifier("/Audio/Announcements/announce.ogg"); | ||
|
||
if (args.Length == 1) | ||
// Optional sender argument | ||
if (args.Length >= 2) | ||
sender = args[1]; | ||
|
||
// Optional color argument | ||
if (args.Length >= 3) | ||
{ | ||
try | ||
{ | ||
chat.DispatchGlobalAnnouncement(args[0], colorOverride: Color.Gold); | ||
color = Color.FromHex(args[2]); | ||
} | ||
else | ||
catch | ||
{ | ||
// Explicit IEnumerable<string> due to overload ambiguity on .NET 9 | ||
var message = string.Join(' ', (IEnumerable<string>)new ArraySegment<string>(args, 1, args.Length-1)); | ||
chat.DispatchGlobalAnnouncement(message, args[0], colorOverride: Color.Gold); | ||
shell.WriteError(Loc.GetString("shell-invalid-color-hex")); | ||
return; | ||
} | ||
shell.WriteLine("Sent!"); | ||
} | ||
|
||
// 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 CompletionResult GetCompletion(IConsoleShell shell, string[] args) | ||
{ | ||
return args.Length switch | ||
{ | ||
1 => CompletionResult.FromHint(Loc.GetString("cmd-announce-arg-message")), | ||
2 => CompletionResult.FromHint(Loc.GetString("shell-argument-username-optional-hint")), | ||
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 | ||
}; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
Resources/Locale/en-US/administration/commands/announce-command.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
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 | ||
# Completion hints | ||
cmd-announce-arg-message = message | ||
cmd-announce-arg-color = color in #RRGGBB format (optional) | ||
cmd-announce-arg-sound = sound path (optional) |