Files
tgstation-server/TGS.Server/ChatCommands/ServerChatCommand.cs
T

47 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
namespace TGS.Server.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;
RequiresAdmin = adminOnly;
HelpText = helpText;
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, Helpers.SanitizeTopicString(String.Join(" ", parameters))));
if (res != "SUCCESS" && !String.IsNullOrWhiteSpace(res))
OutputProc(res);
return ExitCode.Normal;
}
}
}