tgstation-server 5.12.7
The /tg/station 13 server suite
Loading...
Searching...
No Matches
ByondCommand.cs
Go to the documentation of this file.
1using System;
2using System.Globalization;
3using System.Linq;
4using System.Threading;
5using System.Threading.Tasks;
6
11
13{
17 sealed class ByondCommand : ICommand
18 {
20 public string Name => "byond";
21
23 public string HelpText => "Displays the running Byond version. Use --active for the version used in future deployments";
24
26 public bool AdminOnly => false;
27
32
37
44 {
45 this.byondManager = byondManager ?? throw new ArgumentNullException(nameof(byondManager));
46 this.watchdog = watchdog ?? throw new ArgumentNullException(nameof(watchdog));
47 }
48
50 public Task<MessageContent> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
51 {
52 if (arguments.Split(' ').Any(x => x.ToUpperInvariant() == "--ACTIVE"))
53 return Task.FromResult(new MessageContent
54 {
55 Text = byondManager.ActiveVersion == null ? "None!" : String.Format(CultureInfo.InvariantCulture, "{0}.{1}", byondManager.ActiveVersion.Major, byondManager.ActiveVersion.Minor),
56 });
57 if (watchdog.Status == WatchdogStatus.Offline)
58 return Task.FromResult(new MessageContent
59 {
60 Text = "Server offline!",
61 });
62 return Task.FromResult(new MessageContent
63 {
64 Text = watchdog.ActiveCompileJob?.ByondVersion ?? "None!",
65 });
66 }
67 }
68}
Represents a tgs_chat_user datum.
Definition: ChatUser.cs:12
For displaying the installed Byond version.
Definition: ByondCommand.cs:18
ByondCommand(IByondManager byondManager, IWatchdog watchdog)
Initializes a new instance of the ByondCommand class.
Definition: ByondCommand.cs:43
string HelpText
The help text to display when queires are made about the command.
Definition: ByondCommand.cs:23
bool AdminOnly
If the command should only be available to ChatUsers who's ChatUser.Channel has ChannelRepresentation...
Definition: ByondCommand.cs:26
Task< MessageContent > Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
Invoke the ICommand. A Task<TResult> resulting in a MessageContent to send to the invoker.
Definition: ByondCommand.cs:50
readonly IByondManager byondManager
The IByondManager for the ByondCommand.
Definition: ByondCommand.cs:31
readonly IWatchdog watchdog
The IWatchdog for the ByondCommand.
Definition: ByondCommand.cs:36
string Name
The text to invoke the command. May not be "?" or "help" (case-insensitive).
Definition: ByondCommand.cs:20
Represents a message to send to a chat provider.
For managing the BYOND installation.
Version ActiveVersion
The currently active BYOND version.
Represents a command that can be invoked by talking to chat bots.
Definition: ICommand.cs:12
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:30
WatchdogStatus Status
The current WatchdogStatus.
Definition: IWatchdog.cs:20
WatchdogStatus
The current status of the watchdog.