tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
CustomCommand.cs
Go to the documentation of this file.
1using System;
2using System.Threading;
3using System.Threading.Tasks;
4
6
8{
12 public sealed class CustomCommand : ICommand
13 {
15 public string Name { get; }
16
18 public string HelpText { get; }
19
21 public bool AdminOnly { get; }
22
27
34 public CustomCommand(string name, string helpText, bool adminOnly)
35 {
36 Name = name ?? throw new ArgumentNullException(nameof(name));
37 HelpText = helpText ?? throw new ArgumentNullException(nameof(helpText));
38 AdminOnly = adminOnly;
39 }
40
46 {
47 if (this.handler != null)
48 throw new InvalidOperationException("SetHandler() already called!");
49 this.handler = handler ?? throw new ArgumentNullException(nameof(handler));
50 }
51
53 public ValueTask<MessageContent> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
54 {
55 if (handler == null)
56 throw new InvalidOperationException("SetHandler() has not been called!");
57 return handler.HandleChatCommand(Name, arguments, user, cancellationToken);
58 }
59 }
60}
Represents a tgs_chat_user datum.
Definition ChatUser.cs:12
ICustomCommandHandler? handler
The ICustomCommandHandler for the CustomCommand.
bool AdminOnly
If the command should only be available to ChatUsers who's ChatUser.Channel has ChannelRepresentation...
CustomCommand(string name, string helpText, bool adminOnly)
Initializes a new instance of the CustomCommand class.
void SetHandler(ICustomCommandHandler handler)
Set a new handler .
string Name
The text to invoke the command. May not be "?" or "help" (case-insensitive).
string HelpText
The help text to display when queires are made about the command.
ValueTask< MessageContent > Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
Invoke the ICommand.A ValueTask<TResult> resulting in a MessageContent to send to the invoker.
Represents a command that can be invoked by talking to chat bots.
Definition ICommand.cs:12
Handles Commands.ICommands that map to those defined in a IChatTrackingContext.
ValueTask< MessageContent > HandleChatCommand(string commandName, string arguments, ChatUser sender, CancellationToken cancellationToken)
Handle a chat command.