tgstation-server  4.4.0
The /tg/station 13 server suite
CustomCommand.cs
Go to the documentation of this file.
1 using System;
2 using System.Threading;
3 using System.Threading.Tasks;
4 
5 namespace Tgstation.Server.Host.Components.Chat.Commands
6 {
10  public sealed class CustomCommand : ICommand
11  {
13  public string Name { get; set; }
14 
16  public string HelpText { get; set; }
17 
19  public bool AdminOnly { get; set; }
20 
25 
30  public void SetHandler(ICustomCommandHandler handler)
31  {
32  if (this.handler != null)
33  throw new InvalidOperationException("SetHandler() already called!");
34  this.handler = handler ?? throw new ArgumentNullException(nameof(handler));
35  }
36 
38  public Task<string> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
39  {
40  if (handler == null)
41  throw new InvalidOperationException("SetHandler() has not been called!");
42  return handler.HandleChatCommand(Name, arguments, user, cancellationToken);
43  }
44  }
45 }
void SetHandler(ICustomCommandHandler handler)
Set a new handler
Task< string > HandleChatCommand(string commandName, string arguments, ChatUser sender, CancellationToken cancellationToken)
Handle a chat command
Task< string > Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
Invoke the ICommand
Represents a tgs_chat_user datum
Definition: ChatUser.cs:10
ICustomCommandHandler handler
The ICustomCommandHandler for the CustomCommand
Handles Commands.ICommands that map to those defined in a IChatTrackingContext
Represents a command that can be invoked by talking to chat bots
Definition: ICommand.cs:9