Skip to content

Commit

Permalink
Merge branch 'master' into justice-stamps
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomce795 authored Nov 10, 2024
2 parents 9d8a187 + 648396c commit 09c464d
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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.Administration.Commands;

[AdminCommand(AdminFlags.Fun)]
public sealed class AnnounceCustomCommand : IConsoleCommand
{
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly IResourceManager _res = default!;

public string Command => "announcecustom";
public string Description => Loc.GetString("cmd-announcecustom-desc");
public string Help => Loc.GetString("cmd-announcecustom-help", ("command", Command));

public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var chat = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<ChatSystem>();

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");

// Optional sender argument
if (args.Length >= 2)
sender = args[1];

// Optional color argument
if (args.Length >= 3)
{
try
{
color = Color.FromHex(args[2]);
}
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 CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
return args.Length switch
{
1 => CompletionResult.FromHint(Loc.GetString("cmd-announcecustom-arg-message")),
2 => CompletionResult.FromHint(Loc.GetString("shell-argument-username-optional-hint")),
3 => CompletionResult.FromHint(Loc.GetString("cmd-announcecustom-arg-color")),
4 => CompletionResult.FromHintOptions(
CompletionHelper.AudioFilePath(args[3], _protoManager, _res),
Loc.GetString("cmd-announcecustom-arg-sound")
),
_ => CompletionResult.Empty
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## AnnounceCustomCommand
cmd-announcecustom-desc = Send an in-game announcement with custom color and sound.
cmd-announcecustom-help = {$command} <message> [sender] [color] [sound] - Send announcement. Sender defaults to CentCom, color to Gold, sound to announce.ogg
# Completion hints
cmd-announcecustom-arg-message = message
cmd-announcecustom-arg-color = color in #RRGGBB format (optional)
cmd-announcecustom-arg-sound = sound path (optional)

0 comments on commit 09c464d

Please sign in to comment.