tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
EngineCommand.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
3using System.Threading;
4using System.Threading.Tasks;
5
10
12{
16 sealed class EngineCommand : ICommand
17 {
19 public string Name => "engine";
20
22 public string HelpText => "Displays the running engine version. Use --active for the version used in future deployments";
23
25 public bool AdminOnly => false;
26
31
36
43 {
44 this.engineManager = engineManager ?? throw new ArgumentNullException(nameof(engineManager));
45 this.watchdog = watchdog ?? throw new ArgumentNullException(nameof(watchdog));
46 }
47
49 public ValueTask<MessageContent> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
50 {
51 EngineVersion? engineVersion;
52 if (arguments.Split(' ').Any(x => x.Equals("--active", StringComparison.OrdinalIgnoreCase)))
53 engineVersion = engineManager.ActiveVersion;
54 else
55 {
56 if (watchdog.Status == WatchdogStatus.Offline)
57 return ValueTask.FromResult(
59 {
60 Text = "Server offline!",
61 });
62
63 if (watchdog.ActiveCompileJob == null)
64 return ValueTask.FromResult(
66 {
67 Text = "None!",
68 });
69
70 engineVersion = EngineVersion.Parse(watchdog.ActiveCompileJob.EngineVersion);
71 }
72
73 string text;
74 if (engineVersion == null)
75 text = "None!";
76 else
77 {
78 text = engineVersion.Engine!.Value switch
79 {
80 EngineType.OpenDream => $"OpenDream: {engineVersion.SourceSHA}",
81 EngineType.Byond => $"BYOND {engineVersion.Version!.Major}.{engineVersion.Version.Minor}",
82 _ => throw new InvalidOperationException($"Invalid EngineType: {engineVersion.Engine.Value}"),
83 };
84
85 if (engineVersion.CustomIteration.HasValue)
86 text += $" (Custom Upload #{engineVersion.CustomIteration.Value})";
87 }
88
89 return ValueTask.FromResult(
91 {
92 Text = text,
93 });
94 }
95 }
96}
Information about an engine installation.
static EngineVersion Parse(string input)
Parses a stringified EngineVersion.
int? CustomIteration
The revision of the custom build.
Represents a tgs_chat_user datum.
Definition ChatUser.cs:12
For displaying the installed Byond version.
bool AdminOnly
If the command should only be available to ChatUsers who's ChatUser.Channel has ChannelRepresentation...
readonly IEngineManager engineManager
The IEngineManager for the EngineCommand.
string Name
The text to invoke the command. May not be "?" or "help" (case-insensitive).
ValueTask< MessageContent > Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
Invoke the ICommand.A ValueTask<TResult> resulting in a MessageContent to send to the invoker.
string HelpText
The help text to display when queires are made about the command.
readonly IWatchdog watchdog
The IWatchdog for the EngineCommand.
EngineCommand(IEngineManager engineManager, IWatchdog watchdog)
Initializes a new instance of the EngineCommand class.
Represents a message to send to a chat provider.
Represents a command that can be invoked by talking to chat bots.
Definition ICommand.cs:12
EngineVersion? ActiveVersion
The currently active EngineVersion.
Runs and monitors the twin server controllers.
Definition IWatchdog.cs:16
Models.? CompileJob ActiveCompileJob
Retrieves the Models.CompileJob currently running on the server.
Definition IWatchdog.cs:50
WatchdogStatus Status
The current WatchdogStatus.
Definition IWatchdog.cs:35
WatchdogStatus
The current status of the watchdog.