mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-25 22:17:51 +01:00
Document ChatCommands
This commit is contained in:
@@ -5,18 +5,47 @@ using System.Threading;
|
||||
|
||||
namespace TGServerService.ChatCommands
|
||||
{
|
||||
/// <summary>
|
||||
/// Metadata about the currently running <see cref="ChatCommand"/>
|
||||
/// </summary>
|
||||
sealed class CommandInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// If the <see cref="ChatCommand"/> was invoked by an admin
|
||||
/// </summary>
|
||||
public bool IsAdmin { get; set; }
|
||||
/// <summary>
|
||||
/// If the <see cref="ChatCommand"/> was invoked from an admin chat channel
|
||||
/// </summary>
|
||||
public bool IsAdminChannel { get; set; }
|
||||
/// <summary>
|
||||
/// The name of the <see cref="ChatCommand"/> invoker
|
||||
/// </summary>
|
||||
public string Speaker { get; set; }
|
||||
/// <summary>
|
||||
/// A reference to the <see cref="ServerInstance"/> that runs the <see cref="ChatProviders.ITGChatProvider"/> that heard the <see cref="ChatCommand"/>
|
||||
/// </summary>
|
||||
public ServerInstance Server { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// A command heard by a <see cref="ChatProviders.ITGChatProvider"/>
|
||||
/// </summary>
|
||||
abstract class ChatCommand : Command
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="CommandInfo"/> for the <see cref="ChatCommand"/>
|
||||
/// </summary>
|
||||
public static ThreadLocal<CommandInfo> CommandInfo { protected get; set; } = new ThreadLocal<CommandInfo>();
|
||||
/// <summary>
|
||||
/// If set to <see langword="true"/>, the <see cref="ChatCommand"/> cannot be invoked by a non-admin or outside an admin chat channel
|
||||
/// </summary>
|
||||
public bool RequiresAdmin { get; protected set; }
|
||||
public static ThreadLocal<CommandInfo> CommandInfo = new ThreadLocal<CommandInfo>();
|
||||
/// <summary>
|
||||
/// Shorthand for accessing <see cref="CommandInfo.Server"/>
|
||||
/// </summary>
|
||||
protected ServerInstance Instance { get { return CommandInfo.Value.Server; } }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ExitCode DoRun(IList<string> parameters)
|
||||
{
|
||||
if (RequiresAdmin)
|
||||
@@ -37,9 +66,23 @@ namespace TGServerService.ChatCommands
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="ChatCommand"/>s generated by DreamDaemon via the API
|
||||
/// </summary>
|
||||
sealed class ServerChatCommand : ChatCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// The help text for the <see cref="ServerChatCommand"/>
|
||||
/// </summary>
|
||||
readonly string HelpText;
|
||||
|
||||
/// <summary>
|
||||
/// Construct a <see cref="ServerChatCommand"/>
|
||||
/// </summary>
|
||||
/// <param name="name">The invocation of the <see cref="ServerChatCommand"/></param>
|
||||
/// <param name="helpText">The help text of the <see cref="ServerChatCommand"/></param>
|
||||
/// <param name="adminOnly">If set to <see langword="true"/>, the <see cref="ServerChatCommand"/> cannot be invoked by a non-admin or outside an admin chat channel</param>
|
||||
/// <param name="requiredParameters">The number of parameters the <see cref="ServerChatCommand"/> requires</param>
|
||||
public ServerChatCommand(string name, string helpText, bool adminOnly, int requiredParameters)
|
||||
{
|
||||
Keyword = name;
|
||||
@@ -48,11 +91,13 @@ namespace TGServerService.ChatCommands
|
||||
RequiredParameters = requiredParameters;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string GetHelpText()
|
||||
{
|
||||
return HelpText;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var res = Instance.SendCommand(String.Format("{0};sender={1};custom={2}", Keyword, CommandInfo.Value.Speaker, Program.SanitizeTopicString(String.Join(" ", parameters))));
|
||||
@@ -62,8 +107,15 @@ namespace TGServerService.ChatCommands
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The main root chat command
|
||||
/// </summary>
|
||||
sealed class RootChatCommand : RootCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Construct a <see cref="RootChatCommand"/>
|
||||
/// </summary>
|
||||
/// <param name="serverCommands">List of <see cref="ServerChatCommand"/>s supplied by DreamDaemon</param>
|
||||
public RootChatCommand(List<Command> serverCommands)
|
||||
{
|
||||
var tmp = new List<Command> { new PRsCommand(), new VersionCommand(), new RevisionCommand(), new ByondCommand(), new KekCommand() };
|
||||
@@ -74,12 +126,19 @@ namespace TGServerService.ChatCommands
|
||||
PrintHelpList = true;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Retrieves the git SHA of the live DreamDaemon code
|
||||
/// </summary>
|
||||
sealed class RevisionCommand : ChatCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Construct a <see cref="RevisionCommand"/>
|
||||
/// </summary>
|
||||
public RevisionCommand()
|
||||
{
|
||||
Keyword = "revision";
|
||||
}
|
||||
/// <inheritdoc />
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var res = Instance.LiveSha();
|
||||
@@ -91,18 +150,26 @@ namespace TGServerService.ChatCommands
|
||||
return ExitCode.Normal;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string GetHelpText()
|
||||
{
|
||||
return "Prints the current code revision of the repository (not the server)";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve the installed, staged, or latest availab
|
||||
/// </summary>
|
||||
sealed class ByondCommand : ChatCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Construct a <see cref="ByondCommand"/>
|
||||
/// </summary>
|
||||
public ByondCommand()
|
||||
{
|
||||
Keyword = "byond";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var type = ByondVersion.Installed;
|
||||
@@ -115,55 +182,84 @@ namespace TGServerService.ChatCommands
|
||||
return ExitCode.Normal;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string GetHelpText()
|
||||
{
|
||||
return "Gets the specified BYOND version";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string GetArgumentString()
|
||||
{
|
||||
return "[--staged|--latest]";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Retrieve the current service version
|
||||
/// </summary>
|
||||
sealed class VersionCommand : ChatCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Construct a <see cref="VersionCommand"/>
|
||||
/// </summary>
|
||||
public VersionCommand()
|
||||
{
|
||||
Keyword = "version";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
OutputProc(Instance.Version());
|
||||
return ExitCode.Normal;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string GetHelpText()
|
||||
{
|
||||
return "Gets the running service version";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// kek
|
||||
/// </summary>
|
||||
sealed class KekCommand : ChatCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Construct a <see cref="KekCommand"/>
|
||||
/// </summary>
|
||||
public KekCommand()
|
||||
{
|
||||
Keyword = "kek";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
OutputProc("kek");
|
||||
return ExitCode.Normal;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string GetHelpText()
|
||||
{
|
||||
return "kek";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Retrieve the list of test-merged github pull requests
|
||||
/// </summary>
|
||||
sealed class PRsCommand : ChatCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Construct a <see cref="PRsCommand"/>
|
||||
/// </summary>
|
||||
public PRsCommand()
|
||||
{
|
||||
Keyword = "prs";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var PRs = Instance.MergedPullRequests(out string res);
|
||||
@@ -184,6 +280,7 @@ namespace TGServerService.ChatCommands
|
||||
return ExitCode.Normal;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string GetHelpText()
|
||||
{
|
||||
return "Gets the currently merged pull requests in the repository";
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace TGServiceInterface
|
||||
/// <summary>
|
||||
/// Helper for creating commands that contain sub commands
|
||||
/// </summary>
|
||||
public class RootCommand : Command
|
||||
public abstract class RootCommand : Command
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="Command"/>s further down the tree from this one. Set in Constructor
|
||||
|
||||
Reference in New Issue
Block a user