Skip to content

Commit

Permalink
rewrite the announce command
Browse files Browse the repository at this point in the history
  • Loading branch information
DEATHB4DEFEAT committed Apr 13, 2024
1 parent 8a06392 commit e4e66b0
Showing 1 changed file with 70 additions and 15 deletions.
85 changes: 70 additions & 15 deletions Content.Server/Announcements/AnnounceCommand.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System.Linq;
using Content.Server.Administration;
using Content.Server.Chat;
using Content.Server.Chat.Systems;
using Content.Server.Parkstation.Announcements.Systems;
using Content.Shared.Administration;
using Content.Shared.Parkstation.Announcements.Prototypes;
using Robust.Shared.Console;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;

namespace Content.Server.Announcements
{
Expand All @@ -11,27 +14,79 @@ public sealed class AnnounceCommand : IConsoleCommand
{
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.";
// Parkstation-RandomAnnouncers-Start // This entire thing was rewritten
public string Help => $"{Command} <sender> <message> <sound> <announcer>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var chat = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<ChatSystem>();
var announcer = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AnnouncerSystem>();
var proto = IoCManager.Resolve<IPrototypeManager>();

if (args.Length == 0)
switch (args.Length)
{
shell.WriteError("Not enough arguments! Need at least 1.");
return;
case 0:
shell.WriteError("Not enough arguments! Need at least 1.");
return;
case 1:
announcer.SendAnnouncement(announcer.GetAnnouncementId("CommandReport"), Filter.Broadcast(),
args[0], "Central Command", Color.Gold);
break;
case 2:
announcer.SendAnnouncement(announcer.GetAnnouncementId("CommandReport"), Filter.Broadcast(),
args[1], args[0], Color.Gold);
break;
case 3:
announcer.SendAnnouncement(announcer.GetAnnouncementId(args[2]), Filter.Broadcast(), args[1],
args[0], Color.Gold);
break;
case 4:
if (!proto.TryIndex(args[3], out AnnouncerPrototype? prototype))
{
shell.WriteError($"No announcer prototype with ID {args[3]} found!");
return;
}
announcer.SendAnnouncement(args[2], Filter.Broadcast(), args[1], args[0], Color.Gold, null,
prototype);
break;
}

if (args.Length == 1)
{
chat.DispatchGlobalAnnouncement(args[0], colorOverride: Color.Gold);
}
else
shell.WriteLine("Sent!");
}

public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
switch (args.Length)
{
var message = string.Join(' ', new ArraySegment<string>(args, 1, args.Length-1));
chat.DispatchGlobalAnnouncement(message, args[0], colorOverride: Color.Gold);
case 3:
{
var list = new List<string>();

foreach (var prototype in IoCManager.Resolve<IPrototypeManager>()
.EnumeratePrototypes<AnnouncerPrototype>()
.SelectMany<AnnouncerPrototype, string>(p => p.Announcements.Select(a => a.ID)))
{
if (!list.Contains(prototype))
list.Add(prototype);
}

return CompletionResult.FromHintOptions(list, Loc.GetString("admin-announce-hint-sound"));
}
case 4:
{
var list = new List<string>();

foreach (var prototype in IoCManager.Resolve<IPrototypeManager>()
.EnumeratePrototypes<AnnouncerPrototype>())
{
if (!list.Contains(prototype.ID))
list.Add(prototype.ID);
}

return CompletionResult.FromHintOptions(list, Loc.GetString("admin-announce-hint-voice"));
}
default:
return CompletionResult.Empty;
}
shell.WriteLine("Sent!");
}
// Parkstation-RandomAnnouncers-End
}
}

0 comments on commit e4e66b0

Please sign in to comment.